Skip to content

Instantly share code, notes, and snippets.

@knu2xs
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save knu2xs/3de2b99f924082f7de76 to your computer and use it in GitHub Desktop.

Select an option

Save knu2xs/3de2b99f924082f7de76 to your computer and use it in GitHub Desktop.
Get centroid of an entire feature class
# import modules
import arcpy
# set variables to make life easier
fc = "Wilderness"
def get_centroid(feature_class):
# use describe to create an extent obejct to work with
extent = arcpy.Describe(feature_class).extent
# calculate centroid using a little arithmitic
centroid_x = extent.XMax - extent.XMin + extent.XMin
centroid_y = extent.YMax - extent.YMin + extent.YMin
# return the result as a tuple
return [centroid_y, centroid_x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment