1

In my data I have many occurrences of 2 lines that follow the same path, but in opposing directions. Applying LineMerger to this data results in the lines being joined together, but not merged into each other.

e.g. Given two lines with the same nodes

--->--->--->---

---<---<---<---

I want either:

--->--->--->---

or

---<---<---<---

But instead I get

--->--->--->--+
              |
---<---<---<--+

or

+-->--->--->---
|
+--<---<---<---

Is there a way to obtain my desired result in JTS?

3

1 Answer 1

1

Can you union the lines using Geometry.union ?

3
  • It's been a while, but I think I recall that union was a no-op, as the lines are not equivalent when reversed.
    – Synesso
    Commented Apr 30, 2019 at 21:15
  • As long as the lines do have identical vertices (in opposite order) then Geometry.union will work. It will return a MultiLineString, which can then be merged to provide a single line.
    – dr_jts
    Commented Apr 30, 2019 at 23:57
  • I see. I probably stopped exploring this option when I got the multilinestring.
    – Synesso
    Commented May 1, 2019 at 12:57

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.