Skip to main content
5 of 6
added 387 characters in body
GeoSharp
  • 3.3k
  • 18
  • 28

This can be a bit tricky with polylines as the z-values of each vertice are not immediately accessible through the shape field. You will need to access the polyline geometry object (Shape field) with SHAPE@ and drill down further to get to each point in the polyline geometry. Here is a python and arcpy code snippet for how to access the z-values of the vertices of a specific line in a polyline feature class.

id_field = 'TARGET_FID' #field identifies which features need to be shifted
id_value = 12 #value in id_field that identifies specific feature that needs to be shifted
shift_value = 2
with arcpy.da.UpdateCursor("Breaklines", ['SHAPE@', id_field]) as u_cur:
    for row in u_cur:
        if row[1] == id_value:
            geometry = row[0]
            pts = geom.getPart(0) #get polyline geometry
            pt_array = arcpy.Array() #create array to house new points
            for pt in pts:
                pnt.Z += shift_value #shift z value
                pt_array.add(pt) #add point to array
            new_polyline_geometry = arcpy.Polyline(pt_array, None, True) #important to enable z-value by having the third parameter set to True
            row[0] = new_polyline_geometry #set row[0] which is SHAPE@ (geometry object)
            u_cur.updateRow(row)

In a nut shell:

  • loop over the vertices of the polyline geometry
  • update each z value of the point geometry
  • add the updated point to an array
  • once all points in the polyline have been adjusted:
    • create a new polyline geometry with the point array, making sure to set it to z-enabled
  • then update the old polyline geometry with the newly created geometry

Currently this will only work on the first part of the geometry, see pts = geom.getPart(0), however it can be easily edited to work on the line if it has multiple parts. By updating the code and integrating another loop and using the .partCount of the Polyline object.

GeoSharp
  • 3.3k
  • 18
  • 28