ipeaGIT / r5r

https://ipeagit.github.io/r5r/
Other
181 stars 30 forks source link

Setting up r5r with multiple OSM .pbf's #331

Closed kmcd39 closed 1 year ago

kmcd39 commented 1 year ago

I'm a little new to doing routing analyses in R so I'm sorry if I'm overlooking something.

I'm analyzing an area in the US and want to do accessibility/isochrone analysis for various start/end points in the area. The area is between two regions so a reasonable approach to setup files for r5r would seem to download OSM street networks for both regions, call setup_r5r, and run the analysis. However, it seems like only one of the street network pbf's is being read in.

Reproducible example:

library(tidyverse)
library(sf)

rm(list = ls() )

## get osm streets ---------------------------------------------------------

r5dir <- Sys.getenv('r5dir')
osct <- osmextract::oe_match('us/connecticut')

ctrds <- osmextract::oe_read(
  osct$url
  ,layer = 'lines'
  # i think i should set one persistent directory for all osm/open streetmap data...
  ,download_directory = r5dir
)
osri <- osmextract::oe_match('us/rhode island')
rirds <- osmextract::oe_read(
  osri$url
  ,layer = 'lines'
  # i think i should set one persistent directory for all osm/open streetmap data...
  ,download_directory = r5dir
)

## setup r5  ---------------------------------------------------------
library(r5r)
library(data.table)
library(interp)

# allocate more memory to Java per the r5r vignette
library(rJava)
options('java.parameters')
options(java.parameters = "-Xmx2G")

rJava::.jinit()
rJava::.jcall("java.lang.System", "S", "getProperty", "java.version")

# osm streets and gtfs should be saved here
r5dir
r5r_core <- r5r::setup_r5(r5dir)

# extract street network from the r5r_cor
street_net <- r5r::street_network_to_sf(r5r_core)

states <- tigris::states() %>%
  filter(NAME %in% c('Connecticut', 'Rhode Island'))

street_net$edges %>% tibble() %>% count(street_class)

street_net$edges %>%
  filter(street_class == 'MOTORWAY') %>%
  ggplot() +
  geom_sf( color = 'purple') +
  geom_sf(data =st_boundary(states))
# only 1 state's roads were included in the r5_core setup. Roads for other state are missing.

When I ran the travel time matrix function with verbose = T, I got messages that the point was not near the street network. It was near the street network for the state that didn't load, but which i did setup OSM street data for, per example above.

I also wonder if there would be any issue having multiple GTFS files within the r5r data path, but haven't tested this yet.

Here is the situation report:

> r5r::r5r_sitrep()
$r5r_package_version
[1] ‘1.0.1’

$r5_jar_version
[1] "6.9"

$java_version
[1] "11"

$set_memory
[1] "-Xmx2G"

$session_info
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] rJava_1.0-6       interp_1.1-3      data.table_1.14.8 r5r_1.0.1        
 [5] sf_1.0-10         lubridate_1.9.2   forcats_1.0.0     stringr_1.5.0    
 [9] dplyr_1.1.0       purrr_1.0.1       readr_2.1.4       tidyr_1.3.0      
[13] tibble_3.1.7      ggplot2_3.4.1     tidyverse_2.0.0  

