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

edge_ids differ in contracted graph vs. dodgr_to_sf() when using wt_profile = "motorcar" #216

Closed
jucardwell opened this issue Aug 31, 2023 · 3 comments

Comments

@jucardwell
Copy link

Hi,

I am working on a project that requires me to remove road segments based on a set of lat/lons. To do so, I exported a weighted streetnet as an sf object so that I could identify the appropriate segments to remove using spatial queries.

I had initially done testing using the built-in hampi streetnet to ensure that the edge_ids remain consistent between the contracted graph and the sf object, and I determined that they were. For instance, in the case below, both tests return TRUE only

library(dodgr)
library(sf)
library(tidyverse)

#general hampi streetnetwork
hampi_general <- weight_streetnet(hampi)
#contracted
contracted_general <- dodgr_contract_graph(hampi_general)
#sf version
sf_general <- dodgr_to_sf(hampi_general) %>% st_drop_geometry()

#test if edge ids in both
unique(contracted_general$edge_id %in% sf_general$edge_id)
#test if rows are identical
unique(do.call(paste0, contracted_general) %in% do.call(paste0, sf_general))

However, when trying to remove the edges from my own network, I discovered that they actually did not remain consistent. Subsequently I discovered that when using a weighting profile, edge_ids no longer remain consistent between the contracted graph and the sf object. For instance, in the case below, both tests return TRUE and FALSE

hampi_motorcar <- weight_streetnet(hampi, wt_profile = "motorcar")
contracted_motorcar <- dodgr_contract_graph(hampi_motorcar)
sf_motorcar <- dodgr_to_sf(hampi_motorcar) %>% st_drop_geometry()

#test if edge ids in both
unique(contracted_motorcar$edge_id %in% sf_motorcar$edge_id)
#test if rows are identical
unique(do.call(paste0, contracted_motorcar) %in% do.call(paste0, sf_motorcar))

However, it seems that when even using a weighting profile, the from_id and to_id remain consistent

contracted_motorcar_ids <- contracted_motorcar %>% as_tibble() %>% select(from_id, to_id)
sf_motorcar_ids <- sf_motorcar %>% select(from_id, to_id)

unique(do.call(paste0, contracted_motorcar_ids) %in% do.call(paste0, sf_motorcar_ids))

@mpadge
Copy link
Member

mpadge commented May 16, 2024

Sorry @jucardwell that this issue slipped through the gaps for such a long time 😱. The resolution to your problem is that "edge_id" values only mean something within one single graph, and should never be used to compare graphs. The fact that the first example generates identical edge id values should be considered an accident. (This case will only arise when graph contraction produces the exact format required for representation as sf LINESTRING objects, which is not always the case.)

@mpadge mpadge closed this as completed May 16, 2024
@jucardwell
Copy link
Author

Hi @mpadge, thanks for the response. Just for clarification, the node_ids should remain consistent?

@mpadge
Copy link
Member

mpadge commented May 16, 2024

Yes, they're directly from OSM.

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

No branches or pull requests

2 participants