#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[0]:
row[1] = list_idxy[1]
row[2] = list_idxy[2]
i += 1
cur.updateRow(row)
print "points shifted!"
Solved! Go to Solution.
You might try something like:
# empty dictionary
dict = {}
# read PREM_ID as key and coordinates
with arcpy.da.SearchCursor(newfc,['PREM_ID','SHAPE@X','SHAPE@Y']) as cur:
for row in cur:
dict[row[0]]= {'x':row[1],'y':row[2] }
# update old feature
with arcpy.da.UpdateCursor(basefc,['PREM_ID','SHAPE@X','SHAPE@Y']) as upCur:
for row in upCur:
# if PREM_ID is in dictionary, update x,y else skip update
if row[0] in dict:
row[1] = dict[row[0]]['x']
row[2] = dict[row[0]]['y']
upCur.updateRow(row)
print "Updated {}".format(row[0])
What do you want to do if a duplicate PREM_ID is found?
Hi James thank you for your assistance,
If a duplicate PREM_ID is found which is also a duplicate address, it should also go to the same XY as the other duplicate/s. The points will probably stack up in same spot or same xy position.
You might try something like:
# empty dictionary
dict = {}
# read PREM_ID as key and coordinates
with arcpy.da.SearchCursor(newfc,['PREM_ID','SHAPE@X','SHAPE@Y']) as cur:
for row in cur:
dict[row[0]]= {'x':row[1],'y':row[2] }
# update old feature
with arcpy.da.UpdateCursor(basefc,['PREM_ID','SHAPE@X','SHAPE@Y']) as upCur:
for row in upCur:
# if PREM_ID is in dictionary, update x,y else skip update
if row[0] in dict:
row[1] = dict[row[0]]['x']
row[2] = dict[row[0]]['y']
upCur.updateRow(row)
print "Updated {}".format(row[0])