/* int RapidXMLInterface::rapidReadFile(const std::string &fileName) { GEOLIB::GEOObjects* geoObjects = _project->getGEOObjects(); std::ifstream in(fileName.c_str()); if (in.fail()) { std::cout << "XmlStnInterface::rapidReadFile() - Can't open xml-file." << std::endl; return 0; } // buffer file in.seekg(0, std::ios::end); size_t length = in.tellg(); in.seekg(0, std::ios::beg); char* buffer = new char[length+1]; in.read(buffer, length); buffer[in.gcount()] = '\0'; in.close(); // build DOM tree rapidxml::xml_document<> doc; doc.parse<0>(buffer); // parse content if (std::string(doc.first_node()->name()).compare("OpenGeoSysSTN")) { std::cout << "XmlStnInterface::readFile() - Unexpected XML root." << std::endl; return 0; } // iterate over all station lists for (rapidxml::xml_node<>* station_list = doc.first_node()->first_node(); station_list; station_list = station_list->next_sibling()) { std::vector<GEOLIB::Point*>* stations = new std::vector<GEOLIB::Point*>; std::string stnName("[NN]"); stnName = station_list->first_node("name")->value(); for (rapidxml::xml_node<>* list_item = station_list->first_node(); list_item; list_item = list_item->next_sibling()) { std::string b(list_item->name()); if (std::string(list_item->name()).compare("stations") == 0) XmlStnInterface::rapidReadStations(list_item, stations, fileName); if (std::string(list_item->name()).compare("boreholes") == 0) XmlStnInterface::rapidReadStations(list_item, stations, fileName); } if (!stations->empty()) geoObjects->addStationVec(stations, stnName); else delete stations; } doc.clear(); delete [] buffer; return 1; } */ void RapidXMLInterface::readStations(const rapidxml::xml_node<>* station_root, std::vector<GeoLib::Point*> *stations, const std::string &file_name) { for (rapidxml::xml_node<>* station_node = station_root->first_node(); station_node; station_node = station_node->next_sibling()) { if (station_node->first_attribute("id") && station_node->first_attribute("x") && station_node->first_attribute("y")) { double zVal(0.0); if (station_node->first_attribute("z")) zVal = strtod(station_node->first_attribute("z")->value(), 0); std::string station_name(""), sensor_data_file_name(""), bdate_str("0000-00-00"); double station_value(0.0), borehole_depth(0.0); if (station_node->first_node("name")) station_name = station_node->first_node("name")->value(); if (station_node->first_node("sensordata")) sensor_data_file_name = station_node->first_node("sensordata")->value(); if (station_node->first_node("value")) station_value = strtod(station_node->first_node("value")->value(), 0); /* add other station features here */ if (std::string(station_node->name()).compare("station") == 0) { GeoLib::Station* s = new GeoLib::Station( strtod(station_node->first_attribute("x")->value(), 0), strtod(station_node->first_attribute("y")->value(), 0), zVal, station_name); s->setStationValue(station_value); if (!sensor_data_file_name.empty()) s->addSensorDataFromCSV(BaseLib::copyPathToFileName(sensor_data_file_name, file_name)); stations->push_back(s); } else if (std::string(station_node->name()).compare("borehole") == 0) { if (station_node->first_node("bdepth")) borehole_depth = strtod(station_node->first_node("bdepth")->value(), 0); if (station_node->first_node("bdate")) bdate_str = station_node->first_node("bdate")->value(); /* add other borehole features here */ GeoLib::StationBorehole* s = GeoLib::StationBorehole::createStation( station_name, strtod(station_node->first_attribute("x")->value(), 0), strtod(station_node->first_attribute("y")->value(), 0), zVal, borehole_depth, bdate_str); s->setStationValue(station_value); if (station_node->first_node("strat")) RapidXMLInterface::readStratigraphy(station_node->first_node("strat"), s); stations->push_back(s); } } else std::cout << "XmlStnInterface::rapidReadStations() - Attribute missing in <station> tag ..." << std::endl; } }
void XmlStnInterface::readStations( const QDomNode &stationsRoot, std::vector<GEOLIB::Point*>* stations, const std::string &file_name ) { QDomElement station = stationsRoot.firstChildElement(); while (!station.isNull()) { if (station.hasAttribute("id") && station.hasAttribute("x") && station.hasAttribute("y")) { std::string stationName("[NN]"); std::string sensor_data_file_name(""); std::string boreholeDate("0000-00-00"); double boreholeDepth(0.0), stationValue(0.0); QDomNodeList stationFeatures = station.childNodes(); for(int i = 0; i < stationFeatures.count(); i++) { // check for general station features const QDomNode feature_node (stationFeatures.at(i)); const QString feature_name (feature_node.nodeName()); const std::string element_text (feature_node.toElement().text().toStdString()); if (feature_name.compare("name") == 0) stationName = feature_node.toElement().text().toStdString(); if (feature_name.compare("sensordata") == 0) sensor_data_file_name = feature_node.toElement().text().toStdString(); /* add other station features here */ // check for general borehole features else if (feature_name.compare("value") == 0) stationValue = strtod(element_text.c_str(), 0); else if (feature_name.compare("bdepth") == 0) boreholeDepth = strtod(element_text.c_str(), 0); else if (feature_name.compare("bdate") == 0) boreholeDate = element_text; /* add other borehole features here */ } double zVal = (station.hasAttribute("z")) ? strtod((station.attribute("z")).toStdString().c_str(), 0) : 0.0; if (station.nodeName().compare("station") == 0) { GEOLIB::Station* s = new GEOLIB::Station( strtod((station.attribute("x")).toStdString().c_str(), 0), strtod((station.attribute("y")).toStdString().c_str(), 0), zVal, stationName); s->setStationValue(stationValue); if (!sensor_data_file_name.empty()) s->addSensorDataFromCSV(BaseLib::copyPathToFileName(sensor_data_file_name, file_name)); stations->push_back(s); } else if (station.nodeName().compare("borehole") == 0) { GEOLIB::StationBorehole* s = GEOLIB::StationBorehole::createStation( stationName, strtod((station.attribute("x")).toStdString().c_str(), 0), strtod((station.attribute("y")).toStdString().c_str(), 0), zVal, boreholeDepth, boreholeDate); s->setStationValue(stationValue); /* add stratigraphy to the borehole */ for(int j = 0; j < stationFeatures.count(); j++) if (stationFeatures.at(j).nodeName().compare("strat") == 0) this->readStratigraphy(stationFeatures.at(j), s); stations->push_back(s); } } else std::cout << "XmlStnInterface::readStations() - Attribute missing in <station> tag ..." << "\n"; station = station.nextSiblingElement(); } }