[GIS] How to identify gaps in polylines and polylines with more than one end point using ArcGIS 10

arcgis-10.0arcgis-desktoptopology

I have a multipart polyline shapefile containing a large number of lines, some of which are broken by gaps and some of which have more than one start and end (by mistake – see attached). I need to have a multipart shapefile output, which contains only unbroken lines with one start and one end. Is there a way to identify these errors (can't seem to do it with the the topology rules in Arc)?

Once identified they are easy to fix manually.

Best Answer

If the polylines are unbroken then they should only be a single part. You could use Python to create a to loop through each record in the shapefile and get the part count of each feature. If the part count is greater than 1 then the feature should have multiple start and end points or be disconnected.

UPDATE:

import arcpy

inputSHP = r"path/to/input/shapefile"
outputSHP = r"path/to/output/shapefile" # This shapefile should already be created with all the properties of the input shapefile (use input shapefile as a template)

fields = arcpy.ListFields(inputSHP) # This gets all the fields in the input shapefile into a python list

outrows = arcpy.InsertCursor(outputSHP) # This allows you to insert features into the output shapefile

rows = arcpy.SearchCursor(inputSHP) # This reads each feature in the input shapefile one at a time

for row in rows: # Loop through each feature in the input shapefile

    if row.SHAPE.partCount == 1: # Determine if geometry has more than one part

        newrow = outrows.newRow() # Create new feature in output shapefile

        for field in fields: # Loop through fields in input shapefile (these should be exactly the same as in the output shapefile)

            newrow.setValue(field.name, row.getValue(field.name) # Set the value of each field in the output shapefile feature to that field in the of the input shapefile feature

        outrows.insertRow(newrow) # Save the new feature into the output shapefile

        del newrow # Memory management (delete the new row object)

    del row # Memory management (delete the input row object)
del rows, outrows # Memory management (delete the cursor objects)
Related Question