ipeaGIT/r5r

isochrone() -> cannot read properties of undefined (reading '0')

Closed this issue · 8 comments

Hi,

I'm having a problem when running isochrone.

iso <- isochrone(
  conexao_r5r,
  origins = ats,
  mode = c('CAR', 'TRANSIT'),
  departure_datetime = departure_datetime,
  cutoffs = seq(0, 180, 15)
)
12 out of 12 origins processed... DONE!
Consolidating results... DONE!
Preparing final output... DONE!
Error in `dplyr::summarise()`:In argument: `polygons = `%>%`(...)`.
Caused by error:
! TypeError: Cannot read properties of undefined (reading '0')
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error in `dplyr::summarise()`:In argument: `polygons = `%>%`(...)`.
Caused by error:
! TypeError: Cannot read properties of undefined (reading '0')
---
Backtrace:1. ├─r5r::isochrone(...)
  2. │ └─base::lapply(X = unique(origins$id), FUN = prep_iso)
  3. │   └─r5r (local) FUN(X[[i]], ...)
  4. │     └─base::lapply(X = cutoffs[cutoffs > 0], FUN = get_poly)
  5. │       └─r5r (local) FUN(X[[i]], ...)
  6. │         ├─concaveman::concaveman(temp)
  7. │         └─concaveman:::concaveman.sf(temp)
  8. │           └─points %>% ...
  9. ├─dplyr::summarise(...)
 10. ├─sf:::summarise.sf(...)
 11. ├─base::NextMethod()
 12. ├─dplyr:::summarise.data.frame(...)
 13. │ └─dplyr:::summarise_cols(.data, dplyr_quosures(...), by, "summarise")
 14. │   ├─base::withCallingHandlers(...)
 15. │   └─dplyr:::map(quosures, summarise_eval_one, mask = mask)
 16. │     └─base::lapply(.x, .f, ...)
 17. │       └─dplyr (local) FUN(X[[i]], ...)
 18. │         └─mask$eval_all_summarise(quo)
 19. │           └─dplyr (local) eval()
 20. ├─... %>% sf::st_sfc(crs = sf::st_crs(points))
 21. ├─sf::st_sfc(., crs = sf::st_crs(points))
 22. ├─sf::st_polygon(.)
 23. │ └─sf:::MtrxSet(x, dim, type = "POLYGON", needClosed = TRUE)
 24. │   └─base::stopifnot(is.list(x))
 25. ├─base::as.matrix(.)
 26. ├─concaveman::concaveman(sf::st_coordinates(.), concavity, length_threshold)
 27. ├─concaveman:::concaveman.matrix(...)
 28. │ └─concaveman (local) workhorse(points, concavity, length_threshold)
 29. │   └─ctx$eval(jscode)
 30. │     └─V8 (local) evaluate_js(src, serialize = serialize, await = await)
 31. │       ├─V8:::get_str_output(...)
 32. │       └─V8:::context_eval(join(src), private$context, serialize, await)
 33. └─base::stop(`<std::rn_>`)
> r5r::r5r_sitrep()
$r5r_package_version
[1] ‘1.1.0$r5_jar_version
[1] "6.9"

$java_version
[1] "11.0.20.1"

$set_memory
[1] "-Xmx8G"

$session_info
R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.4.1

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: America/Sao_Paulo
tzcode source: internal

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

other attached packages:
[1] r5r_1.1.0

loaded via a namespace (and not attached):
 [1] crayon_1.5.2       vctrs_0.6.3        cli_3.6.1          rlang_1.1.1        DBI_1.1.3          KernSmooth_2.23-21 generics_0.1.3     sf_1.0-14          jsonlite_1.8.7     data.table_1.14.8 
[11] rJava_1.0-6        glue_1.6.2         backports_1.4.1    V8_4.3.3           e1071_1.7-13       fansi_1.0.4        grid_4.3.1         sfheaders_0.4.3    classInt_0.4-9     tibble_3.2.1      
[21] lifecycle_1.0.3    compiler_4.3.1     dplyr_1.1.2        Rcpp_1.0.11        pkgconfig_2.0.3    rstudioapi_0.15.0  R6_2.5.1           class_7.3-22       tidyselect_1.2.0   utf8_1.2.3        
[31] curl_5.0.1         pillar_1.9.0       magrittr_2.0.3     checkmate_2.2.0    concaveman_1.1.0   tools_4.3.1        proxy_0.4-27       units_0.8-2       

Could you please tell us the area of study so we cna try to reproduce the problem ?

I've made a extract (from Protomaps) covering 'Espirito Santo' (Brazil).
And I'm trying to make isochrones for 12 points in that state.
Thanks,

ok, coul you send the coordinates of those 12 points? This does not have to be super exact. Coordinates close to those 12 points would be enough

Can I send you in private, pls? You can find me at username at gmail.
Otherwise I try to post it here.

I'll post it here:

lat lon
-20.8464868 -41.1165829
-18.708948 -40.4035305
-20.3513038 -40.324244
-19.5351335 -40.63241439999999
13.0851139 -86.3630197
-20.6726278 -40.4985232
-18.7608328 -40.8887762
-18.7145005 -39.8707459
-20.3168448 -40.3184538
-20.3235931 -41.1370487
-19.9321287 -40.1455633
-19.3994319 -40.0652589

Important to mention that I tried running the function for "Minas Gerais" and it worked. It must be something related to the "Espirito Santo" dataset, somehow.
Thanks,

The problem is with the 5th point, which has a wrong lat lon. I'm closing the issue and leave here my appreciation for the library, many thanks!!

ah, I'm glad you've found the source of the problem.

If the problem was related to your OSM data file, I would reccommend you download it again:

options(java.parameters = '-Xmx4G')
library(r5r)
library(osmextract)
library(tmaptools)

data_path <- 'C:/Users/user/Downloads/r5r_es'

# get coordinates of location
ES <- tmaptools::geocode_OSM("Espirito Santo, Brazil")$coords

# get link to file
link <- oe_match(ES, provider = "openstreetmap_fr")

osmextract::oe_download(link$url, 
                        provider = "openstreetmap_fr",
                        download_directory  = data_path)

Thanks, Rafael.

The osm area must (at least) cover the point from which the isochrone is drawn, right? And because the point coords were wrong, it could not draw any.
I am/was worried about letting an excess area beyond the state borders, but due to the max area allowed, that is not always possible (for instance, for Minas Gerais). I might have to draw an isochrone for an individual point, sometimes.

Thanks again,