luukvdmeer / sfnetworks

Tidy Geospatial Networks in R
https://luukvdmeer.github.io/sfnetworks/
Other
347 stars 20 forks source link

Preserve certain nodes during smoothing even if they are pseudo nodes #177

Closed luukvdmeer closed 2 years ago

luukvdmeer commented 3 years ago

Is your feature request related to a problem? Please describe. The to_spatial_smooth() morpher now removes all pseudo nodes from the network. The goal of removing pseudo nodes is mainly to speed-up routing tasks. When routing, st_network_paths() finds the nearest nodes to origin and destination points. In the original network, such a nearest node might have been a pseudo node. Since you smoothed your network before routing, however, all these pseudo nodes are gone and the nearest node to a point is now basically the nearest junction node. This will give less accurate shortest paths.

Describe the solution you'd like It would be nice if you can "protect" some nodes from being smoothed out. E.g. a vector of booleans defining for every node if this node should be protected or not. If TRUE, such a node will not be smoothed out, even if it is a pseudo node. By default we can set this boolean vector to contain only FALSE values, i.e. all nodes that are pseudo nodes will be smoothed out.

In this way, you can first find the nearest nodes to your origin and destination points (or blend these points into the network with st_network_blend()), then smooth the network but protecting these nearest/blended nodes, and then route.

This is similar to the verts argument in dodgr::dodgr_contract_graph(), see here.

luukvdmeer commented 2 years ago

Implemented in v0.6.0 through arugment protect, see https://luukvdmeer.github.io/sfnetworks/articles/sfn02_preprocess_clean.html#smooth-pseudo-nodes