I am trying to modify some lines in ArcGIS Pro, shifting the Start vertex to coordinates in a pair of fields in the layer attributes. My arcpy script works... almost.
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
mapx = aprx.activeMap
layer_name = "tempfc"
layer = mapx.listLayers(layer_name)[0]
# Create an update cursor to modify feature geometry
with arcpy.da.UpdateCursor(layer, ["SHAPE@", "xcoord", "ycoord"]) as cursor:
for row in cursor:
# Unpack the current feature's geometry and the target x, y coordinates
geom, x_coord, y_coord = row
# Create a new point geometry for the start point
new_start_point = arcpy.Point(x_coord, y_coord)
# Get the array of points from the current geometry (line)
# We need to ensure we use an arcpy Array to handle points
old_points = geom.getPart(0)
new_points = arcpy.Array([new_start_point] + [old_points.getObject(i) for i in range(1, old_points.count)])
# Create a new polyline using the updated array of points
new_line = arcpy.Polyline(new_points, geom.spatialReference)
# Update the row with the new geometry
cursor.updateRow([new_line, x_coord, y_coord])
print("Start points of lines have been updated.")
The problem is, some of my lines contain curves (or curve segments), and in my Update Cursor when I rebuild the shape it simply draws straight lines between each of the existing vertices
And after running my script, this is what the line looks like (with the original shown in blue for reference). The shift of the first vertex to the new start point is good, exactly what I want, and the last segment is fine too. But the curve has gone and become a straight line.
How can I modify my line shape but keep existing curve segments in place? If the first segment is a curve, I still want it to become a straight segment (this is to avoid nasty curves appearing because I shifted it), but the rest I would like to remain as-is.