Moving / offsetting point locations using ArcPy or ModelBuilder?
This code should do it using the SHAPE@XY token that came with arcpy.da.UpdateCursor in ArcGIS 10.1.
import arcpy
# Set some variables
fc = r"C:\temp\test.gdb\testFC"
fc2 = r"C:\temp\test.gdb\testFCcopy"
xOffset = 0.001
yOffset = 0.001
# Code to make a copy which will have its coordinates moved (and can be compared with original)
if arcpy.Exists(fc2):
arcpy.Delete_management(fc2)
arcpy.Copy_management(fc,fc2)
# Perform the move
with arcpy.da.UpdateCursor(fc2, ["SHAPE@XY"]) as cursor:
for row in cursor:
cursor.updateRow([[row[0][0] + xOffset,row[0][1] + yOffset]])
The coding pattern used here came from ArcPy Café.
I credit @artwork21 for leading me to my final solution. I actually found a nearly complete script in the ArcGIS 10.0 online help article called "Calculate Field examples", listed under the subcategory "Code samples—geometry" and "For a point feature class, shift the x coordinate of each point by 100"
The final script that I used within the ModelBuilder "Calculate Field" tool was:
Expression:
shiftXYCoordinates(!SHAPE!,%ShiftX%,%ShiftY%)
where ShiftX and ShiftY are variables (as parameters) defined on the ModelBuilder canvas.
Expression Type:
PYTHON_9.3
Code Block:
def shiftXYCoordinates(shape,x_shift,y_shift):
point = shape.getPart(0)
point.X += float(x_shift)
point.Y += float(y_shift)
return point
Since all models work on a selected set, you should also be able to create this as a generic tool that will work in conjunction with other models/tools in other modelbuilder sessions. The very simple model I created (as a "plugin" to other models to shift coordinate values) looks like this. That way I can control the shift on a per-selection-set basis (as defined in other models):
It worked like a charm, thank you all for your input!
You may also use this field calculator script to move feature locations:
def XYsetVALUE( shape, X_value, Y_value):
myMoveX = 0.001
myMoveY = 0.001
point = shape.getPart(0)
point.X = X_value + myMoveX
point.Y = Y_value + myMoveY
return point
XYsetVALUE ( !SHAPE!, !X_COORD!, !Y_COORD! )
You could include an extra Calculate Field method within your model using the function above.