[Gdal-dev] OGRGeometry::Contains speed issue

Rob McCulley RMcCulley at county24.com
Wed Feb 8 15:44:01 EST 2006


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




More information about the Gdal-dev mailing list