You’re probably familiar with using feature classes, feature layers or feature sets as parameters of geoprocessing tools in your Python code, but you may not be aware that you can also use instances of Geometry, MultiPoint, PointGeometry, Polygon and PolyLine objects in exactly the same way. This can save time creating feature classes that you really don’t want to persist, for those times you need a geometric property or method momentarily in your script. Here is a snippet that illustrates the concept (in real life we would take care to manage the spatial references of geometries too):
#Make a 5000m buffer around a sample point
SamplePoint = arcpy.Point(1765863,5926652)
SamplePointGeometry = arcpy.PointGeometry(SamplePoint)
outGeom = arcpy.Geometry()
outGList = arcpy.Buffer_analysis(SamplePointGeometry,outGeom,”5000 Meters”)
print str(outGList[0].area) + ” Square Meters”
78539816.3397 Square Meters
Note that when a Geometry object is given as the output “feature class”, tool outputs are Python lists of geometry features. Therefore, as above, you will need to specify an index position to retrieve a feature.
A powerful way to use Geometry objects in this way is within cursors, to operate on a feature class geometry with row granularity.
Content provided by Bruce Harold
Commenting is not enabled for this article.