HOW TO
Line feature misalignments can be detected programmatically to ensure features such as roads, pipelines, or power lines follow intended paths or reference alignments. This article describes the workflow to detect line feature misalignments using ArcPy in ArcGIS Pro.
Note: This workflow requires a full script to run in the ArcGIS Pro Python window. The indents must be retained as portrayed in the code block.
line_feature_class = r"<pathToFeatureClass>"
alignment_feature_class = r"<pathToFeatureClass>"
misalignment_threshold = <bufferDistance>
sr = arcpy.Describe(line_feature_class).spatialReference
arcpy.analysis.Near(line_feature_class, alignment_feature_class)
join_result = arcpy.analysis.SpatialJoin(line_feature_class, alignment_feature_class, r"C:<outputShapeFile>", join_type="KEEP_COMMON")
with arcpy.da.UpdateCursor(line_feature_class, ["SHAPE@", "NEAR_DIST", "OBJECTID"]) as cursor:
for row in cursor:
# NEAR_DIST field contains the distance to the alignment
if row[1] > misalignment_threshold:
print(f"Line {row[2]} is misaligned by {row[1]} meters.")
The code below demonstrates the full working script.
line_feature_class = r"C:\Users\Documents\ArcGIS\Projects\MyProject44\MyProject44.gdb\Linefeatureclass"
alignment_feature_class = r"C:\Users\Documents\ArcGIS\Projects\MyProject44\MyProject44.gdb\Line1"
misalignment_threshold = 5
sr = arcpy.Describe(line_feature_class).spatialReference
arcpy.analysis.Near(line_feature_class, alignment_feature_class)
join_result = arcpy.analysis.SpatialJoin(line_feature_class, alignment_feature_class, r"C:\Users\Documents\ArcGIS\Projects\MyProject44\Output\reference_line.shp", join_type="KEEP_COMMON")
with arcpy.da.UpdateCursor(line_feature_class, ["SHAPE@", "NEAR_DIST", "OBJECTID"]) as cursor:
for row in cursor:
if row[1] > misalignment_threshold:
print(f"Line {row[2]} is misaligned by {row[1]} meters.")
The image below shows the list of the misaligned lines printed in the Python window.
Article ID: 000035974
Get help from ArcGIS experts
Download the Esri Support App