Expected behavior for polygon supplied in "from" or "to" argument of st_network_cost? #151
-
Hello, Thanks for the awesome package! I was wondering what the expected behavior is when a polygon/multipolygon sf object is supplied to the "to" or "from" argument in the st_network_cost function. In my particular case I have been putting polygon sites in the from argument with point locations in the "to" argument and for my particular purpose I would like the function to find the closest point in the "to" to the closest node of the polygon (from). However, I believe this is not what is happening so I am wondering a.) what is happening/should there be a warning?, and b.) is it best practice to just take the centroid of a polygon first? Thanks again |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Internally, sfnetworks calls |
Beta Was this translation helpful? Give feedback.
Internally, sfnetworks calls
sf::st_nearest_feature()
(in the form st_nearest_feature(input_geoms, network_nodes) to find the nearest network node to each input geometry, see https://r-spatial.github.io/sf/reference/st_nearest_feature.html. As far as I am aware (but not 100% sure!), that should do exactly what you are asking for. Hence, when your input geometries are polygons, it should use the nearest network nodes to the boundaries of these polygons (and not to their centroids) for shortest path calculations. To be honest I am not sure how st_nearest_features behaves when there are nodes inside your polygons.