Skip to main content
Solved

Joining of two lines where more than two intersect


fbinneman
Contributor

Hi All

I am working on an electric network as input where line segments sometimes join. The end vertices lie on top of each other. I have used the Snapper and LineCombiner to combine lines where only two lines meet. The LineCombiner transformer can however not combine lines where more than two lines meet.

It does not really matter what two lines are combined, although it would make sense to join the longest segments. The line segments all have the same attribute values (ie the same voltage and reticulation name). The reason for wanting this is to make the output dataset as small as possible, as there is so much unnecessary duplication with the attributes for small pieces of line being exactly the same.

Is there a way to combine two lines where more than two meets?

Hope someone can help.

Best answer by mark2atsafe

Haven't tried it, but am thinking:

  • Create points at the intersection (TopologyBuilder)
  • Give those points an ID (counter)
  • Get the ID onto the lines (pointOnLineOverlayer)
  • Use a ModuloCounter, counter name = ID attr, max=1
  • Connect lines with group by _modulo

Thinking it will alternatively number connections 0,1,0,1 - so you could connect them with a group where only two items exist in the group. That's the aim anyway.

Or similar to @cartoscro, you could use a RandomNumberGenerator to generate a number 0 or 1 for each line, then do a line joining with that as a group-by. It probably won't join everything, but it would have a 2/3 chance (maybe 75% now I think of it) of cleaning up each 3-line junction.

View original
Did this help you find an answer to your question?

10 replies

dustin
Influencer
Forum|alt.badge.img+30
  • Influencer
  • November 8, 2017

Just a thought - You could do a LengthCalculator on all lines, then feed into a StatisticsCalculator to get the mean or median of the data set. Then using a Tester, separate those lines whose length is longer than the average, and those that are shorter than the average. Then use the 2 LineCombiners on the two subsets.

This will not resolve all situations where three lines meet, but it may help to work toward your goal of reducing the number of lines.


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • Best Answer
  • November 8, 2017

Haven't tried it, but am thinking:

  • Create points at the intersection (TopologyBuilder)
  • Give those points an ID (counter)
  • Get the ID onto the lines (pointOnLineOverlayer)
  • Use a ModuloCounter, counter name = ID attr, max=1
  • Connect lines with group by _modulo

Thinking it will alternatively number connections 0,1,0,1 - so you could connect them with a group where only two items exist in the group. That's the aim anyway.

Or similar to @cartoscro, you could use a RandomNumberGenerator to generate a number 0 or 1 for each line, then do a line joining with that as a group-by. It probably won't join everything, but it would have a 2/3 chance (maybe 75% now I think of it) of cleaning up each 3-line junction.


dustin
Influencer
Forum|alt.badge.img+30
  • Influencer
  • November 8, 2017
mark2atsafe wrote:

Haven't tried it, but am thinking:

  • Create points at the intersection (TopologyBuilder)
  • Give those points an ID (counter)
  • Get the ID onto the lines (pointOnLineOverlayer)
  • Use a ModuloCounter, counter name = ID attr, max=1
  • Connect lines with group by _modulo

Thinking it will alternatively number connections 0,1,0,1 - so you could connect them with a group where only two items exist in the group. That's the aim anyway.

Or similar to @cartoscro, you could use a RandomNumberGenerator to generate a number 0 or 1 for each line, then do a line joining with that as a group-by. It probably won't join everything, but it would have a 2/3 chance (maybe 75% now I think of it) of cleaning up each 3-line junction.

I guess you could repeat the RandomNumberGenerator/LineCombiner as many times as you wanted, increasing the resolution chances with each.

 

 


Forum|alt.badge.img
  • November 8, 2017

Hi @francois_binnem

 

you could try using LineOnLineOverlayer to find lines that have matching end points. Then, for every group of lines with matching end points, you would need to separate two longest lines and join them. You might need to do this more than once if you have a complex network.

 


fbinneman
Contributor
  • Author
  • Contributor
  • November 9, 2017
mark2atsafe wrote:

Haven't tried it, but am thinking:

  • Create points at the intersection (TopologyBuilder)
  • Give those points an ID (counter)
  • Get the ID onto the lines (pointOnLineOverlayer)
  • Use a ModuloCounter, counter name = ID attr, max=1
  • Connect lines with group by _modulo

Thinking it will alternatively number connections 0,1,0,1 - so you could connect them with a group where only two items exist in the group. That's the aim anyway.

Or similar to @cartoscro, you could use a RandomNumberGenerator to generate a number 0 or 1 for each line, then do a line joining with that as a group-by. It probably won't join everything, but it would have a 2/3 chance (maybe 75% now I think of it) of cleaning up each 3-line junction.

Thank you very much for everyone's suggestions! Mark, I basically used your idea, with the following difference:

 

Since I have already done a LineCombiner on the data, I only needed to follow your steps from point 4 ("Use a ModuloCounter") onwards. Just a small correction there: Count Maximum needed to be set to 2 so that the counter could iterate between 0 and 1. I then did a LineCombiner using the ModuloCounter (your step 5).

 

The results? A network with 520,000 segments (each segment consisting of two or more coordinates) of which all segments are not connected reduced to about 380,000 segments after the first LineCombiner that connected all lines where only two lines met. Then, after Mark's suggestion (incorporating his step 4 and 5) further reduced the number of line segments to about 260,000, resulting in a saving of about 50% in number of segments. I could also have tried to connect the longest segments as Lena suggested, but I could not get her workbench to run without errors on my side (probably due to a lack of knowledge on some of the transformers). I am quite happy with the results I obtained from Mark's solution though.

 

 

