[GIS] Merging polylines together keeping the attributes of the largest one

arcgis-10.0arcgis-desktopdissolvemerge

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

Best Answer

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.

Example

So you will have a table as such:

NewID,OldID,Length,Polygon

1,1,20,A

2,1,10,X

3,1,10,A

4,1,40,X

5,1,1,B

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:

1,A,30

1,B,1

1,X,40

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.

Related Question