get feature extent error

549
2
Jump to solution
08-03-2011 05:42 PM
YinghaiKe
New Contributor
I was trying to follow an python script example of getting extent of features (Note "test.shp" is polygon feature)

________________________________________________________
import arcpy
from arcpy import env

env.workspace = "C:/Data/"

sCur = arcpy.SearchCursor("test.shp", "","","ID_1" )

# Fetch each feature from the cursor and examine the extent properties
#
for row in sCur:
    geom = row.shape
    ext = geom.extent  # or row.Shape.extent
    print "Extent of feature:\nXMin: %f, YMin: %f, \nXMax: %f, YMax: %f" % \
             (ext.XMin,ext.YMin,ext.XMax,ext.YMax)
_________________________________________________________________

The script stopped at "ext = geom.extent". The error message shows:
    ext = geom.extent
AttributeError: 'passthrough' object has no attribute 'extent'

I don't know how to fix it. Any idea? Thanks!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
I believe the problem is with the Search cursor.  You have:

sCur = arcpy.SearchCursor("test.shp", "","","ID_1")


When specifying "ID_1" you are limiting the search cursor to this specific field, but you are trying to query the "Shape" field's extent.  I would recommend keeping this parameter empty, or including the ''Shape'' field.  Ex:

sCur = arcpy.SearchCursor("test.shp", "","","ID_1; Shape")


or

sCur = arcpy.SearchCursor("test.shp")

View solution in original post

0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
I believe the problem is with the Search cursor.  You have:

sCur = arcpy.SearchCursor("test.shp", "","","ID_1")


When specifying "ID_1" you are limiting the search cursor to this specific field, but you are trying to query the "Shape" field's extent.  I would recommend keeping this parameter empty, or including the ''Shape'' field.  Ex:

sCur = arcpy.SearchCursor("test.shp", "","","ID_1; Shape")


or

sCur = arcpy.SearchCursor("test.shp")
0 Kudos
YinghaiKe
New Contributor
Hi Jake, It works. Thank you very much!
0 Kudos