Relocating multiple points

846
3
01-07-2022 07:10 AM
Labels (2)
LoganMillerGA
New Contributor

Hello All,

I'm trying to move points inside of a specific polygons. The image below represents water meters outside of there specific polygons. They both have location IDs associated with them, and the meters ID should match up with the polygons ID that its inside of. Is there a tool/way to move them into there correct polygon on a massive scale, and not have to do it individually? I hope this makes sense.

Meter.PNG

 Thanks!!!

0 Kudos
3 Replies
AdminGIS2
New Contributor III

I don't think there's a pre-built tool to do this. If it doesn't matter where in the polygon the point is moved it should be a possible using a fairly short script by replacing the point geometry by the centroid geometry from the polygon. Something like this should work (not tested): 

import arcpy

# starting data
point_featureclass = "path_to_point_featureclass"
polygon_featureclass = "path_to_point_featureclass"

# compose a dictionary with the the ID and new geometry as pairs
new_point_dict= {row[0]: row[1] for row in arcpy.da.SearchCursor(polygon_featureclass , ["ID_FIELD", "SHAPE@XY"])}

# overwrite point geometry with centroids from point feature class
with arcpy.da.UpdateCursor(point_featureclass, ["ID_FIELD", "SHAPE@"]) as cursor:
    for row in cursor:
        if row[0] in new_point_dict:
            row[1] = new_point_dict[row[0]]
            cursor.updateRow(row)

 

 

0 Kudos
LoganMillerGA
New Contributor

it shouldn't matter just as long as it with the polygon. thanks for the Help

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

I could think of a workaround. Please check if that works for you.

1. Using the Polygon layer, execute Feature To Point (Data Management). Check INSIDE option. The output would be point layer with the attributes of the corresponding polygons.

2. Using  Join Field (Data Management), transfer all the required fields from Water Meter points to the above point layer based on Location ID field.

You could use the updated point layer as the new Water Meter Point layer. Delete the unwanted fields, if necessary.



Think Location