Move (shift) polylines

3004
3
08-18-2011 01:00 PM
EdwardChonón
New Contributor II
Someone could help me with a python script or something to move (shitfing) polylines through the x-axis and y axis

I can do this task manually in an edit session in ArcMap 10, using the "Move.." Command (Delta X, Y) in Toolbar Editor. But the idea is to automate this because it is part of a larger model.

Please anyone help me?

Thanks a million!
Tags (2)
0 Kudos
3 Replies
ChristopherFricke1
New Contributor
Your best bet is to do this automation with a cursor.

Check out
* Update cursor - http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000003m000000.htm
* Working with geometry - http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Working_with_geometry_in_Python/002z00...

I haven't tested this, but you will do something like:
shapeField = arcpy.Describe("Feature Class").ShapeFieldName
deltaX = 10
deltaY = 10

c = arcpy.UpdateCursor("Feature Class")
for row in c:
    partnum = 0
    feat = row.getValue(shapefieldname)
    for part in feat:
        for pnt in feat.getPart(partnum):
            pnt.X = pnt.X + deltaX
            pnt.Y = pnt.Y + deltaY
    c.updateRow(row)
0 Kudos
EdwardChonón
New Contributor II
Hello Christoph, thank you very much for your prompt response, I tried your code is executed, but the only thing that happens is that the attribute table is cleared, but the polylines are not moved, I attached the code I used you.

Displacement coordinates are not equal to x and y.

I enclose the shapefile with which I am doing the tests.

Thank you very much for your support, I'm checking the links you sent me help, but would appreciate very much your help with this issue.

Many thanks

Edward

import arcpy
shapeField = arcpy.Describe(r"C:\2011\ACCESOS\accesos_yan_loc_psad56.shp").ShapeFieldName
deltaX = 10
deltaY = 10

c = arcpy.UpdateCursor(r"C:\2011\ACCESOS\accesos_yan_loc_psad56.shp")
for row in c:
    partnum = 0
    feat = row.getValue(shapeField)
    for part in feat:
        for pnt in feat.getPart(partnum):
            pnt.X = pnt.X + deltaX
            pnt.Y = pnt.Y + deltaY
    c.updateRow(row)
0 Kudos
ChrisSnyder
Regular Contributor III
How about simply projecting your data with an altered false easting and false northing? Then define the prj of your altered dataset to be that of the original prj. You can programatically create/alter projection definitions though the gp/arcpy object.
0 Kudos