I have changed the coordinates of couple points in the attribute table and I want to update the location. I have found the script that is working in field calculator.
Does anybody know how to write it using a Python script in ArcGIS Desktop (not in Field Calculator)?
def XYsetVALUE( shape, X_value, Y_value):
point = shape.getPart(0)
point.X = X_value
point.Y = Y_value
return point
__esri_field_calculator_splitter__
XYsetVALUE ( !SHAPE!, !X_COORD!, !Y_COORD! )
COORDINATE FIELD TYPE ------ STRING !!!!
Answer
Use the UpdateCursor for this with the SHAPE@X and SHAPE@Y tokens. This will change the data so backup before executing:
import arcpy
feature_class=r'C:\Default.gdb\Points' #Change to match your data
fields=['X_coord','Y_coord'] #Change to match your column names containing x and y coordinates
with arcpy.da.UpdateCursor(feature_class,['SHAPE@X','SHAPE@Y']+fields) as cursor:
for row in cursor:
row[0]=float(row[2])
row[1]=float(row[3])
cursor.updateRow(row)
No comments:
Post a Comment