loaded via a namespace (and not attached):
  [1] colorspace_2.1-0    deldir_1.0-6        ellipsis_0.3.2      class_7.3-20       
  [5] gtfsio_1.1.0        fs_1.5.2            rstudioapi_0.14     proxy_0.4-27       
  [9] farver_2.1.1        remotes_2.4.2       graphlayouts_0.8.4  ggrepel_0.9.3      
 [13] bit64_4.0.5         fansi_1.0.3         cachem_1.0.6        knitr_1.42         
 [17] polyclip_1.10-4     pkgload_1.3.2       jsonlite_1.8.4      visaux_0.0.0.9000  
 [21] censusrx_0.0.0.9000 taux_0.0.0.9000     ggforce_0.4.1       shiny_1.7.4        
 [25] compiler_4.2.2      httr_1.4.5          backports_1.4.1     fastmap_1.1.0      
 [29] cli_3.5.0           later_1.3.0         tweenr_2.0.2        htmltools_0.5.4    
 [33] prettyunits_1.1.1   tools_4.2.2         igraph_1.4.1        gtable_0.3.1       
 [37] glue_1.6.2          rappdirs_0.3.3      Rcpp_1.0.10         vctrs_0.5.2        
 [41] sfnetworks_0.6.2    tigris_2.0.1        ggraph_2.1.0        lwgeom_0.2-11      
 [45] xfun_0.37           ps_1.7.0            divseg_0.0.0.9000   timechange_0.2.0   
 [49] mime_0.12           miniUI_0.1.1.1      lifecycle_1.0.3     devtools_2.4.5     
 [53] MASS_7.3-58.2       scales_1.2.1        tidygraph_1.2.3     tidytransit_1.5.0  
 [57] vroom_1.6.1         ragg_1.2.5          hms_1.1.2           promises_1.2.0.1   
 [61] geodist_0.0.8       RColorBrewer_1.1-3  curl_5.0.0          yaml_2.3.7         
 [65] memoise_2.0.1       RSocrata_1.7.12-4   gridExtra_2.3       stringi_1.7.6      
 [69] checkmate_2.1.0     e1071_1.7-11        pkgbuild_1.4.0      osmextract_0.4.1   
 [73] systemfonts_1.0.4   rlang_1.0.6         pkgconfig_2.0.3     evaluate_0.20      
 [77] gtfs2gps_2.1-0      htmlwidgets_1.6.1   bit_4.0.5           processx_3.8.0     
 [81] tidyselect_1.2.0    plyr_1.8.8          magrittr_2.0.3      R6_2.5.1           
 [85] generics_0.1.3      profvis_0.3.7       DBI_1.1.3           pillar_1.8.1       
 [89] withr_2.5.0         units_0.8-0         traveltime_0.0.2    crayon_1.5.2       
 [93] uuid_1.1-0          KernSmooth_2.23-20  utf8_1.2.2          tzdb_0.3.0         
 [97] rmarkdown_2.20      urlchecker_1.0.1    sfheaders_0.4.2     aevis_0.0.0.9000   
[101] viridis_0.6.2       usethis_2.1.6       grid_4.2.2          callr_3.7.3        
[105] digest_0.6.31       classInt_0.4-8      xtable_1.8-4        httpuv_1.6.9       
[109] textshaping_0.3.6   munsell_0.5.0       osmdata_0.2.1       viridisLite_0.4.1  
[113] sessioninfo_1.2.2  

Thank you!!

rafapereirabr commented 1 year ago

Hi @kmcd39 . Thanks for the opening this issue. The problem is that there should be only one .pbf file in the directory. Ideally, you should be able to download a single OSM data file covering the entire region of interest. If that's not possible, you can probably merge the two files using with JOSM or Osmosis

kmcd39 commented 1 year ago

okay, great, thanks. Gonna try those workarounds!

Should it be able to work with multiple gtfs .zip's in the data path?

rafapereirabr commented 1 year ago

Yes, it works fine with  multiple gtfs feeds in the data pathRafael H M Pereira -------- Original message --------From: kmcd39 @.> Date: 4/7/23 16:35 (GMT-03:00) To: ipeaGIT/r5r @.> Cc: Rafael H M Pereira @.>, Comment @.> Subject: Re: [ipeaGIT/r5r] Setting up r5r with multiple OSM .pbf's (Issue #331) okay, great, thanks. Gonna try those workarounds! Should it be able to work with multiple gtfs .zip's in the data path?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

stupidpupil commented 1 year ago

You can definitely merge multiple OSM files using osmium.