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

lineSplit seems unable to handle splitter points with nearly the same longitude #1075

Closed
haoliangyu opened this issue Nov 4, 2017 · 4 comments
Labels

Comments

@haoliangyu
Copy link

haoliangyu commented Nov 4, 2017

I run into an edge case where two points with nearly the same longitude breaks lineSplit() (in turf v4.7.3). The coordinates are collected via GPS and the longitude difference is only 0.000001. You can see the geometry in this Gist.

When I try to split a line with these two points,

var turf = require('@turf/turf');

var line = turf.lineString([[-87.168433, 37.946093], [-87.168510, 37.960085]]);
var splitter = turf.multiPoint([[-87.168446, 37.947929], [-87.168445, 37.948301]]);
var split = turf.lineSplit(line, splitter);

they break lineSplit() and throw an error.

/home/turf_test/node_modules/@turf/line-split/index.js:92
            results = results.filter(function (feature) { return feature.id !== closestLine.id; });
                                                                                           ^

TypeError: Cannot read property 'id' of undefined
    at /home/turf_test/node_modules/@turf/line-split/index.js:92:92
    at Array.filter (<anonymous>)
    at /home/turf_test/node_modules/@turf/line-split/index.js:92:31
    at featureEach (/home/turf_test/node_modules/@turf/meta/index.es5.js:358:13)
    at splitLineWithPoints (/home/turf_test/node_modules/@turf/line-split/index.js:73:5)
    at Object.module.exports [as lineSplit] (/home/turf_test/node_modules/@turf/line-split/index.js:52:16)
    at Object.<anonymous> (/home/turf_test/index.js:5:18)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)

The problem is likely caused by the difference in the last decimal. It will work if I drop the 6th decimal or change the number to enlarge the difference. But I am not sure whether that is the correct way to avoid or fix the problem.

DenisCarriere added a commit that referenced this issue Nov 5, 2017
@DenisCarriere
Copy link
Member

@haoliangyu See PR #1078

@DenisCarriere
Copy link
Member

This definitely caused some issue 👍 thanks for reporting this.

@haoliangyu
Copy link
Author

@DenisCarriere Thanks for the quick fix!

In your PR, moving the point on the line is mentioned as a fixture. Can I consider it as a reliable way to avoid this issue for now and use turf.pointOnLine() to process the splitter beforehand?

DenisCarriere added a commit that referenced this issue Nov 6, 2017
@DenisCarriere
Copy link
Member

use turf.pointOnLine() to process the splitter beforehand?

👍 Yep that might be a good idea to use as the splitter since the lineSplit is fairly strict for position. Most of the applications do "snapping" which causes the point or cursor to snap on the line which then makes the splitter point exactly on the line.

Going to close this issue, however feel free to re-open or submit more fixtures that are failing.

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

2 participants