Row.shape and .extent

4653
6
03-05-2013 05:58 AM
JT2
by
New Contributor II
I was figuring out how to get a dataset's extent via python. In the help entry for extent I was intrigued to note the following sample code snippet:

for row in sCur:
    geom = row.shape
    ext = geom.extent


I am unable to find any information in the help files on the .shape class. Can anyone tell me about it? I had thought that you had to do something like this:

arcpy.Describe("Layer").extent.xmin


...so I was surprised to see this .shape.extent property. As far as I can see it's undocumented. Where am I going wrong, or where should I look? Thanks
Tags (2)
0 Kudos
6 Replies
MathewCoyle
Frequent Contributor
It is part of the geometry object and is definitely documented.

http://resources.arcgis.com/en/help/main/10.1/index.html#//018z00000070000000
0 Kudos
ChrisSnyder
Regular Contributor III
To get the extent xmin bound of the entire layer:
arcpy.Describe("Layer").extent.XMin


To get the extent xmin bound of each feature in the layer:
searchRows = arcpy.da.SearchCursor("layer",["OID@","SHAPE@"])
for searchRow in searchRows:
    oidValue = searchRow[0]
    xminExt = searchRow[1].extent.XMin
    print "OID = " + str(oidValue) + " has an xmin extent of " + str(xminExt)
0 Kudos
JT2
by
New Contributor II
It is part of the geometry object and is definitely documented.

http://resources.arcgis.com/en/help/main/10.1/index.html#//018z00000070000000


Thanks for the pointer, but I cannot find any reference to .shape on the page you linked. There is no property of the Geometry class called 'shape'. So, as far as I can see, my original question stands: where is .shape documented?

Why does the following work, when the Row class doesn't even have a property called 'shape'? And why is there no object model diagram? It's so difficult to see how classes interact when you have to hop from one help entry to the other. We need a diagram to see how they fit together!

>>> cur = arcpy.SearchCursor("Landscan_Sample")
>>> for row in cur:
...     print row.shape.extent.XMax
... 
-10.8041666667

-10.7958333333

-10.7875
0 Kudos
MathewCoyle
Frequent Contributor
Thanks for the pointer, but I cannot find any reference to .shape on the page you linked. There is no property of the Geometry class called 'shape'. So, as far as I can see, my original question stands: where is .shape documented?

Why does the following work, when the Row class doesn't even have a property called 'shape'? And why is there no object model diagram? It's so difficult to see how classes interact when you have to hop from one help entry to the other. We need a diagram to see how they fit together!

>>> cur = arcpy.SearchCursor("Landscan_Sample")
>>> for row in cur:
...     print row.shape.extent.XMax
... 
-10.8041666667

-10.7958333333

-10.7875


It accesses the shape field, which is a geometry object. You could get the same with
geom = row.getValue('Shape')
0 Kudos
JT2
by
New Contributor II
Oh I see, thanks for pointing that out. Yes, according to this page http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001q000000:

There are two basic ways to get and set field values on a row:
Using the field name, as in value = row.road_type
Using getValue and setValue, as in value = row.getValue("road_type")


How incredibly confusing that there's no way to tell if the .property is referring to a field name or a class/property. And what would happen if your field was called 'length'? Which takes precedence, the field name 'length', or the .length property of the Geometry class? How on earth are we meant to differentiate when reading others' code? Very confusing...
0 Kudos
MathewCoyle
Frequent Contributor
The properties are all listed in the help which you linked to in a previous post. It is pretty simple to tell the difference. A property of row requires a parameter.
row.getValue(field)

Whereas a field referenced by the row object does not.
row.field

If for some reason you happen to have a row with the same name as a property, such as getValue, the property will take precedence. Your example of length doesn't work since it is a property of the geometry object not the row. It is accessed like this.
row.shape.length
0 Kudos