Closed abhardwaj-iitd closed 3 weeks ago
can you run the cpde below?
library(r5r)
# build transport network
data_path <- system.file("extdata/poa", package = "r5r")
r5r_core <- setup_r5(data_path)
# load origin/destination points
points <- read.csv(file.path(data_path, "poa_points_of_interest.csv"))
departure_datetime <- as.POSIXct(
"13-05-2019 14:00:00",
format = "%d-%m-%Y %H:%M:%S"
)
ttm <- travel_time_matrix(
r5r_core,
origins = points,
destinations = points,
mode = c("WALK", "TRANSIT"),
departure_datetime = departure_datetime,
max_trip_duration = 60
)
head(ttm)
Hi, I am encountering the same issue again.
Please run the r5r::r5r_sitrep()
function to generate a situation report, and paste the output along with your issue. This will help us find eventual bugs.
The issue here is
> ttm <- travel_time_matrix(
+ r5r_core,
+ origins = points,
+ destinations = points,
+ mode = c("WALK", "TRANSIT"),
+ max_walk_time = 30,
+ max_trip_duration = 120,
+ verbose = FALSE,
+ progress = FALSE
+ )
Error in .jcall("RJavaTools", "Z", "hasField", .jcast(x, "java/lang/Object"), :
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "<parameter1>" is null
In addition: Warning messages:
1: In assign_points_input(origins, "origins") :
'origins$id' forcefully cast to character.
2: In assign_points_input(destinations, "destinations") :
'destinations$id' forcefully cast to character.
The output is pasted below.
> r5r::r5r_sitrep()
$r5r_package_version
[1] ‘2.0’
$r5_jar_version
[1] "7.1"
$java_version
[1] "21.0.2"
$set_memory
[1] "-Xmx2M"
$session_info
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22631)
Matrix products: default
locale:
[1] LC_COLLATE=English_India.1252 LC_CTYPE=English_India.1252 LC_MONETARY=English_India.1252
[4] LC_NUMERIC=C LC_TIME=English_India.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] r5r_2.0 processx_3.8.1 rJava_1.0-6
loaded via a namespace (and not attached):
[1] vctrs_0.6.1 utf8_1.2.3 rlang_1.1.0 pillar_1.9.0 glue_1.6.2
[6] lifecycle_1.0.4 memoise_2.0.1 fastmap_1.1.1 ps_1.7.5 fansi_1.0.4
[11] backports_1.4.1 checkmate_2.1.0 cachem_1.0.7 fs_1.5.2 cli_3.6.1
[16] tools_4.1.1 magrittr_2.0.3 tibble_3.2.1 crayon_1.5.3 pkgconfig_2.0.3
[21] ellipsis_0.3.2 data.table_1.14.8 rstudioapi_0.16.0 R6_2.5.1 compiler_4.1.1
can you run the cpde below?
library(r5r) # build transport network data_path <- system.file("extdata/poa", package = "r5r") r5r_core <- setup_r5(data_path) # load origin/destination points points <- read.csv(file.path(data_path, "poa_points_of_interest.csv")) departure_datetime <- as.POSIXct( "13-05-2019 14:00:00", format = "%d-%m-%Y %H:%M:%S" ) ttm <- travel_time_matrix( r5r_core, origins = points, destinations = points, mode = c("WALK", "TRANSIT"), departure_datetime = departure_datetime, max_trip_duration = 60 ) head(ttm)
have you tried running this code from a new R session ?
Hi @rafapereirabr
I am getting the same error
Error in .jcall("RJavaTools", "Z", "hasField", .jcast(x, "java/lang/Object"), : java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "<parameter1>" is null
But it is very odd, your reproducible example runs fine, as well as with some files for the UK.
However, I am trying with some files in the US and I am encountering the error. I think this is related to #393
This is my reproducible example:
# Using latest version
# devtools::install_github("ipeaGIT/r5r", subdir = "r-package")
options(java.parameters = '-Xmx12G')
# java version "21.0.2" 2024-01-16 LTS
system("java -version")
library(r5r)
library(sf)
library(tidyverse)
# Compute graph -----------------------------------------------------------
# Using PBF file only from:
# https://download.geofabrik.de/north-america/us-midwest.html
r5r_router <- r5r::setup_r5('router/', verbose = TRUE)
# Get ODs -----------------------------------------------------------------
# Read roadsx
road_network <- st_read('router/us-midwest-latest.osm.pbf', layer = 'lines')
# Get OD ponits
set.seed(3)
centroids <- st_centroid(road_network)
centroids <- sample_n(centroids, 100)
centroids <- centroids %>%
rename(id = osm_id) %>%
select(id)
# origin
origin <- centroids[70,]
# Dep time
departure_datetime <- as.POSIXct(
"10-05-2024 14:00:00",
format = "%d-%m-%Y %H:%M:%S"
)
# Run travel matrix
travel_time_matrix(
r5r_core = r5r_router,
origins = origin,
destinations = centroids,
mode = 'WALK',
departure_datetime = departure_datetime,
max_trip_duration = 60
)
And this is my situation report:
> r5r::r5r_sitrep()
$r5r_package_version
[1] ‘2.0.9999’
$r5_jar_version
[1] "7.1"
$java_version
[1] "21.0.2"
$set_memory
[1] "-Xmx512m"
$session_info
R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.3
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Europe/London
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] r5r_2.0.09999
loaded via a namespace (and not attached):
[1] compiler_4.3.1 backports_1.5.0 tools_4.3.1 rstudioapi_0.16.0.9000
[5] data.table_1.15.4 checkmate_2.3.1 rJava_1.0-11
Thanks!
@rafavdz , when exactly does the error occur for you? When building the graph or when running calculating the travel time matrix?
Two quick observations:
r5r_sitrep()
correctly shows that R correctly picks up your Java version.update: Using @rafavdz's code I was able to reproduce the error.
network.dat
file of the graph was not automatically saved in the data dir, which is strage)travel_time_matrix()
function.
Error in .jcall("RJavaTools", "Z", "hasField", .jcast(x, "java/lang/Object"), : java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "
" is null
I could run the reprex I mentioned a few comments above without a problem, in the same R session. In short, I don't know what could be causing this. I suspect it could be due to (1) RAM memory limit, or (2) the area is too large but R5 is no throwing an informative error in the v7.1
Hi @rafapereirabr ,
Thanks a lot for looking at this issue. Sorry for my slow reply. I confirm it is not an issue related to detecting the Java version as it builds the newtwrok. So not related to #393 .
I tried re-rerunning the repex earlier with more RAM (100GB) and I got the same error when running the travel_time_matrix()
function:
Error in .jcall("RJavaTools", "Z", "hasField", .jcast(x, "java/lang/Object"), :
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "" is null
However, I've got the following update. I re-run a similar code using a subset of the road network directly extracted from OSM and it ran without issues:
# Using latest version
# devtools::install_github("ipeaGIT/r5r", subdir = "r-package")
# rJavaEnv::java_quick_install(version = 21)
options(java.parameters = '-Xmx12G')
# java version "21.0.2" 2024-01-16 LTS
system("java -version")
library(r5r)
library(sf)
library(tidyverse)
# Compute graph -----------------------------------------------------------
# Using PBF file only from:
# https://gla-my.sharepoint.com/:u:/g/personal/joserafael_verduzco-torres_glasgow_ac_uk/EQBLwLynKrpLhky7L1XYLCMBL824Si53PovR2GSSytWYrg?e=jHyhNP
r5r_router <- r5r::setup_r5('router2/', verbose = TRUE)
# Get ODs -----------------------------------------------------------------
library(mapview)
# Read roads
road_network <- st_read('router2/kansas_city.osm.pbf', layer = 'lines')
# Get OD points
set.seed(3)
centroids <- st_centroid(road_network)
centroids <- sample_n(centroids, 100)
centroids <- centroids %>%
rename(id = osm_id) %>%
select(id)
# Dep time
departure_datetime <- as.POSIXct(
"13-05-2019 14:00:00",
format = "%d-%m-%Y %H:%M:%S"
)
# Run travel matrix
travel_mat <- travel_time_matrix(
r5r_core = r5r_router,
origins = centroids,
destinations = centroids,
mode = 'CAR',
departure_datetime = departure_datetime,
max_trip_duration = 60
)
So, it might be related to the input from Geofabrik, and not necessarily r5r. Alternatively, the size of the road network might be causing some problems for a reason, which I am less sure of because I've used the complete road network for the UK in a similar setting without problems.
Thanks again.
Hi @rafavdz , you said this time you used "a subset of the road network directly extracted from OSM and it ran without issues". Did you make any changes to the OSM network in your previous attempt?
Hi @rafapereirabr. No, I didn't. The first attempt uses the US-midwest PBF file directly from Geofabric.
So r5r
was able to build the network but failed to run the travel_time_matrix()
function. Correct?
What was different then between the attempt that failed and the one that worked? How many origins and destinations did you use in both cases?
Correct, @rafapereirabr . The network is built without apparent issues (I haven't checked the log in detail though). The error is returned when running the travel_time_matrix()
function (and other routing functions indeed).
The difference in the second attempt is that I am using a different PBF file, which covers a smaller area of the US-midwest and it is not sourced from Geobrik (I am including the URL for download in the code). Regarding the OD points, I used 3K in the first attempt. But I also tried with much less obtaining the same error. In the second repex I am using only 100 without any issues.
hm, so the error is not related to the number of OD points and it looks realated to an issue in the Geofabrik PBF file. correct?
I think so—the error occurs only when using the us-midwest Geofrabrik PBF file regardless of the number of OD points.
Hi all. This seems to be an issue with input data, and not necessarily with {r5r}. I'm closing this issue for now but I'm happy to reopen it if the problem persists
As I run my code for the time matrix, it shows the error [1] "Java-Object" for > r5r_core. And the final error shows Error in .jcall("RJavaTools", "Z", "hasField", .jcast(x, "java/lang/Object"), :
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "" is null. What should I do to get the value of r5r and a time matrix?