You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thank you so much for developing this very useful package!
I am working on calculating a travel time matrix (by car) between each "iris" (essentially neighborhoods) in France. Since the full .pbf file for France was too large for r5r to process (4.5 GB), I first filtered the file following guidelines from conveyal . Then, I implemented a solution where I select a 100 km buffer around each French department, calculate the bounding box, and crop the .pbf file accordingly.
For cropping the .pbf file, I used Osmosis as recommended in FAQ 4 of r5r. However, for several departments I encountered errors when setting up r5. Specifically, I was receiving this error: Error in setup_r5(...) : java.lang.NullPointerException.
According to these issues (1, 2), it seemed to me that this error may occur when ways and relations are excluded during cropping. Therefore, I modified the Osmosis cropping code by including clipIncompleteEntities=yes (as suggested here).
This approach has allowed me to compute the travel time matrix for most departments successfully. However, I am still encountering an issue with two departments (departments code==33 and 60). When setting up r5r using the pbf files related to these departments, I receive the following error:
Do you have any idea on waht might be causing this issue? I am including my code, and the cropped .pbf file for one of the two departments causing the error.
Thank you in advance for your help!
Here is the full r code:
options(java.parameters='-Xmx12G')
options(scipen=999)
library(sf)
library(r5r)
library(tidyverse)
library(arrow)
library(fs)
library(accessibility)
library(mapview)
departement_fr<- st_read(here::here("coordinates\\ADMIN-EXPRESS-COG_1-1__SHP__FRA_2018-04-03\\ADMIN-EXPRESS-COG\\1_DONNEES_LIVRAISON_2018-03-28\\ADE-COG_1-1_SHP_LAMB93_FR\\DEPARTEMENT.shp"))
load("data\\iris_adm.Rdata")
load("data\\school_france_ttm.Rdata")
fr_iris<- st_transform(fr_iris, 4326)
fr_iris_tmp<-fr_iris %>%
select(code_iris)
centroids_fr<- as.data.frame(st_coordinates(st_centroid(fr_iris$geometry))) %>%
rename(lon=1, lat=2)
centroids_fr<- cbind(centroids_fr, fr_iris_tmp)
# List all unique department codesunique_departments<- unique(departement_fr$INSEE_DEP)
# Initialize timing for the full processtotal_start_time<- Sys.time()
# Initialize a vector to store department codes with errorserror_departments<- c()
for (dep_codeinunique_departments ) {
cat(paste0("Processing department: ", dep_code, "\n"))
# Select current departmentdepartment_x<-departement_fr %>%
st_transform(4326) %>%
filter(INSEE_DEP==dep_code)
# Create a 100 km buffer around the selected departmentbuffer_100km<- st_buffer(department_x, dist=100000) # 100 km# Find all neighborhoods that intersect with this 100 km bufferneighborhoods_in_buffer<-fr_iris %>%
st_filter(buffer_100km, .predicate=st_intersects)
# Compute bounding box for areaarea_bbox<- st_bbox(neighborhoods_in_buffer)
area_bbox_sf<- st_as_sfc(area_bbox)
# Define paths for temporary files created by Osmosisfolder_path<- sprintf("D:\\France\\network_%s\\", dep_code)
dir.create(folder_path, recursive=TRUE)
smaller_pbf<- sprintf("D:\\France\\network_%s\\smaller_%s.pbf", dep_code,dep_code)
network_dat<-"D:\\France\\network\\network.dat"network_settings<-"D:\\France\\network\\network_settings.json"mapdb<- paste0(smaller_pbf, ".mapdb")
mapdb_p<- paste0(smaller_pbf, ".mapdb.p")
large_pbf_path<-"D:\\France\\ttm\\filtered.osm.pbf"# Run Osmosis command to create a smaller .pbf fileosmosis_cmd<- sprintf("%s --read-pbf %s --bounding-box left=%s bottom=%s right=%s top=%s clipIncompleteEntities=yes --write-pbf %s",
"osmosis",
large_pbf_path,
as.numeric(area_bbox$xmin), as.numeric(area_bbox$ymin),
as.numeric(area_bbox$xmax), as.numeric(area_bbox$ymax),
smaller_pbf)
# Execute the Osmosis command
shell(osmosis_cmd, translate=TRUE)
gc()
# Try to set up r5r core with error handlingr5r_core<- tryCatch({
setup_r5(sprintf("D:\\France\\network_%s\\", dep_code), verbose=FALSE)
}, error=function(e) {
cat(paste0("Error in setting up r5r for department ", dep_code, ": ", e$message, "\n"))
# Append the department code to error_departments vectorerror_departments<<- c(error_departments, dep_code)
return(NULL) # Return NULL if there's an error
})
# Skip to the next iteration if setup_r5 failedif (is.null(r5r_core)) {
files_to_delete<- c(folder_path, smaller_pbf, network_dat, network_settings, mapdb, mapdb_p)
for (file_pathinfiles_to_delete) {
if (file.exists(file_path)) {
file.remove(file_path)
cat(paste0("Deleted temporary file: ", file_path, "\n"))
}
}
next
}
stop_r5(r5r_core)
gc()
files_to_delete<- c(folder_path, smaller_pbf, network_dat, network_settings, mapdb, mapdb_p)
for (file_pathinfiles_to_delete) {
if (file.exists(file_path)) {
file.remove(file_path)
cat(paste0("Deleted temporary file: ", file_path, "\n"))
}
}
gc()
}
total_end_time<- Sys.time()
cat(paste0("Total processing time: ", total_end_time-total_start_time, " seconds.\n"))
The text was updated successfully, but these errors were encountered:
Hi @rafapereirabr , I’m sorry to bother you directly. I was wondering if you think this issue is not strictly related to r5r, and if I should seek help elsewhere. Many thanks again!
Hi @gmariani95 . I'm sorry for the slow response and thanks for such detailed explanation. We have never encountered this error message before. Basde on this part of the message "Invalid number of points in LineString (found 1 - must be 0 or >= 2)", it seems to me that there was a problem with one or more road segments when they got cropped.
I guess a simple solution would be to use a slightly larger or smaller buffer for these areas. Could you maybe try a 105 km buffer for these two areas and see if it works ?
First of all, thank you so much for developing this very useful package!
I am working on calculating a travel time matrix (by car) between each "iris" (essentially neighborhoods) in France. Since the full .pbf file for France was too large for r5r to process (4.5 GB), I first filtered the file following guidelines from conveyal . Then, I implemented a solution where I select a 100 km buffer around each French department, calculate the bounding box, and crop the .pbf file accordingly.
For cropping the .pbf file, I used Osmosis as recommended in FAQ 4 of r5r. However, for several departments I encountered errors when setting up r5. Specifically, I was receiving this error:
Error in setup_r5(...) : java.lang.NullPointerException
.According to these issues (1, 2), it seemed to me that this error may occur when ways and relations are excluded during cropping. Therefore, I modified the Osmosis cropping code by including
clipIncompleteEntities=yes
(as suggested here).This approach has allowed me to compute the travel time matrix for most departments successfully. However, I am still encountering an issue with two departments (departments code==33 and 60). When setting up r5r using the pbf files related to these departments, I receive the following error:
This is the result form running the
r5r::r5r_sitrep()
function:Do you have any idea on waht might be causing this issue? I am including my code, and the cropped .pbf file for one of the two departments causing the error.
Thank you in advance for your help!
Here is the full r code:
The text was updated successfully, but these errors were encountered: