Move point features based on XY values

6613
3
Jump to solution
05-06-2015 08:13 PM
SiyangTeo
Occasional Contributor

Hi,

I have posted this question previously, but was unable to obtain a definite reply. Hence I am re-posting it once more.

I need to move a set of features based on the XY values from another table linked through table join.

I found a field calculator script (see below), but it was not perfect. This is because the this script can only work if the XY values are within the same table. It does not work with a table join.

Can anyone help to tweak this script or propose an alternative?

def pointMove(shape,x_value,y_value):
   point = shape.getPart(0)
   point.X = x_value
   point.Y = y_value
   return point

__esri_field_calculator_splitter__
pointMove( !Shape!, !X!, !Y! )

I am using ArcGIS Desktop 10.2.2.

Thanks!

Regards,

Siyang

0 Kudos
1 Solution

Accepted Solutions
SiyangTeo
Occasional Contributor

After playing around with some arcpy, I managed to overcome the limitation of the field calculator by using this stand alone Python script:

import arcpy

#input path of gdb where original feature class resides
gdb = "C:\Users\XXX\Test.gdb"
#input original feature class path with outdated XY
basefc = "C:\Users\XXX\Test.gdb\featureclass_old"
#input feature class path of points with updated XY
newfc = "C:\Users\XXX\Test.gdb\featureclass_new"
#input field name which has a unique ID to both original and new point feature class
field = "fieldname"

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!"






View solution in original post

0 Kudos
3 Replies
curtvprice
MVP Esteemed Contributor

Sorry your thread got abandoned.

I'm not where I can test workarounds.... but I think the easiest solution would be to copy the XY fields to the local table using the Join Field tool, do the XY move, and then delete them when you're done if you don't need them.

SiyangTeo
Occasional Contributor

Thanks Price,

I have my hands tied on that option unfortunately.

The feature class is hosted in an ArcSDE gbd and I do not have the administrator access. It also requires quite a bit of effort (and $$) to make the changes. 😕

For now before a solution can be found, I have to stick to manual shifting by eye-balling and snapping the points together.

0 Kudos
SiyangTeo
Occasional Contributor

After playing around with some arcpy, I managed to overcome the limitation of the field calculator by using this stand alone Python script:

import arcpy

#input path of gdb where original feature class resides
gdb = "C:\Users\XXX\Test.gdb"
#input original feature class path with outdated XY
basefc = "C:\Users\XXX\Test.gdb\featureclass_old"
#input feature class path of points with updated XY
newfc = "C:\Users\XXX\Test.gdb\featureclass_new"
#input field name which has a unique ID to both original and new point feature class
field = "fieldname"

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!"






0 Kudos