[FWTools] ogr2ogr -spat extents

Frank Warmerdam warmerdam at pobox.com
Tue Apr 4 23:25:33 EDT 2006


Travis Kirstine GIS Tech wrote:
> I've been test the ogr2ogr utility program to create shapefiles based on
> spatial extents.  The problem I'm having is that the resulting shapefiles
> contains features beyound the defined extents.  I've attached a jpeg to
> illustrate the problem where the box is the extents purple polygons are the
> dst_datasource
> 
> Commandline
> ogr2ogr -f "ESRI Shapefile" -spat 610400 4819000 610500 4819100 output2.shp
> lro_test_3.shp

Travis,

In order to optimize spatial queries, they are defined to return at least
all the features intersecting the search region, but possibly some extras.
In this case, the logic is to compare the search rectangle to the bounding
rectangle of each feature geometry, and return any geometries for which the
boxes intersect (even if the actual geometry does not intersect).  It is
hard to be sure in this example, but I think this is what is happening
here.

If you use a GEOS enabled build of OGR, such as FWTools it should be possible
to write a python script that does an exact query.  It will basically do the
same spatial query you are doing now, but also apply the Intersect() test
afterwards to ensure the actual geometry intersects the target region.

Let me know if you need an example of such a script.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGF, http://osgeo.org



More information about the FWTools mailing list