Friday, July 13, 2012

Create a List of Geometries (10.1)

At 10.1, you can use geometries directly in geoprocessing functions like Clip or reading geometry properties.  Here is a tip to copy all the geometries into memory and use it as a list:

import arcpy
ds = r"c:\temp\sample.gdb\Parcels"
g = arcpy.Geometry()
geomList = arcpy.CopyFeatures_management(ds,g)
# Get the Area (Sq Ft)
area = 0.0
for geom in geomList:
    area += geom.area
print "Total Parcel Area: {0}".format(area)

The CopyFeatures() copies the results as a geometry object to a list and the area property is a standard Geometry object property.