HOW TO
In ArcGIS Pro, adding line vertices at fixed intervals using ArcPy significantly improves spatial data precision and time management. This method automates the process of creating line vertices at the intersection of point features, which are generated using the Generate Points Along Line tool. The automation produces more detailed line geometry while maintaining consistent vertex distances, which are useful for spatial queries and analysis.
Browse this article for the workflow to add line vertices at fixed intervals using ArcPy in ArcGIS Pro.
Note: The indentations must be maintained in the script. They specify which code block the script resides in.
import arcpy
line_layer = r"<location_path>\<name>.gdb" point_layer = r"<location_path>\<name>.gdb"
with arcpy.da.UpdateCursor(line_layer, ['SHAPE@']) as lineCursor: for row in lineCursor: geo = row[0]
arcpy.management.SelectLayerByLocation(point_layer, "INTERSECT", geo, None, "NEW_SELECTION") res = arcpy.management.GetCount(point_layer) n = int(res.getOutput(0))
if n > 0: point_List = [] with arcpy.da.SearchCursor(point_layer, ['SHAPE@']) as pointCursor: for pointRow in pointCursor: point_List.append(pointRow[0])
lineArr = geo.getPart(0) for p in lineArr: point_List.append(arcpy.PointGeometry(p))
pointDict = {} for p in point_List: poin = geo.measureOnLine(p, True) pointDict[poin] = p
centroid_points = [pointDict[key].centroid for key in sorted(pointDict.keys())] newLine = arcpy.Polyline(arcpy.Array(centroid_points))
row[0] = newLine lineCursor.updateRow(row)
The code below demonstrates the full working script.
import arcpy line_layer = r"C:\User\Desktop\Testfolder\test.gdb\testline" point_layer = r"C:\User\Desktop\Testfolder\test.gdb\testpoint" with arcpy.da.UpdateCursor(line_layer, ['SHAPE@']) as lineCursor: for row in lineCursor: geo = row[0] arcpy.management.SelectLayerByLocation(point_layer, "INTERSECT", geo, None, "NEW_SELECTION") res = arcpy.management.GetCount(point_layer) n = int(res.getOutput(0)) if n > 0: point_List = [] with arcpy.da.SearchCursor(point_layer, ['SHAPE@']) as pointCursor: for pointRow in pointCursor: point_List.append(pointRow[0]) lineArr = geo.getPart(0) for p in lineArr: point_List.append(arcpy.PointGeometry(p)) pointDict = {} for p in point_List: poin = geo.measureOnLine(p, True) pointDict[poin] = p centroid_points = [pointDict[key].centroid for key in sorted(pointDict.keys())] newLine = arcpy.Polyline(arcpy.Array(centroid_points)) row[0] = newLine lineCursor.updateRow(row)
The map shows the line feature with vertices added at fixed intervals.
Get help from ArcGIS experts
Download the Esri Support App