Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lineIntersect returns the same point several times #688

Closed
grundid opened this issue Apr 25, 2017 · 7 comments
Closed

lineIntersect returns the same point several times #688

grundid opened this issue Apr 25, 2017 · 7 comments
Assignees
Labels
Milestone

Comments

@grundid
Copy link
Contributor

grundid commented Apr 25, 2017

I'm trying to find out the point at which two lines intersect. The two lines have the intersecting point in common like:

  const line1 = turf.lineString([[7, 50], [8, 50], [9, 50]]);
  const line2 = turf.lineString([[8, 49], [8, 50], [8, 51]]);

  var features = turf.lineIntersect(line1, line2);

In this case lineIntersect returns the point [8, 50] 4 times. By looking at the implementation the problem is obvious since the given lines are split into 2-vertex lines and then the intersections are calculated.

I'm not sure if you want to fix this, but it would be nice if the documentation would explain this scenario.

@rowanwins rowanwins added the bug label Apr 25, 2017
@rowanwins
Copy link
Member

Gday @grundid

Thanks for the report, that does seem to be an unexpected output! I think we can mark this as a bug, it should be fairly easy to remove duplicate pairs of output coordinates.

@DenisCarriere
Copy link
Member

Agreed, this is a bug, I can definitely have a look at this.

@DenisCarriere DenisCarriere self-assigned this Apr 25, 2017
@DenisCarriere DenisCarriere added this to the 4.2.0 milestone Apr 25, 2017
@grundid
Copy link
Contributor Author

grundid commented Apr 25, 2017

Thanks for looking into it. Unfortunately the problem is also visible in other functions like lineSplit.

When I split a line like this:

  const point = turf.point([8, 50]);
  const line1 = turf.lineString([[7, 50], [8, 50], [9, 50]]);
  const splitLines = turf.lineSplit(line1, point);

I receive two lines, which is correct, but the second line contains the splitter point twice.

line[0]: { type: 'LineString', coordinates: [ [ 7, 50 ], [ 8, 50 ] ] }
line[1]: { type: 'LineString', coordinates: [ [ 8, 50 ], [ 8, 50 ], [ 9, 50 ] ] }

Wherever listSegment is used to split the line into 2-vertex lines one would have to rethink the algorithm, I guess.

@DenisCarriere
Copy link
Member

Once @turf/line-intersect is fixed this shouldn't happen on @turf/line-split.

@grundid
Copy link
Contributor Author

grundid commented Apr 25, 2017

I'm sorry, but the splitLineWithPoint function in the line-split module doesn't use lineIntersect.

I guess, a simple fix for the splitLineWithPoint function might be to check if the initialValue (or getCoords(segments.features[0])[0]) in line 143 equals to the coords in line 148 and then don't add it to the returning array in line 151. I haven't tested it though ;)

@DenisCarriere
Copy link
Member

👍 Oh that's true, I assumed it was since the require('@turf/line-intersect) (I should know, I built the module 🤦‍♂️ ).

Feel free to send a PR with a fix, we can hash out any details in the PR.

@DenisCarriere
Copy link
Member

Fixed in next minor release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants