luukvdmeer / sfnetworks

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

Use edge lengths as default weights for shortest path calculation #106

Closed luukvdmeer closed 3 years ago

luukvdmeer commented 3 years ago

As discussed in https://github.com/luukvdmeer/sfnetworks/discussions/67: in st_network_paths it makes sense to change the default igraph behaviour regarding edge weight handling. When the edges don't have a weight column and the weights argument is set to NULL, igraph calculates shortest paths without edge weights. That is, the shortest path between the nodes is the path with the fewest number of edges.

For spatial shortest paths is rarely intended to calculate paths without edge weights. Therefore it makes more sense to always use the edge length as default in that case. Hence, when the edges don't have a weight column and the weights argument is set to NULL, sfnetworks will calculate shortest paths by using geographic edge length internally. You can still calculate paths without weights by setting the weights argument to NA, just as in igraph. But at least you have to explicitly set that option.

luukvdmeer commented 3 years ago

Pushed to master as part of a new minor version