I have a list of structures which need to be moved to specific Lat/Longs. Each Lat/Long is different. I wrote the code below to move all the structures to the lat/long which is stored in the attribute table. I am trying to use arcpy and the below python script to move the structures. currently the code below does move all the structures, but they are all moved to the lat/long of (0,0) instead of the lat/longs in the columns Lidar_Lat and Lidar_Long. How can I modify the code or other ways to mass move depending on lat/long.
Any Suggestions? Thanks.
import arcpy
# Define the feature class and its coordinate system
feature_class = "ValleyNelsonTMT_New4"
coordinate_system = arcpy.Describe(feature_class).spatialReference
# Define the table containing the X and Y coordinates
table_with_coordinates = "ValleyNelsonTMT_New4"
x_field = "Lidar_Long"
y_field = "Lidar_Lat"
# Create a search cursor to read the X and Y coordinates from the table
with arcpy.da.SearchCursor(table_with_coordinates, [x_field, y_field]) as cursor:
for row in cursor:
x_field = row[0]
y_field = row[1]
# Create a new PointGeometry object with the coordinates
new_point = arcpy.Point(x_field,y_field)
new_geometry = arcpy.PointGeometry(new_point, coordinate_system)
# Update the geometry of the structure
with arcpy.da.UpdateCursor(feature_class, ["SHAPE@"], spatial_reference=coordinate_system) as update_cursor:
for update_row in update_cursor:
update_row[0] = new_geometry
update_cursor.updateRow(update_row)
print("Done")