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

Support sfnetworks #19

Open
latot opened this issue Dec 18, 2023 · 1 comment
Open

Support sfnetworks #19

latot opened this issue Dec 18, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@latot
Copy link

latot commented Dec 18, 2023

Hi all, actually cppRouting has a lot of tools to internally handle some changes like contraction hierarchies.

At the same time, rn sfnetworks is a popular and very useful library to work on, I think would be a good idea have a function to convert sfnetwork graph to cpprouting graph.

I already have a function for it, but would be good to have for it some extra tests and I don't fully understand all the cppRouting graph structure to construct them for every case that may be of interestest.

The function I have:

sfnet2cppRouting <- ? function(
    network = NULL ? geotypes::sfnetworks_sfnetwork(null_ok = FALSE),
    weight = NULL ? typed::Character(1, anyNA = FALSE, null_ok = FALSE)) {
  cppRouting_graph <- cppRouting::makegraph(
    network %.>%
      sfnetworks::activate(., "edges") %.>%
      sf::st_as_sf(.) %.>%
      sf::st_drop_geometry(.) %.>%
      as.data.frame(.) %.>%
      dplyr::transmute(., .data$from, .data$to, cost = .data[[weight]]),
    directed = igraph::is_directed(network)
  )
  # }
  original_nodes <- network %.>%
    sfnetworks::activate(., "nodes") %.>%
    sf::st_as_sf(.)
  if (nrow(original_nodes) != cppRouting_graph$nbnode) {
    stop("The net was simplified by cppRouting, the nodes assignation can be broken.")
  }
  cppRouting_graph
}

Personally, the latest section, the stop is a need, happened, very low times, that sadly I was not able to reproduce, some nodes disappear using makegraph, so it would helps to detect that cases, has been some time from when that happened, maybe is fixed, sadly I was not able to found any issue here to check it.

Thx!

@vlarmet vlarmet self-assigned this Dec 19, 2023
@vlarmet vlarmet added the enhancement New feature or request label Dec 19, 2023
@vlarmet
Copy link
Owner

vlarmet commented Dec 19, 2023

For your information, the next (big) feature is to convert any spatial dataset (shp, geojson, sf, osm.pbf ...) into a routable network.

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

No branches or pull requests

2 participants