-
Notifications
You must be signed in to change notification settings - Fork 991
Refactor and extend properties of returned nearest point in @turf/nearest-point-on-line #2867
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
base: master
Are you sure you want to change the base?
Refactor and extend properties of returned nearest point in @turf/nearest-point-on-line #2867
Conversation
|
@smallsaucepan I just resolved a merge conflict so this PR can be cleanly merged again. I would appreciate if this was included in the next release. Please let me know if anything is missing from it or holding it back. |
fb75782 to
1f0c122
Compare
|
@smallsaucepan I have again resolved any merge conflicts of this PR. It would be great if this feature could be included in the upcoming 7.3.0 release. |
|
Oh @EmilJunker! Missed the release by just a few minutes. Will review and make sure we get into the next version 👍 |
|
Have been reviewing your PR (looks good!) and I think I gave you bad advice earlier. I'm not sure any more multiFeatureLOCATION is the best choice. Other functions use distance or a variation when describing how far along a line you've gone (see along). I started wondering if any other existing properties don't make sense ...
If we could start fresh, do you think the options below would be more clear or meaningful?
Trying to establish a plan before we go further, and would appreciate your thoughts on it. |
|
Thank you for the review. I agree with you that the current naming of the properties doesn't really make sense and that this would be a good opportunity to fix that. The fact that the location describes the distance along the line while dist is the distance to the closest point really confused me when I started using the nearestPointOnLine function. I also mostly agree with your suggested new names. I also agree with you that (going by my current implementation) multiFeatureLocation and location should basically switch roles since the former is probably more useful in practice than the latter. However, I think I would prefer "pointDistance" over "ptDistance" as a new name for "dist", because I'm generally not too fond of acronyms in source code. We aren't writing C++ here 😉 . Maybe the function parameter name could also be changed from "pt" to "point" while we are at it. But turf functions seem to be a bit inconsistent in that regard, e.g. pointToPolygonDistance has a "point" param while pointToLineDistance has a "pt" param. To make it even clearer that the distance is measured along the line, we could also call the other properties "lineDistance" and "multiFeatureLineDistance". In conclusion, I think the closest point should have the following properties:
I'd be happy to make the necessary naming changes as part of this pull request. My only concern is that this would be a breaking change, thus possibly deferring the release of this feature. Can you guarantee that it would still be included in the next turf release even with this breaking change? |
|
I see you've put a lot of thought into this. I like your idea to name the index after the type of item instead of the container. At the moment, the property names are a bit confusing because the function accepts both LineStrings and MultiLineStrings, so some of the properties are called multiXXX. But this is of course confusing for users who call the function with just a LineString and then still see multiXXX properties. Your suggestions for lineStringIndex and segmentIndex would definitely help to clear up that confusion because they make sense regardless of how many LineStrings there are (one or many). By the same logic, maybe the old location property could be renamed to totalLineStringDistance instead of multiLineStringDistance. Not sure, just an idea. Do you think that would be better? I'm not strongly advocating for the parameter to be called point instead of pt. My main point (no pun intended) was that I think pointDistance would be a better name than ptDistance for the old dist property. I would be happy to adapt this pull request in any way you see fit. Just tell me how to proceed and I'll do my best to get it done quickly. |
|
Thanks @EmilJunker. Proposing the mashup below. Might ask @JamesLMilner and @mfedderly to review as well. tl;dr feel we could do better naming the properties in the return object from nearestPointOnLine. Suggesting we take the opportunity with this PR to introduce new property names, and deprecate the old ones somewhere down the track. Existing properties would continue to work (be duplicated in the response) until at least the next major release.
There's no overlap so it wouldn't change the behaviour of existing code. Do these seem internally consistent, and also in line with terminology in other functions? |
|
Re Re return property names: I agree the existing ones are inconsistent, and I've found them confusing. The proposed names seem reasonable to me. If I can get greedy I'd love for the implementation to change to putting the proposed new properties into the object, and then a second block below that copying to the old names, with a comment above that block saying that it is deprecated. |
…f/nearest-point-on-line Fix unit tests
0bdf59a to
23a4ca8
Compare
23a4ca8 to
7f36fea
Compare
|
@smallsaucepan @mfedderly Thank you for your input. I have implemented and pushed the necessary changes. Everything looks good from my side. Please let me know if this is what you had in mind. I added the six new properties as discussed above, including segmentDistance. The old properties remain unchanged for now, but they can be easily removed later. I also renamed the |
|
This all lgtm, I'd be in favor of adding the |
|
Alright, I added the deprecation annotations and updated the README. Generating the README with Furthermore, it tried to add weird sections to the README based on the Anyway, it's all good to go now from my side. |



This adds amultiFeatureLocationproperty to the points returned by thenearestPointOnLinefunction. If there is just one LineString, then this will be the same as the existinglocationproperty. But if you pass a MultiLineString, this will tell you the distance along the line between the start of the MultiLineString where the closest point was found and the closest point itself. See #2753 for an example why this is useful.This PR adds the following new properties to the returned nearest point:
lineStringIndex: same as current multiFeatureIndex property
segmentIndex: same as current index property
totalDistance: same as current location property
lineDistance: new property I requested in #2753
segmentDistance: new property suggested in #2867 (comment)
pointDistance: same as current dist property
The original properties are kept for backwards compatibility, but they can be easily removed later.
Closes #2753.
Please provide the following when creating a PR: