luukvdmeer / sfnetworks

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

Allow duplicated "to" nodes in cost matrix calculation #183

Closed luukvdmeer closed 2 years ago

luukvdmeer commented 2 years ago

Is your feature request related to a problem? Please describe. In igraph::distances() it is not allowed to have duplicated node indices in the to argument. See here.

to: Numeric vector, the vertices to which the shortest paths will be calculated. By default it includes all vertices. Note that for distances every vertex must be included here at most once

For our wrapper st_network_cost() we have the same requirement, because we simply call the igraph function. However, st_network_cost() allows to provide spatial points as to argument, which will then internally be "represented" by their nearest node. Two different points may have the same nearest node, however. In that case one of the points will be ignored by st_network_cost() and the warning Duplicated values in argument 'to' were removed is given. The returned matrix will not have the same amount of columns as the number of points you forwarded. That can be super annoying.

Describe the solution you'd like Because igraph does not support duplicated to indices, we must remove them, as we already do. However, afterwards we could just insert the missing column again in the matrix, such that the user does not even notice it.

luukvdmeer commented 2 years ago

Implemented in v0.6.0