[FWTools] GEOS contains fails after multiple iterations

Bryan Keith bryan at geomega.com
Wed Feb 22 12:12:56 EST 2006


I'm having a problem with GEOS using Python and FWTools1.0.09a on 
Windows 2000.  I've simplified my code to the point where I can 
reproduce the error in this short script:

import ogr
#get valley file polygon
myVFPY = ogr.CreateGeometryFromWkt("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))")
#get grid shapefile
ogrSDS = ogr.Open("S:\\ProductionData\\Data\\GWModel", 1)
ogrSLayer = ogrSDS.GetLayerByName("grid_py")
#for i in range(ogrSLayer.GetFeatureCount()):
#for i in range(10, 100):
for i in range(100, 200):
    print str(i)
    myFeature = ogrSLayer.GetFeature(i)
    myGeom = myFeature.GetGeometryRef()
    myPTC = myGeom.Centroid()
    #the following line fails at the 33rd time in the loop
    if myVFPY.Contains(myPTC):
        print "Contains myPTC"
    else:
        print "Does not contain myPTC"


I get a "memory could not be read" error from the Contains() method 
during the 33rd iteration of the loop.  The failure is not dependent on 
the point as I've tested various sets of features in ogrSLayer.  The 
failure always happen the 33rd time through the loop.  Nor is the 
failure dependent on the shapefile or the polygon.  I've tested multiple 
of each.

Anyone know what I'm doing wrong here?

Bryan

Bryan Keith
GIS Specialist
Geomega, Inc.
Boulder, CO, USA


More information about the FWTools mailing list