I have a feature class with x/y values populated on the native projection of the feature class (state plane).
In the same feature class I also have Lat/Long fields that I need to populate (WGS 84 in decimal degree).
The problem I have is the calculate geometry function doesn't allow me to choose a different projection other than State Plane when I try to auto populate the Lat/Long values.
Does anyone have any python code or ideas that might help with this request?
Answer
you just need to run a cursor on it and use the projectAs()
geometry method.
import arcpy
fc = r'C:\path_to\your_data\points.shp'
wgs = arcpy.SpatialReference(4326)
with arcpy.da.UpdateCursor(fc, ['SHAPE@', 'lat_field', 'long_field']) as rows:
for row in rows:
pnt_wgs = row[0].projectAs(wgs)
row[1:] = [pnt_wgs.centroid.Y, pnt_wgs.centroid.X] #will be in decimal degrees
rows.updateRow(row)
No comments:
Post a Comment