AnsweredAssumed Answered

I need to move a set of point features based on the XY values from another feature class

Question asked by LarryAdgate on Apr 2, 2018
Latest reply on Apr 2, 2018 by rvburton

#My goal is similar to the thread listed below:
#https://community.esri.com/thread/158291
#"I need to move a set of point features based on the XY values from another table linked through table join"

#This script works perfectly as long as the feature class with the outdated xy's have no duplicate "PREM_ID" numbers.
# A "PREM_ID" number represents a Geocoded address point and its possible to have several of them stacked on top of each other on one parcel.
#Unfortunately my outdated xy feature class has a combination of both unique and duplicate PREM_ID numbers and this script will not pass duplicate PREM_ID numbers.
#IndexError: list index out of range
#Thank You for your assistance,
#Larry Adgate

 

import arcpy

#input path of gdb where original feature class resides
gdb = "C:\\Projects\\MyProject\\Arden.gdb"

#input original feature class path with outdated XY (This feature Class has both unique and duplicate "PREM_ID" numbers)
basefc = "C:\\Projects\\MyProject\\Arden.gdb\\Arden\\LateralLinesPoints"

#input feature class path of points with updated XY (This Feature Class contains only unque "PREM_ID numbers
#and not all there numbers can be found in the outdate xy feature class)
newfc = "C:\\Projects\\MyProject\\Arden.gdb\\Arden\\CCB_Points"

#input field name which has a unique ID to both original and new point feature class
field = "PREM_ID"

list_idxy = []
with arcpy.da.SearchCursor(newfc, [field, "SHAPE@X", "SHAPE@Y"]) as cur:
for row in cur:
list_idxy.append(row)
i = 0
with arcpy.da.Editor(gdb) as edit:
with arcpy.da.UpdateCursor(basefc, [field, "SHAPE@X", "SHAPE@Y"]) as cur:
for row in cur:
print row
if row[0] == list_idxy[i][0]:
row[1] = list_idxy[i][1]
row[2] = list_idxy[i][2]
i += 1
cur.updateRow(row)
print "points shifted!"

Outcomes