Skip to main content
2 of 5
deleted 37 characters in body
User1974
  • 198
  • 1
  • 19

Loop through polyline vertices and update coordinate

I have a Python 2.7 script that loops through GIS polylines and updates a coordinate.

The coordinate is called an "M" coordinate (aka a "Measure-value"). M coordinates are similar to X and Y coordinates, but are used for specialized linear referencing purposes.

enter image description here

More info: Set M-values to cumulative length of line

import arcpy
connection = "Database Connections\my_conn.sde"
fc = connection + "\my_owner.my_fc"
spatialRef = arcpy.Describe(fc).spatialReference

with arcpy.da.Editor(connection) as editSession:
    with arcpy.da.UpdateCursor(fc, ["ASSET_ID", "SHAPE@"]) as cursor:
        for row in cursor:
            feature = row[1].densify ("ANGLE", 10000, 0.174533)
            partNum = 0
            partArray = arcpy.Array()
            for part in feature:
                pointArray = arcpy.Array()
                n = len(part)
                for i in range(n):
                    point = part.getObject(i)
                    point.M = feature.measureOnLine(point)
                    pointArray.append(point)
                partArray.append(pointArray)
                partNum += 1
            row[1] = arcpy.Polyline(partArray, spatialRef)
            cursor.updateRow(row)

How can the script be improved?

User1974
  • 198
  • 1
  • 19