Skip to content

Instantly share code, notes, and snippets.

@maptastik
Created February 12, 2020 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maptastik/4f92dd08503f6f334004108736aff579 to your computer and use it in GitHub Desktop.
Save maptastik/4f92dd08503f6f334004108736aff579 to your computer and use it in GitHub Desktop.
import arcpy
# Assume a feature class called polygon_fc with two separate float/double fields, x and y
with arcpy.da.UpdateCursor('polygon_fc', ['SHAPE@', 'x', 'y']) as cursor:
for row in cursor:
geom_4326 = row[0].projectAs(arcpy.SpatialReference(4326))
row[1] = geom_4326.centroid.X
row[2] = geom_4326.centroid.Y
cursor.updateRow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment