esri2sf
esri2sf copied to clipboard
Error: lexical error: invalid char in json text
I'm getting an error about invalid chars in json text. I think it's related to the number of results being returned, but not sure.
If I pass the additional argument resultRecordCount = 1045
the error does not occur (1045 seems to be the max value that will work, but it doesn't return all rows I expect).
I've put a reprex below, thanks.
bbox <- sf::st_bbox(c("xmin" = 148.724638, "ymin" = -35.509575, "xmax" = 149.424995, "ymax" = -35.123524), crs = 4326L)
url <- "https://geo.abs.gov.au/arcgis/rest/services/ASGS2016/SEARCH/MapServer/12"
# Fails
esri2sf::esri2sf(url, bbox = bbox)
#> Layer Type: Feature Layer
#> Geometry Type: esriGeometryPolygon
#> Service Coordinate Reference System: 3857
#> No encoding supplied: defaulting to UTF-8.
#> Error: lexical error: invalid char in json text.
#> <!DOCTYPE html> <html lang=en>
#> (right here) ------^
# Works
esri2sf::esri2sf(url, bbox = bbox, resultRecordCount = 1045)
#> Layer Type: Feature Layer
#> Geometry Type: esriGeometryPolygon
#> Service Coordinate Reference System: 3857
#> Output Coordinate Reference System: 4326
#> Simple feature collection with 1045 features and 6 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: 148.1424 ymin: -36.00292 xmax: 149.7606 ymax: -34.91801
#> Geodetic CRS: WGS 84
#> First 10 features:
#> OBJECTID SA1_MAINCODE_2016 Shape_Length Shape_Area SA1_7DIGIT_2016
#> 1 41 80107107112 3599.253 376559.82 8107112
#> 2 120 80101100311 1404.023 99378.99 8100311
#> 3 128 80109110108 2906.142 400432.40 8110108
#> 4 132 80107107104 1560.334 136348.11 8107104
#> 5 203 80104103511 1472.241 106309.49 8103511
#> 6 325 80106112902 3028.459 535893.94 8112902
#> 7 346 80108109707 2822.745 250644.43 8109707
#> 8 357 80107107905 2589.095 385617.58 8107905
#> 9 469 80107108220 2589.859 283930.20 8108220
#> 10 490 80101100206 1847.252 171195.43 8100206
#> STATE_CODE_2016 geoms
#> 1 8 MULTIPOLYGON (((149.1099 -3...
#> 2 8 MULTIPOLYGON (((149.0963 -3...
#> 3 8 MULTIPOLYGON (((149.1077 -3...
#> 4 8 MULTIPOLYGON (((149.0967 -3...
#> 5 8 MULTIPOLYGON (((149.1398 -3...
#> 6 8 MULTIPOLYGON (((149.1367 -3...
#> 7 8 MULTIPOLYGON (((149.0604 -3...
#> 8 8 MULTIPOLYGON (((149.1195 -3...
#> 9 8 MULTIPOLYGON (((149.0472 -3...
#> 10 8 MULTIPOLYGON (((149.0734 -3...
sessionInfo()
#> R version 4.3.1 (2023-06-16)
#> Platform: aarch64-apple-darwin20 (64-bit)
#> Running under: macOS Ventura 13.5
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.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: Australia/Melbourne
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> loaded via a namespace (and not attached):
#> [1] styler_1.10.1 utf8_1.2.3 generics_0.1.3 class_7.3-22
#> [5] KernSmooth_2.23-21 RSQLite_2.3.1 digest_0.6.33 magrittr_2.0.3
#> [9] evaluate_0.21 grid_4.3.1 fastmap_1.1.1 blob_1.2.4
#> [13] R.oo_1.25.0 R.cache_0.16.0 jsonlite_1.8.7 R.utils_2.12.2
#> [17] e1071_1.7-13 DBI_1.1.3 httr_1.4.7 purrr_1.0.2
#> [21] fansi_1.0.4 pbapply_1.7-2 cli_3.6.1 rlang_1.1.1
#> [25] crayon_1.5.2 units_0.8-3 R.methodsS3_1.8.2 bit64_4.0.5
#> [29] reprex_2.0.2 withr_2.5.0 cachem_1.0.8 yaml_2.3.7
#> [33] tools_4.3.1 esri2sf_0.1.1 parallel_4.3.1 memoise_2.0.1
#> [37] dplyr_1.1.2 curl_5.0.2 vctrs_0.6.3 R6_2.5.1
#> [41] proxy_0.4-27 lifecycle_1.0.3 classInt_0.4-9 fs_1.6.3
#> [45] bit_4.0.5 pkgconfig_2.0.3 pillar_1.9.0 glue_1.6.2
#> [49] Rcpp_1.0.11 sf_1.0-14 xfun_0.40 tibble_3.2.1
#> [53] tidyselect_1.2.0 knitr_1.43 htmltools_0.5.6 rmarkdown_2.24
#> [57] compiler_4.3.1
Created on 2023-08-21 with reprex v2.0.2