Thanks again everyone!

 

 


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • November 13, 2017
fbinneman wrote:
Thank you very much for everyone's suggestions! Mark, I basically used your idea, with the following difference:

 

Since I have already done a LineCombiner on the data, I only needed to follow your steps from point 4 ("Use a ModuloCounter") onwards. Just a small correction there: Count Maximum needed to be set to 2 so that the counter could iterate between 0 and 1. I then did a LineCombiner using the ModuloCounter (your step 5).

 

The results? A network with 520,000 segments (each segment consisting of two or more coordinates) of which all segments are not connected reduced to about 380,000 segments after the first LineCombiner that connected all lines where only two lines met. Then, after Mark's suggestion (incorporating his step 4 and 5) further reduced the number of line segments to about 260,000, resulting in a saving of about 50% in number of segments. I could also have tried to connect the longest segments as Lena suggested, but I could not get her workbench to run without errors on my side (probably due to a lack of knowledge on some of the transformers). I am quite happy with the results I obtained from Mark's solution though.

 

 

Thanks again everyone!

 

 

Excellent. Glad I was able to help.

 

 


fmenco
Contributor
Forum|alt.badge.img+5
  • Contributor
  • August 7, 2019
mark2atsafe wrote:

Haven't tried it, but am thinking:

  • Create points at the intersection (TopologyBuilder)
  • Give those points an ID (counter)
  • Get the ID onto the lines (pointOnLineOverlayer)
  • Use a ModuloCounter, counter name = ID attr, max=1
  • Connect lines with group by _modulo

Thinking it will alternatively number connections 0,1,0,1 - so you could connect them with a group where only two items exist in the group. That's the aim anyway.

Or similar to @cartoscro, you could use a RandomNumberGenerator to generate a number 0 or 1 for each line, then do a line joining with that as a group-by. It probably won't join everything, but it would have a 2/3 chance (maybe 75% now I think of it) of cleaning up each 3-line junction.

@mark2atsafe Hi, I'm trying to implement the same thing. I want to combine different line segments, but have noticed that the linesegments where more than two linesegments intersect,don't get combined.

I've tried implementing your suggestion, but that doesn't neccesarily solve the problem totally. I still have some uncombined linesegments left, but maybe I'm doing tosmthing wrong.

Just to make sure I understand it correctly, in the 1st step with the topologybuilder, you put nodes on every vertex right? Not just the ones where more than three lines connect?


fbinneman
Contributor
  • Author
  • Contributor
  • August 7, 2019
fmenco wrote:

@mark2atsafe Hi, I'm trying to implement the same thing. I want to combine different line segments, but have noticed that the linesegments where more than two linesegments intersect,don't get combined.

I've tried implementing your suggestion, but that doesn't neccesarily solve the problem totally. I still have some uncombined linesegments left, but maybe I'm doing tosmthing wrong.

Just to make sure I understand it correctly, in the 1st step with the topologybuilder, you put nodes on every vertex right? Not just the ones where more than three lines connect?

Hi fmenco

Just a guess, but I will try to assist. :) My guess is that you need to have more passes of using a ModuloCounter transformer to assign the same value to various (perhaps random) line segments and then use the LineCombiner again and again. The more passes, the more connected your output should become. Perhaps you can feed the output of your workbench into a similar workbench a couple of times to do this connecting for you using the ModuloCounter transformer?

The other issue may be that your vertices do not quite appear on exactly the same positions, causing them not to connect, but from what you have written, this does not seem to be the issue.

Hope this helps.

 


fmenco
Contributor
Forum|alt.badge.img+5
  • Contributor
  • August 7, 2019
fbinneman wrote:

Hi fmenco

Just a guess, but I will try to assist. :) My guess is that you need to have more passes of using a ModuloCounter transformer to assign the same value to various (perhaps random) line segments and then use the LineCombiner again and again. The more passes, the more connected your output should become. Perhaps you can feed the output of your workbench into a similar workbench a couple of times to do this connecting for you using the ModuloCounter transformer?

The other issue may be that your vertices do not quite appear on exactly the same positions, causing them not to connect, but from what you have written, this does not seem to be the issue.

Hope this helps.

 

Hi,

Thank you for your response. I've implemented the multiple passes as well. However, I basically want to have one long line for every network of lines (and with network I mean here, just a group of connected lines). This would mean a great deal of passes. There has to be some sort of other way.... Maybe I'll ask a new question, and link to this post, since the question is similar but also slightly different.


soly
Contributor
Forum|alt.badge.img+3
  • Contributor
  • January 29, 2020
lenaatsafe wrote:

Hi @francois_binnem

 

you could try using LineOnLineOverlayer to find lines that have matching end points. Then, for every group of lines with matching end points, you would need to separate two longest lines and join them. You might need to do this more than once if you have a complex network.

 

Thanks really for ur method,it s so helpful for me but i am not sure ,how can i apply it again.

bcs it succeded to combine each two lines but when i have 3 lines get out of same point ,it gives me no combined even i tried to take the output and feed it again ,it is still the same result .

could u suggest me what should i do and thanks again for ur method


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings