[gdal-dev] Geometry.Within error

Spencer Gardner sjgardner at wisc.edu
Mon Mar 8 18:51:51 EST 2010


I'm writing a script that tests whether a feature lies completely within features of another layer.  When the script runs, it gives me the following error:

Traceback (most recent call last):
  File "landuse.py", line 82, in <module>
    if landGeom.Within(bufferGeom):
AttributeError: 'NoneType' object has no attribute 'Within'

I don't know Python well enough to know exactly what that error is telling me.  I was able to run the script several days ago without problems and don't remember making any significant modifications since that time.  In the meantime, I have received an update to OGR.  Could this be a bug introduced by the update?

Thanks for the help,
Spencer Gardner
----------------------------
relevant code:

while nodesFeature:

  # buffer the nodes by .5 miles (2640 feet)
  nodesGeom = nodesFeature.GetGeometryRef()
  bufferGeom = nodesGeom.Buffer(2640)


  # use bufferGeom as a spatial filter on the node to get all parcels
  # within .5 miles
  landLayer.SetSpatialFilter(bufferGeom)

  # set up the resarea and totalarea variables
  resarea = 0
  totalarea = 0

  # select the first feature in land use
  landFeature = landLayer.GetNextFeature()

  # loop through each land feature and check if it falls entirely within the buffer
  while landFeature:
    landGeom = landFeature.GetGeometryRef()
    if landGeom.Within(bufferGeom):
      lucode = landFeature.GetFieldAsInteger(landFeature.GetFieldIndex('LUCODE'))
      area = landGeom.GetArea()
      totalarea += area
      if lucode == 111 or lucode == 113 or lucode == 115:
        resarea += area

    # close things down and move to the next landFeature
    landFeature.Destroy()
    landFeature = landLayer.GetNextFeature()
  

  # write the resarea and total area for each node
  nodesFeature.SetField(nodesFeature.GetFieldIndex('TOTAREA'), totalarea)
  nodesFeature.SetField(nodesFeature.GetFieldIndex('RESAREA'), resarea)


More information about the gdal-dev mailing list