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

Functions to snap points to nodes or edges #25

Closed
luukvdmeer opened this issue Apr 3, 2020 · 6 comments
Closed

Functions to snap points to nodes or edges #25

luukvdmeer opened this issue Apr 3, 2020 · 6 comments
Assignees
Labels
feature 🎁 Request a new feature
Milestone

Comments

@luukvdmeer
Copy link
Owner

luukvdmeer commented Apr 3, 2020

Is your feature request related to a problem? Please describe.
It would be nice to have a function that takes a (set of) spatial point(s), either as sf, sfc or sfg, and snaps them to the nearest node or nearest edge. In that way you can provide any spatial point to a shortest path query, no matter if it lies exactly on the network or not.

Describe the solution you'd like
A function st_snap_point_to_node that replaces the geometry of the given point by the geometry of the nearest node, and a function st_snap_point_to_edge that replaces the geometry of the given point by the nearest point on the nearest edge. The first can simply use sf's st_nearest_feature (or st_nearest_node if we implement that), the latter can use sf's st_nearest_points to find the nearest point on the nearest edge.

Probably these functions will need a tolerance argument, like st_snap in sf.

@luukvdmeer luukvdmeer added the feature 🎁 Request a new feature label Apr 3, 2020
@luukvdmeer luukvdmeer added this to the Milestone 2 milestone Apr 3, 2020
@luukvdmeer luukvdmeer self-assigned this Apr 3, 2020
@luukvdmeer
Copy link
Owner Author

See also how the shp2graph package handles this: https://www.mdpi.com/2220-9964/7/8/293/pdf

Screenshot from 2020-04-15 11-36-30

@Robinlovelace
Copy link
Collaborator

shp2graph is slow. The fastest approach I know of is with the nabor package, which I use in stplanr: https://github.com/ropensci/stplanr/blob/129b679c89a4ff9ba7f73dd5d59beb9bb734ace4/R/node-funs.R#L122

@luukvdmeer
Copy link
Owner Author

Ah, yes, I remember now we also used nabor in our blogpost. Regarding shp2graph I was mainly pointing to the figure with the explanation of the four strategies, which I like!

@Robinlovelace
Copy link
Collaborator

Yes it's a great figure, we need more good visuals like that. Good point.

@rafapereirabr
Copy link

Hi all. In the gtfs2gps package we use a quite fast function based on C++ to snap points to the closest points of another set using. Perhaps it might be useful here.

@luukvdmeer
Copy link
Owner Author

This topic was getting a little bit scattered.

There are now separate issues:

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

No branches or pull requests

3 participants