Skip to content

Instantly share code, notes, and snippets.

@hunterwei
Created January 19, 2018 16:02
Show Gist options
  • Save hunterwei/b6954467e934b4abd471ed35ad33c566 to your computer and use it in GitHub Desktop.
Save hunterwei/b6954467e934b4abd471ed35ad33c566 to your computer and use it in GitHub Desktop.
A python script snippet to quickly get the extent of polygon feature(s)
import arcpy
LAYER_NAME="Your layer name"
FIELD_NAME="Your field name"
shapeFieldName = arcpy.Describe(LAYER_NAME).shapeFieldName
rows = arcpy.SearchCursor(LAYER_NAME)
for row in rows:
fieldValue = row.getValue(FIELD_NAME).strip()
feat = row.getValue(shapeFieldName)
extent = feat.extent
print "'{0}' : {{ 'xmin':{1}, 'ymin':{2}, 'xmax':{3}, 'ymax':{4} }},"
.format(fieldValue, extent.XMin, extent.YMin, extent.XMax, extent.YMax)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment