Пример #1
0
/*
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;
    }
}
Пример #2
0
void GeoMapper::mapData()
{
	const std::vector<GeoLib::Point*> *points (this->_geo_objects.getPointVec(this->_geo_name));
	GeoLib::Station* stn_test = dynamic_cast<GeoLib::Station*>((*points)[0]);
	bool is_borehole(false);
	if (stn_test != nullptr && static_cast<GeoLib::StationBorehole*>((*points)[0])->type() == GeoLib::Station::StationType::BOREHOLE)
		is_borehole = true;
	
	double min_val(0), max_val(0);
	if (_mesh)
	{
		GeoLib::AABB<GeoLib::Point> bounding_box (_mesh->getNodes().begin(), _mesh->getNodes().end());
		min_val = bounding_box.getMinPoint()[2];
		max_val = bounding_box.getMaxPoint()[2];
	}
	size_t nPoints (points->size());

	if (!is_borehole)
	{
		for (unsigned j=0; j<nPoints; ++j)
		{
			GeoLib::Point* pnt ((*points)[j]);
			(*pnt)[2] = (_grid) ? this->getMeshElevation((*pnt)[0],(*pnt)[1], min_val, max_val)
				                : this->getDemElevation((*pnt)[0],(*pnt)[1]);
		}
	}
	else
	{
		for (unsigned j=0; j<nPoints; ++j)
		{
			GeoLib::Point* pnt ((*points)[j]);
			double offset = (_grid) ? (this->getMeshElevation((*pnt)[0],(*pnt)[1], min_val, max_val) - (*pnt)[2])
				                    : (this->getDemElevation((*pnt)[0],(*pnt)[1]) - (*pnt)[2]);

			GeoLib::StationBorehole* borehole = static_cast<GeoLib::StationBorehole*>(pnt);
			const std::vector<GeoLib::Point*> layers = borehole->getProfile();
			size_t nLayers = layers.size();
			for (unsigned k=0; k<nLayers; ++k)
			{
				GeoLib::Point* layer_pnt = layers[k];
				(*layer_pnt)[2] = (*layer_pnt)[2] + offset;
			}
		}
	}
}
Пример #3
0
/*
   // all boreholes to GMS which each borehole in a single file
   void StationIO::writeBoreholesToGMS(const std::vector<GeoLib::Point*> *stations)
   {
    //std::vector<std::string> soilID(1);
    std::vector<std::string> soilID = readSoilIDfromFile("d:/BodeTimeline.txt");
    for (std::size_t i=0; i<stations->size(); i++)
        StationIO::writeBoreholeToGMS(static_cast<GeoLib::StationBorehole*>((*stations)[i]), std::string("Borehole-" + static_cast<GeoLib::StationBorehole*>((*stations)[i])->getName() + ".txt"), soilID);
    StationIO::writeSoilIDTable(soilID, "SoilIDReference.txt");
   }
 */
