I want to check if 2 linestrings intersects (or overlaps) or no.

I use turf.js overlap.

Here are the results I want to get:


1- If only first or last points of line 1 intersects with first or last points of line 2, intersection test should return false.

2- If a part of line 1 overlaps with a part of line 2, intersection test should return true

Problem is here:

// button click event

  // line-A end point coord and line-B start point coord equal
  // result must be true
  var overlapping = turf.lineOverlap(long, short);
  L.geoJSON(overlapping, {color: 'white',opacity:0.6,lineCap:'butt'}).addTo(map);

  // Part of line-C overlaps line-D 
  // result must be false
  var overlapping = turf.lineOverlap(long1, short1);
  L.geoJSON(overlapping, {color: 'white',opacity:0.6,lineCap:'butt'}).addTo(map);

  • 2
    Please include your code (JS part) in the body of the question. – TomazicM Oct 24 '19 at 15:27
  • Added js part include my question – vulkan Oct 25 '19 at 7:59

If you look at the description (and example) of turf.lineOverlap function (see http://turfjs.org/docs/#lineOverlap), you will see that it returns overlaping line only if any whole line in first geometry overlaps with any whole line in the second geomtry. Partial overlap does not count.

If you want just to check if there is overlap between two lines that results in line, you can use turf.booleanOverlap function (see http://turfjs.org/docs/#booleanOverlap). It return true if there is overlap.

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.