コード例 #1
0
ファイル: polygon.cpp プロジェクト: marcelobianchi/seiscomp3
std::string PolyRegions::findRegionName(double lat, double lon) const {
	GeoFeature *region = findRegion(lat, lon);
	if ( region )
		return region->name();

	return "";
}
コード例 #2
0
ファイル: polygon.cpp プロジェクト: marcelobianchi/seiscomp3
bool PolyRegions::readFepBoundaries(const std::string& filename) {
	SEISCOMP_DEBUG("reading boundary polygons from file: %s", filename.c_str());

	std::ifstream infile(filename.c_str());

	if (infile.bad())
		return false;

	boost::regex vertexLine("^\\s*([-+]?[0-9]*\\.?[0-9]+)\\s+([-+]?[0-9]*\\.?[0-9]+)(?:\\s+([^\\d\\s].*)$|\\s*$)");
	boost::regex LLine("^\\s*L\\s+(.*)$");
	boost::smatch what;

	std::string line;
	bool newPolygon = true;
	GeoFeature *pr = NULL;
	OPT(Vertex) last;

	while(std::getline(infile, line)) {

		if (newPolygon){
			pr = new GeoFeature();
			newPolygon = false;
		}

		if ( boost::regex_match(line, what, vertexLine) ) {
			if ( last ) pr->addVertex(*last);
			last = Vertex(atof(what.str(2).c_str()), atof(what.str(1).c_str()));
		}
		else if (boost::regex_match(line, what, LLine)) {
			if ( last && pr->vertices().size() > 0 ) {
				if ( *last != pr->vertices().back() )
					pr->addVertex(*last);
			}

			if ( pr->vertices().size() < 3 )
				delete pr;
			else {
				pr->setName(what.str(1));
				pr->setClosedPolygon(true);
				addRegion(pr);

				if ( pr->area() < 0 )
					SEISCOMP_WARNING("Polygon %s is defined clockwise", pr->name().c_str());
			}

			last = Core::None;
			newPolygon = true;
		}
		else {
			//std::cout << "Warning: line ignored: " << line << std::endl;
		}
		
	}

	return true;

}
コード例 #3
0
ファイル: GeoFeaturePyImp.cpp プロジェクト: crobarcro/FreeCAD
PyObject* GeoFeaturePy::getPropertyNameOfGeometry(PyObject * args)
{
    if (!PyArg_ParseTuple(args, ""))
        return 0;
    GeoFeature* object = this->getGeoFeaturePtr();
    const PropertyComplexGeoData* prop = object->getPropertyOfGeometry();
    const char* name = prop ? prop->getName() : 0;
    if (name) {
        return Py::new_reference_to(Py::String(std::string(name)));
    }
    return Py::new_reference_to(Py::None());
}
コード例 #4
0
ファイル: geofeatureset.cpp プロジェクト: aemanov/seiscomp3
/**
 * Reads one BNA file. A BNA file may contain multiple segments consisting of
 * multiple points which define a non closed polyline. A new segment is
 * introduced by the following line:
 *   '"arbitrary segment name","rank <#rank>",<#points>'
 * e.g.
 *   '"test segment","rank 1",991'
 *
 * A point or vertex is defined by the following line:
 *   '<latitude>,<longitude>'
 * e.g.
 *   '31.646944,25.151389'
 *
 * In addition the BNA file format supports complex areas such as main land and
 * islands. The coordinate pairs representing the islands are separated from
 * each other by repeating the initial coordinate of the main area. The
 * following sample file illustrates a complex area:
 *
 *   "Test Area","rank 1",17
 *   2,2 --begin main area
 *   2,1
 *   1,1
 *   1,2
 *   2,2 --end of main area
 *   4,4 --begin island #1
 *   4,3
 *   3,3
 *   3,4
 *   4,4 --end island #1
 *   2,2 --end main area
 *   7,7 --begin island #2
 *   7,5
 *   6,4
 *   5,6
 *   7,7 --end of island #2
 *   2,2 --end of main area
 */
bool GeoFeatureSet::readBNAFile(const std::string& filename,
                                const Category* category) {
	SEISCOMP_DEBUG("Reading segments from file: %s", filename.c_str());

	std::ifstream infile(filename.c_str());

	if ( infile.fail() ) {
		SEISCOMP_WARNING("Could not open segment file for reading: %s",
		                 filename.c_str());
		return false;
	}

	GeoFeature* feature;
	unsigned int lineNum = 0;
	std::string tmpStr;
	std::string segment;
	unsigned int rank;
	unsigned int points;
	bool isClosed;
	Vertex v;
	bool startSubFeature;

	while ( infile.good() ) {
		++lineNum;

		if ( !readBNAHeader(infile, segment, rank, points, isClosed) ) {
			if ( infile.eof() ) break;
			SEISCOMP_WARNING("error reading BNA header in file %s at line %i",
			                 filename.c_str(), lineNum);
			continue;
		}
		startSubFeature = false;

		feature = new GeoFeature(segment, category, rank);
		_features.push_back(feature);
		if ( isClosed )
			feature->setClosedPolygon(true);

		// read vertices
		for ( unsigned int pi = 0; pi < points && infile.good(); ++pi ) {
			++lineNum;
			std::getline(infile, tmpStr, ',');
			v.lon = atof(tmpStr.c_str());
			std::getline(infile, tmpStr);
			v.lat = atof(tmpStr.c_str());
			if ( v.lon < -180 || v.lon > 180 ) {
				SEISCOMP_DEBUG("invalid longitude in file %s at line %i",
						       filename.c_str(), lineNum);
				continue;
			}
			if ( v.lat < -90 || v.lat > 90 ) {
				SEISCOMP_DEBUG("invalid latitude in file %s at line %i",
				               filename.c_str(), lineNum);
				continue;
			}

			if ( !feature->vertices().empty() ) {
				// check if the current vertex marks the end of a (sub-) or
				// feature and if so don't add it to the vertex vector but mark
				// the next vertex as the starting point of a new sub feature
				if ( v == feature->vertices().front() ) {
					startSubFeature = true;
					continue;
				}
				// Don't add the vertex if it is equal to the start point of
				// the current subfeature
				else if ( !startSubFeature &&
				         !feature->subFeatures().empty() &&
				         v == feature->vertices()[feature->subFeatures().back()] ) {
					continue;
				}
			}
			feature->addVertex(v, startSubFeature);
			startSubFeature = false;
		}
	}

	return true;
}