void GMSInterface::writeBoreholesToGMS(const std::vector<GeoLib::Point*>* stations,
                                       const std::string &filename)
{
	std::ofstream out( filename.c_str(), std::ios::out );
	//std::vector<std::string> soilID = readSoilIDfromFile("d:/BodeTimeline.txt");

	// write header
	out << "name" << "\t" << std::fixed << "X" << "\t" << "Y"  << "\t" << "Z" <<  "\t" <<
	"soilID" << "\n";

	for (std::size_t j = 0; j < stations->size(); j++)
	{
		GeoLib::StationBorehole* station =
		        static_cast<GeoLib::StationBorehole*>((*stations)[j]);
		std::vector<GeoLib::Point*> profile = station->getProfile();
		std::vector<std::string> soilNames  = station->getSoilNames();
		//std::size_t idx = 0;
		std::string current_soil_name("");

		std::size_t nLayers = profile.size();
		for (std::size_t i = 1; i < nLayers; i++)
		{
			if ( (i > 1) && (soilNames[i].compare(soilNames[i - 1]) == 0) )
				continue;
			//idx = getSoilID(soilID, soilNames[i]);
			current_soil_name = soilNames[i];

			out << station->getName() << "\t" << std::fixed
				<< (*(profile[i - 1]))[0] << "\t"
			    << (*(profile[i - 1]))[1]  << "\t"
				<< (*(profile[i - 1]))[2] <<  "\t"
			    << current_soil_name/*idx*/ << "\n";
		}
		out << station->getName() << "\t" << std::fixed <<
		(*(profile[nLayers - 1]))[0] << "\t"
		    << (*(profile[nLayers - 1]))[1]  << "\t"
			<< (*(profile[nLayers - 1]))[2] <<  "\t"
		    << current_soil_name << "\n"; // this line marks the end of the borehole
	}

	out.close();
	//GMSInterface::writeSoilIDTable(soilID, "d:/SoilIDReference.txt");
}
Пример #4
0
void GeoMapper::mapData(MeshLib::Mesh const*const mesh)
{
	const std::vector<GeoLib::Point*> *points (this->_geo_objects.getPointVec(this->_geo_name));
	GeoLib::Station* stn_test = dynamic_cast<GeoLib::Station*>((*points)[0]);
	bool is_borehole(false);
	if (stn_test != NULL && static_cast<GeoLib::StationBorehole*>((*points)[0])->type() == GeoLib::Station::BOREHOLE)
		is_borehole = true;
	size_t nPoints (points->size());

	if (!is_borehole)
	{
		for (unsigned j=0; j<nPoints; ++j)
		{
			GeoLib::Point* pnt ((*points)[j]);
			(*pnt)[2] = (_grid) ? this->getMeshElevation((*pnt)[0],(*pnt)[1], mesh)
				                : this->getDemElevation((*pnt)[0],(*pnt)[1]);
		}
	}
	else
	{
		for (unsigned j=0; j<nPoints; ++j)
		{
			GeoLib::Point* pnt ((*points)[j]);
			double offset = (_grid) ? (this->getMeshElevation((*pnt)[0],(*pnt)[1], mesh) - (*pnt)[2])
				                    : (this->getDemElevation((*pnt)[0],(*pnt)[1]) - (*pnt)[2]);

			GeoLib::StationBorehole* borehole = static_cast<GeoLib::StationBorehole*>(pnt);
			const std::vector<GeoLib::Point*> layers = borehole->getProfile();
			size_t nLayers = layers.size();
			for (unsigned k=0; k<nLayers; ++k)
			{
				GeoLib::Point* layer_pnt = layers[k];
				(*layer_pnt)[2] = (*layer_pnt)[2] + offset;
			}
		}
	}


}
Пример #5
0
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();
	}
}
Пример #6
0
int GMSInterface::readBoreholesFromGMS(std::vector<GEOLIB::Point*>* boreholes,
                                       const std::string &filename)
{
	double depth(-9999.0);
	std::string line(""), cName(""), sName("");
	std::list<std::string>::const_iterator it;
	GEOLIB::Point* pnt = new GEOLIB::Point();
	GEOLIB::StationBorehole* newBorehole = NULL;
	std::ifstream in( filename.c_str() );

	if (!in.is_open())
	{
		std::cout << "GMSInterface::readBoreholeFromGMS() - Could not open file...\n";
		return 0;
	}

	/* skipping first line because it contains field names */
	getline(in, line);

	/* read all stations */
	while ( getline(in, line) )
	{
		std::list<std::string> fields = splitString(line, '\t');

		if (fields.size() >= 5)
		{
			if (fields.begin()->compare(cName) == 0) // add new layer
			{
				it = fields.begin();
				(*pnt)[0] = strtod((++it)->c_str(), 0);
				(*pnt)[1] = strtod((++it)->c_str(), 0);
				(*pnt)[2] = strtod((++it)->c_str(), 0);

				// check if current layer has a thickness of 0.0.
				// if so skip it since it will mess with the vtk-visualisation later on!
				if ((*pnt)[2] != depth)
				{
					newBorehole->addSoilLayer((*pnt)[0], (*pnt)[1], (*pnt)[2], sName);
					sName = (*(++it));
					depth = (*pnt)[2];
				}
				else
					std::cout << "Warning: Skipped layer \"" << sName << "\" in borehole \"" 
					          << cName << "\" because of thickness 0.0." << "\n";
			}
			else // add new borehole
			{
				if (newBorehole != NULL)
				{
					newBorehole->setDepth((*newBorehole)[2] - depth);
					boreholes->push_back(newBorehole);
				}
				cName = *fields.begin();
				it = fields.begin();
				(*pnt)[0] = strtod((++it)->c_str(), 0);
				(*pnt)[1] = strtod((++it)->c_str(), 0);
				(*pnt)[2] = strtod((++it)->c_str(), 0);
				sName = (*(++it));
				newBorehole = GEOLIB::StationBorehole::createStation(cName, (*pnt)[0], (*pnt)[1], (*pnt)[2], 0);
				depth = (*pnt)[2];
			}
		}
		else
			std::cout <<
			"GMSInterface::readBoreholeFromGMS() - Error reading format..." <<
			"\n";
	}
	// write the last borehole from the file
	if (newBorehole != NULL)
	{
		newBorehole->setDepth((*newBorehole)[2] - depth);
		boreholes->push_back(newBorehole);
	}
	in.close();

	if (boreholes->empty())
		return 0;
	return 1;
}