[Gdal-dev] OGRGeometry::Contains speed issue

Sean Gillies sgillies at frii.com
Wed Feb 8 16:21:55 EST 2006


On Feb 8, 2006, at 1:44 PM, Rob McCulley wrote:

> Hi all,
>
> I've got a python script that runs through a bunch of shapefiles,  
> performs an OGRGeometry::Transform on them, adds a couple of  
> attributes, and merges them all into one final shapefile.  All told  
> it opens 76 shapefiles containing a total of ~18,000 polygons.  It  
> performs this in about 10 minutes.
>
> My area of interest is an irregular area which contains ~16,000 of  
> the polygons. I added in a couple of lines to the script to check  
> if the polygon was in the aoi, and set an attribute accordingly:
>
> point = newGeom.Centroid()
> aoiTest = aoiGeom.Contains(point)
> if aoiTest == 1:
> 	aoiVal = 1
> else:
> 	aoiVal = 0
>
> There shouldn't ever be a situation where a polygon will cross the  
> aoi boundary, but I use a centroid for the Contains, just in case  
> it isn't perfect.
>
> The problem I'm having is this makes things a lot slower.  The  
> first run through after adding those lines of code was ~17 hours  
> (At the end the script outputs the run time in seconds).  For my  
> purposes, 17 hours is too long.  I know that the aoi polygon is  
> quite complex (~4000 vertices), and that probably slows things down  
> a bit, but that much?  Am I missing something, or is there a better  
> way of doing this?
>
> Thanks
> Rob McCulley
> GIS Coordinator
> County of Vermilion River No. 24
> (780) 846-2244
> www.vermilion-river.ab.ca
>

Rob,

Try a two step approach:

1) if bounding boxes of the aoi and new geom intersect (fast):
2) make more rigorous evaluation of the intersection

aoiGeom.Intersects(newGeom) may be faster than computing the centroid  
and containment.

cheers,
Sean

---
Sean Gillies
sgillies at frii dot com
http://zcologia.com/news






More information about the Gdal-dev mailing list