Hello
I have created a points feature class from a spreadsheet with the Add data-> XY Point data.
I have since gotten an updated spreadsheet where some of the points have new X and Y coordinates.
Is there a way to update the position of the old points based on the new coordinates?
Thank you
Solved! Go to Solution.
I am assuming your xy event theme is not a featureclass.
You could join the new data to the old data using the ID field and use the field calculator to copy over the x, y coordinates from the new data's fields to the old data's x, y fields, then.... add the table as an X Y event theme. If it works, then copy features to a new feature class since the shape field won't get updates in a featureclass
You could map the new data the same way you did the original data. Then since there is a common ID field, you could then join the original data to the new data, calculate your fields if necessary to make the new data match the original data, and then your point locations will be updated.
Is the new data just the updated point locations and their data?
Has an id or some other key field been used in the spreadsheet that would facilitate joins?
Yes the new data is the just the updated coordinates.
They do have an ID field attached to them.
I am assuming your xy event theme is not a featureclass.
You could join the new data to the old data using the ID field and use the field calculator to copy over the x, y coordinates from the new data's fields to the old data's x, y fields, then.... add the table as an X Y event theme. If it works, then copy features to a new feature class since the shape field won't get updates in a featureclass
You could map the new data the same way you did the original data. Then since there is a common ID field, you could then join the original data to the new data, calculate your fields if necessary to make the new data match the original data, and then your point locations will be updated.
As said before join the new data to the old data using an ID field. Fields containing new x and y values is named x_new and y_new. Then With Calculate Field use a python expression...
Field Name (Existing or New):
SHAPE
Expression:
shiftCoordinates(!SHAPE!,!x_new!,!y_new!)
Code block:
def shiftCoordinates(shape,x_new,y_new):
point = shape.getPart(0)
point.X = x_new
point.Y = y_new
return point
Hit Run and the geometry is updated.
The Calculate Field using the "shiftCoordinates" expression does not move the points, does it? Doesn't that just update the coordinates in the attribute table?
If anyone (including OP) is still watching this thread... I have the same problem except in my case I have photos attached to the feature class in the geodatabase and now I need to update the location of those points (about 1,000 of them) to the X,Y coordinates (lat/long) in the attribute table.
So what I need to do is run a tool that will move the points to the latitude and longitude I already have specified in the attribute table for each point. This seems like such a simple task for GIS and one that people run into often, but I cannot find any solutions.
HELP!!
I figured out a solution using UpdateCursor that was actually really simple! See script below.
import arcpy
# Set the local parameters
inFeatures = "Survey"
# Move the Features
with arcpy.da.UpdateCursor(inFeatures, ["SHAPE@XY","Longitude","Latitude"]) as cursor:
for row in cursor:
row[0] = ([row[1],row[2]])
cursor.updateRow(row)
@CCMM Have you ever hit this error?
Traceback (most recent call last):
File "<string>", line 6, in <module>
RuntimeError: Invalid SQL syntax [near "For": syntax error] [GDB_Items]
The only things I altered were my field names:
# Set the local parameters
inFeatures = "xy_test"
# Move the Features
with arcpy.da.UpdateCursor(inFeatures, ["Shape@XY","POINT_X","POINT_Y"]) as cursor:
for row in cursor:
row[0] = ([row[1],row[2]])
cursor.updateRow(row)