[gdal-dev] Reading Geometry from text file

moritzzz spam at kolix.de
Tue Oct 5 05:33:47 EDT 2010


Hey guys,

I just started using gdal/ogr and am running into a lot of problems. The
main one right now comes up when I'm trying to create a geometry from a
string that I read from a file. The line I'm reading looks like this:
MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2)),((6 3,9 2,9 4,6
3)))

Now I wrote some c++ code that's supposed to create a OGRMultipolygon in
which line is the mentioned line from the file:

double* kdTreeMgmtServer::process_polygon(string line, string path) {
	char* lineArr = (char*) line.c_str();

	OGRGeometry* new_geom;
	OGRGeometryFactory::createFromWkt(&lineArr, NULL, &new_geom);
	if (wkbFlatten(new_geom->getGeometryType()) != wkbMultiPolygon) {
		log_error("not a multipolygon! geometrytype =
%d\n",new_geom->getGeometryType());
		return NULL;
	}
	if (!new_geom->IsValid()) {
		log_debug("line is invalid: '%s'\n", line.c_str());
	}
	OGRMultiPolygon* poly = (OGRMultiPolygon*) new_geom;
	poly->get_Area();
}

The first part seems to work fine, as the geometry is recognized as a
multipolygon but the validation always fails and poly->get_Area(); causes a
crash of the code. What am I doing wrong?

Cheers

Moritz
-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Reading-Geometry-from-text-file-tp5602472p5602472.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list