-
Notifications
You must be signed in to change notification settings - Fork 944
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
turf.nearest for linestrings #198
Comments
The challenge with nearest for linestrings is that a linestring could have only 2 points, making it difficult to run nearest through each sets of coordinates in that point. I solved this problem by taking linestring and 'complexifying' it by adding points on the linestring within a certain distance of each other. Then I can search for nearest in that list of coordinates on the linestring. I did this in rwt-to/GeoJSON-Tools (MovingGauteng/GeoJSON-Tools@35abcf0), but I'm not promoting that you use the tool. I just saw Turfjs today, and if someone would like to port the 'complexify' method from GeoJSON-Tools, you're welcome to. |
Gday @peterqliu I've had a shot at creating this module, basically you input a collection of points and a linestring, and it returns the nearest point as well as the distance that point is from the line, this is included as a property on the feature. The user can also specify the distance units as a parameter (as per the existing turf distance module) which defaults to kilometers. It was actually quite simple to do as it builds on a number of existing turf modules, namely point-on-line and distance. cc @tcql & @morganherlocker . I still need to write some tests but if you're interested in transferring ownership at some stage let me know. Cheers |
@rowanwins thank you so much for jumping in here. hoping to see this in the not-too-distance turf future. |
@rowanwins @DenisCarriere it seems to me that Thoughts? |
Mmm not quite @stebogit . It would be neat to bulk out nearest to support other scenarios, even if we did this |
@rowanwins 👍 of course! Now I got the difference 😄 |
How would the case of a parallel line be handled? There is no single closest point. |
If in doubt @morganherlocker the answer is c - we'll just place something artibitralily 😜! |
Implemented with #939 |
For example, when I want to find the closest gas station to the stretch of freeway where I'll likely be low on gas.
This is better than doing turf.nearest on a single point, for two reasons:
The text was updated successfully, but these errors were encountered: