4

I have lots of lines that I need to merge IF and only if they share the same polygon(s). All lines are made from the polygons (copy-paste into line) so they all snap.

enter image description here

In this little example line 499, 451, 447, 452 and 448 could be merged since they all share polygon 136 and none polygon on the outer side of the line.
Similarly line 442, 443 and 427 could be merged since they all share polygon 133 on the inner side and polygon 136 on the outer side.

My guess so far is to make points on the middle of each line (Features->Feature Vertices to Point and point type [MID]). And then do a Spatial Join where I use this new point layer as Target and my polygonlayer as Join [Join-One-To-Many]. Then I get a new feature that tells me the line-to-polygon relation; line = ORIG_FID and polygon JOIN_FID.

enter image description here

Line 427 is adjacent to polygon 133 and 136.
Line 443 is adjacent to polygon 133 and 136.
Line 447 is adjacent only to polygon 136.

And this is where I stop.
I now need a script that checks which polygon(s) each line is adjacent to and if two or more lines share exactly the same polygon or polygons then merge.

UPDATE:
I figured out that if I could make an unique ID on each link based on adjacent polygon(s) [Pol_ID], I could use this new link-ID to merge links with the same new_ID value. Here I made it simple and added the Pol_ID value(s) from adjacent polygon(s); see black values in figure.

New_ID 136 = Pol_ID value 136.
New_ID 269 = Pol_ID values 136+133.

So far so well, and I easily could merge all links with the same new_ID.

But then a new problem arose: the lines also have to be connected. Therefore the two lines with value 133 (blue arrows) shall not be merged since they are not connected to each other.

The missing part is now to: check if links with same new_ID value is connected, then merge the connected ones.

The red values represent the unique value [X-coordinate + Y-coordinate] to the start-/endpoint of the line. Thought I could use this value to check if lines were connected (share start/endpoint), but haven't figured it out yet..

enter image description here

  • Have you experimented with the Select Layer By Location options? I think you'll find one there that let's you use a polygon to select the lines that lay along its border. – PolyGeo Oct 23 '15 at 8:59
  • Hi. Can't really figure out how to use the Select Layer By Location on this problem... As far as I now that option is more on a layer level; select line-layer intersecting polygon-layer. – gobrandal Oct 23 '15 at 9:07
  • That's right, but if you can get it to make the selection then you can calculate a field value to dissolve the lines on. Once you can do that for one polygon and its surrounding/bordering lines then you can use an ArcPy cursor to go through a polygon feature class one polygon at a time to automate the whole process. – PolyGeo Oct 23 '15 at 9:17
  • 1
    If you made the lines from the polygons perhaps you could instead use the Polygon to Line tool, keeping the attributes, and then dissolve the lines based on the polygon attributes they have. – johns Oct 23 '15 at 12:52
1

Solution:
When the new_ID has been saved as attribute to each line then use the Dissolve tool. Check the new_ID as "Dissolve_Fields(s)", and uncheck "Create multipart feature (optional)" and check "Unsplit lines (optional)". That will merge all connected lines with the same new_ID.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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