4

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.

1
  • 1
    attachment is not visible..can you post it to dropbox or somewhere else if you can't add image here?
    – vinayan
    Commented Jan 17, 2013 at 12:43

2 Answers 2

4

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)
2
  • Thank you - it sounds as though that would do it. Unfortunately I have almost no experience with Python. Do you know of anywhere I could find a similar example script?
    – Rob
    Commented Jan 18, 2013 at 12:57
  • I added a code example to get you started. Check out the ArcPy Site Package and the ArcGIS Python help to get some more background. resources.arcgis.com/en/help/main/10.1/#/What_is_Python/…
    – Brian
    Commented Jan 18, 2013 at 15:32
1

These are the steps I would use:

add field TmpID as long
calculate tmpID = Objectid (to preserve the ObjectID)
run tool MultipartToSinglepart
run tool UnsplitLine
run tool Frequency on tmpID (this produces a feature count for each tmpID)
join the frequency table to your polylines (join on polyline.objectid = frequency.tmpid)
select "Frequency" > 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.