Select to view content in your preferred language

Moving the last vertices

1850
11
Jump to solution
02-03-2014 10:00 AM
DavidNarkewicz
Deactivated User
Hi All,

I have a feature class made up of lines. Each of these lines are loops. Therefore they have the same beginning and ending xy coordinates. I am looking to move the end vertices for each line a known value away to disconnect each loop. I understand that through editor I can manually change the end vertices for each loop in sketch properties but I am looking for an automated way to move the last/end vertices of each line in my feature class the same known distance.

Example: I move each line's end vertex 5 meters in the x direction and 5 meters in the y direction.

Any guidance would be greatly appreciated.

Thanks!
Tags (2)
11 Replies
XanderBakker
Esri Esteemed Contributor
Hi David,

Indeed the assumption "firstpnt = part[len(part) + 0]" is wrong. The "part" represents a list of points. Between the square brackets you put the index to the point you're interested in. The list index starts with 0 (for the first point) and ends with the number of points minus 1. Therefor, in case of the last point we used "len(part) - 1", which is the number of points - 1. For the first point you just use index 0.

import arcpy
fc = r'c:\yourFGDB.gdb\yourLines'

# update cursor (be careful with this and try it on a copy of your data)
fields = ["SHAPE@","XCentroid","YCentroid"]
with arcpy.da.UpdateCursor(fc,fields) as curs:
    for row in curs:
        geom = row[0]
        x_new = row[1]
        y_new = row[2]
        array = arcpy.Array()
        for part in geom:
            firstpnt = part[0]
            firstpnt.X = x_new
            firstpnt.Y = y_new
            part[0] = firstpnt
            array.add(part)
        curs.updateRow([arcpy.Polyline(array), x_new, y_new])


Hope this explanation helps you to achieve your goal.

Kind regards,

Xander
0 Kudos
DavidNarkewicz
Deactivated User
Xander and Ian,

Thank you very much for the quick response! I understand the concept and why the code was wrong. You solved my problem.

David
0 Kudos