[Gdal-dev] Free OGRGeometry?

Craig Miller craig.miller at spatialminds.com
Fri Nov 25 14:10:32 EST 2005


I'm trying to set a spatial filter, but am having difficulty determining how
I am supposed to create and free OGRGeometry correctly.  In ogr2ogr the
spatial filter doesn't appear to be freed.  In my code, this is causing a
memory leak.  What is the best way to allocate/deallocate OGRGeometry?

In ogr2ogr it done like this:

// inside of main()
// Declared
OGRGeometry *poSpatialFilter = NULL;

// Initialized
OGRLinearRing  oRing;

oRing.addPoint( atof(papszArgv[iArg+1]), atof(papszArgv[iArg+2]) );
oRing.addPoint( atof(papszArgv[iArg+1]), atof(papszArgv[iArg+4]) );
oRing.addPoint( atof(papszArgv[iArg+3]), atof(papszArgv[iArg+4]) );
oRing.addPoint( atof(papszArgv[iArg+3]), atof(papszArgv[iArg+2]) );
oRing.addPoint( atof(papszArgv[iArg+1]), atof(papszArgv[iArg+2]) );

poSpatialFilter = new OGRPolygon();
((OGRPolygon *) poSpatialFilter)->addRing( &oRing );

// Used
if( poSpatialFilter != NULL )
	poLayer->SetSpatialFilter( poSpatialFilter );

// Freed?









More information about the Gdal-dev mailing list