I have a set of polygons with polylines running through them. I am trying to assign the polylines the polygon ID that they pass through the most. I have already split the polylines to the polygon boundaries, merged the individual shapefiles together keeping seperate features and joined them spatially to the polygons to give them the polygon IDs.

The issue I now face is to dissolve the features based on their polyline IDs while making the features keep the attributes of the section that is longest in a polygon. For example, if 60m of a polyline falls in polygon 1 and 40m of it falls in polygon 2, the rejoined line keeps the attributes of the section in polygon 1. There may be any number of features to merge.

Notable Condition: Some polylines may have more length outside of a polygon than inside. For those lines, I need the line to keep the attributes of the one that passes through a polygon. For example, if 5m of the line passes through polygon 1 and 95m of it pass through empty space, the merged attributes should reflect the line passing through the polygon

Here is the basic logic that I believe will work. I am just not sure how to code it into python or if there are tools that can accomplish what I am trying to do.

Select two line features. When one line has lineid = 1 and the second has lineid = 1, check for polygon ids in both, if only one has a polygon id, merge based on the one with an id, if they both have polygon ids, compare the lengths and merge based on the one that is longest. Move on to the next feature.

I am not sure if they need to be compared one at a time or if the dissolve tool or something else incorporates this kind of code. Thoughts?

I am using ArcGIS 10.0

  • What GIS software and version are using to try and do this?
    – PolyGeo
    Nov 23, 2013 at 2:19
  • I am using ArcGIS 10.0
    – user24275
    Nov 25, 2013 at 12:50
  • What about the scenario of 60m in polygon 1, 40m in polygon 2 and for example the middle part of the polyline and lets say its 100m, then you are dissolving 3 polylines and presumably attributing it with polygon 1?
    – Hornbydd
    Nov 25, 2013 at 21:59
  • Exactly. It retains the attributes of the polygon it is in the most.
    – user24275
    Nov 26, 2013 at 13:53

1 Answer 1


OK this is how I see your task:

Lets say the original polyline ID was 1 and after your intersection you now have a dataset with 5 polylines. The image below shows my working example. Purple numbers are the new polyline ID's and green is length of polyline.


So you will have a table as such:







X = Indicates the polyline lies outside of any polygon so is to be ignored.

You could run a simple summary statistics table on this grouping by OldID and Polygon summing length this would give you a table similar to this:




You could then delete all rows with polygon X as you are never interested in them, a model sorting the table and reading the first row would give you the polygon ID that the polyline most falls within and you assign that back to the original polyline dataset.

Of course you'll need to deal with the pathological cases such as a 50/50 split, entirely within a single polygon or not in any polygon.

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.