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

Efficiently break-up network #54

Closed
Robinlovelace opened this issue Oct 27, 2020 · 3 comments
Closed

Efficiently break-up network #54

Robinlovelace opened this issue Oct 27, 2020 · 3 comments
Assignees

Comments

@Robinlovelace
Copy link
Contributor

We already have code to break up bits on the OSM network but this fails for the rnet use case:

# Aim: test breaking-up long linestrings

rnet = pct::get_pct_rnet("hereford-and-worcester")
rnet$length = as.numeric(sf::st_length(rnet))
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
summary(rnet$length)
#>      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
#>     0.133    54.516   190.069   552.491   514.810 15207.218

rnet = sf::st_transform(rnet, 27700)
rnet_updated = trafficalmr::osm_consolidate(rnet, segment = 500)
#> Error in trafficalmr::osm_consolidate(rnet, segment = 500): all(c("name", "ref", "highway") %in% n) is not TRUE

Created on 2020-10-27 by the reprex package (v0.3.0)

Challenge: starting with the rnet object above, efficiently break up any lines over 500m.
Implementation based on new stplanr code is quite slow.

@Robinlovelace
Copy link
Contributor Author

He's a reproducible example showing it working with the new stplanr function - a bit slow:

# Aim: test breaking-up long linestrings

library(sf)
library(stars)
library(dplyr)

rnet = pct::get_pct_rnet("hereford-and-worcester")
rnet$length = as.numeric(sf::st_length(rnet))
summary(rnet$length)

rnet = sf::st_transform(rnet, 27700)
r = raster::raster(rnet, resolution = 500)
raster::values(r) = 1
rast_template_polys = r %>% stars::st_as_stars() %>% sf::st_as_sf(as_points = FALSE)
rast_template_polys

system.time({
rnet_updated = trafficalmr::osm_consolidate(rnet, segment = 500)
})

rnet_long = rnet %>% filter(length > 1000)
summary(rnet_long$length)
system.time({
rnet_updated = stplanr::line_breakup(l = rnet_long, z = rast_template_polys)
})
summary(st_length(rnet_updated))

@Robinlovelace
Copy link
Contributor Author

Update: using multithreaded code documented here r-spatial/qgisprocess#26

@Robinlovelace
Copy link
Contributor Author

Multithreaded implementation in GRASS via the qgisprocess package did it in 5 minutes for the national route network.

Details: https://github.com/saferactive/saferactive/blob/master/code/tests/line_breakup_qgis.R#L92

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