I have a shapefile that has most of the lines spaced at regular intervals. However, there are some lines that are overlapped with each other or at very close distance to each other (figure for your illustration). I need to be able to find those lines and delete them automatically. For example, I need to delete either Line 1 or Line 2 (I am not focusing much on which to keep at the moment, but might need to think once I resolve this issue).

To address this issue, I used "Generate Near Table" with a same file as input and near feature file. I specified a search distance less than average distance between two lines (in my case, the lines were typically spaced at 0.7 meter, so I used half this distance (o.35) to search the lines that might be unnecessary). This gives me lines that have distance <0.35. That means it includes both Lines 1 and 2, and Lines 3 and 4. Although it addresses part of the problem, it does not solve the complete problem. I now need to figure out how to select either Line 1 or Line 2 (or Line 3 or Line 4), but not both.

When we create a near table, we get the IN_FID, NEAR_ID and NEAR_DIST attributes. I think I need to treat records that have same combinations of IN_FID and NEAR_ID (i.e., if Line 1 has IN_FID= 1 and NEAR_ID =2, and Line 2 has IN_FID=2 and NEAR_ID=1) as same. I don't know how to do this via program. Once we do, I think I can use Delete Identical function to get rid of those lines.

has someone been into the similar situation and can help me out here.enter image description here

  • 1
    Use Integrate to snap the Lines, then Dissolve to remove Stacked lines.
    – klewis
    Commented Sep 11, 2017 at 20:13
  • Klewis, dissolve did the magic in this case. Commented Sep 11, 2017 at 20:37
  • 1
    Just saw you solved it after I posted my answer - good work. Why not write up what you did as an answer, and then the question can be marked as closed.
    – RoperMaps
    Commented Sep 11, 2017 at 20:46

1 Answer 1


Here's a possible python solution. I don't have arc on my home computer so it's not tested - back up your data before trying...

It uses a update cursor and a list of tuples that have been deleted. If a feature has a near neighbour and the tuple (neigbour_id, feature_id) is not in the deleted list, then the tuple (feature_id, neighbour_id) is added to the deleted list and the feature is deleted.

What this assumes that the near relationship will always be mutual - i.e. there won't be one row with two nearest neighbours, and if A's nearest neighbour is B then B's nearest neighbour is A.

If that is not the case then you'll need to create a dictionary of neigbours to determine which ones to keep or throw away. How to create the dictionary is described here.


import arcpy
lines_fc = r"path/to/your/feature/class"
search_radius = 0.35
arcpy.Near_analysis(lines_fc, lines_fc, search_radius)
deleted = []

#NB "OID@" should select your object id field.
cursor = arcpy.UpdateCursor(lines_fc, ["OID@", "NEAR_FID"] as rows:
for row in cursor:
    if row[1] != -1 and (row[1], row[0]) not in deleted:

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.