# Snapping point to point based on attribute?

I'm using ArcMap.

I have two identical point feature classes, one snapped to a line and the other not. Each point represents a telecommunication pole and the line represents fiber optic cable. I sequence the poles to the fiber optic cable line using the 'Route Events GeoProcessing Wizard' which by design, snaps all points to the fiber cable. I then have to manually snap the points that don't belong on the fiber line manually, which is very time consuming. Is there a way to snap two identical point feature classes with unique ID's together, instead of snapping based off proximity?

• Do the Points have an ID or other field that has the same value to identify identical Points? One point is now moved and the other point is at the original position. Oct 24, 2016 at 21:48
• Yes, each point has has a unique ID field. The two point feature classes are replicas of each other except one has all the poles snapped to the line. There may be 80 poles I need snapped to their original location while leaving the remaining poles snapped to the line. Oct 26, 2016 at 15:23

You can move geometries using da.UpdateCursor:

``````pt_on_line = 'orginal_points'
pt_on_line_ID = 'FID' # common ID field
pt_off_line = 'points_to_move'
pt_off_line_ID = 'FID' # common ID field
pt_on_line_dict = {str(row[0]):row[1] for row in arcpy.da.SearchCursor(pt_on_line,[pt_on_line_ID,"SHAPE@"])} # make dictionary, like {ID:geometry}
with arcpy.da.UpdateCursor(pt_off_line,[pt_off_line_ID,"SHAPE@"]) as cursor:
for row in cursor: # loop through points
row[1] = pt_on_line_dict[str(row[0])] # move point geometry to match point geometry from dictionary
cursor.updateRow(row) # update the geometry
``````

Of course, Python is for consenting adults. This will move your data, so you may want to test on a backup.

• I appreciate you taking the time to write out this script. Would you know of a place I can read on how to actually put this to use inside ArcMap? Oct 31, 2016 at 12:42
• I run small scripts like this in the Python Window in ArcMap. This is a good starting point for help: desktop.arcgis.com/en/arcmap/latest/analyze/arcpy/… Oct 31, 2016 at 16:32

Useful script @phloem - thanks! I suggest adding a KeyError handling exception, especially if there are missing keys in the dict, e.g.,

``````...
with arcpy.da.UpdateCursor(pt_off_line,[pt_off_line_ID,"SHAPE@"]) as cursor:
for row in cursor: # loop through points
try:
row[1] = pt_on_line_dict[str(row[0])] # move point geometry to match point geometry from dictionary
cursor.updateRow(row) # update the geometry
except KeyError:
print("{} doesn't have a match".format(row[0]))
``````