Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up'reverse_geocode()' should recognize and avoid empty geometries #16
Comments
|
Added check for empty entries in the geometry column in 5d66f33. Attempts to apply functions on empty geometries are now recognized and trigger an error. Construct an empty library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
nrows <- 3
(x <- st_sf(
id = 1:nrows,
geometry = st_sfc(lapply(1:nrows, function(x) st_geometrycollection()))
))
#> Simple feature collection with 3 features and 1 field (with 3 geometries empty)
#> geometry type: GEOMETRYCOLLECTION
#> dimension: XY
#> bbox: xmin: NA ymin: NA xmax: NA ymax: NA
#> epsg (SRID): NA
#> proj4string: NA
#> id geometry
#> 1 1 GEOMETRYCOLLECTION EMPTY
#> 2 2 GEOMETRYCOLLECTION EMPTY
#> 3 3 GEOMETRYCOLLECTION EMPTYAnd test the functions: library(hereR)
# POIs
reverse_geocode(x)
#> Error in .check_points(poi): 'points' has empty entries in the geometry column.
weather(x)
#> Error in .check_points(poi): 'points' has empty entries in the geometry column.
# AOIs
traffic(x)
#> Error in .check_polygon(aoi): 'polygon' has empty entries in the geometry column.And with the example from above: x <- data.frame(
id = c(1, 2, 3),
company = c("Schweizerische Bundesbahnen SBB", "Bahnhof AG", "Deutsche Bahn AG"),
address = c("Wylerstrasse 123, 3000 Bern 65", "not_an_address", "Potsdamer Platz 2, 10785 Berlin"),
stringsAsFactors = FALSE
)
locs <- geocode(x$address)
#> Address(es) 'not_an_address' not found.
y <- st_as_sf(merge(x, locs, all.x = TRUE, by = "id"))
reverse_geocode(y)
#> Error in .check_points(poi): 'points' has empty entries in the geometry column.Session infodevtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#> setting value
#> version R version 3.6.1 (2019-07-05)
#> os macOS Catalina 10.15.1
#> system x86_64, darwin15.6.0
#> ui X11
#> language (EN)
#> collate de_CH.UTF-8
#> ctype de_CH.UTF-8
#> tz Europe/Zurich
#> date 2019-12-16
#>
#> ─ Packages ──────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)
#> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.0)
#> callr 3.3.2 2019-09-22 [1] CRAN (R 3.6.0)
#> class 7.3-15 2019-01-01 [1] CRAN (R 3.6.1)
#> classInt 0.4-2 2019-10-17 [1] CRAN (R 3.6.0)
#> cli 1.1.0 2019-03-19 [1] CRAN (R 3.6.0)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0)
#> curl 4.2 2019-09-24 [1] CRAN (R 3.6.0)
#> data.table 1.12.6 2019-10-18 [1] CRAN (R 3.6.0)
#> DBI 1.0.0 2018-05-02 [1] CRAN (R 3.6.0)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0)
#> devtools 2.2.1 2019-09-24 [1] CRAN (R 3.6.0)
#> digest 0.6.22 2019-10-21 [1] CRAN (R 3.6.0)
#> e1071 1.7-2 2019-06-05 [1] CRAN (R 3.6.0)
#> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.0)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0)
#> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.0)
#> glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0)
#> hereR * 0.2.0.9000 2019-12-16 [1] local
#> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.0)
#> jsonlite 1.6 2018-12-07 [1] CRAN (R 3.6.0)
#> KernSmooth 2.23-16 2019-10-15 [1] CRAN (R 3.6.0)
#> knitr 1.25 2019-09-18 [1] CRAN (R 3.6.0)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.0)
#> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.0)
#> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.0)
#> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.0)
#> processx 3.4.1 2019-07-18 [1] CRAN (R 3.6.0)
#> ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0)
#> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.0)
#> Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.0)
#> remotes 2.1.0 2019-06-24 [1] CRAN (R 3.6.0)
#> rlang 0.4.1 2019-10-24 [1] CRAN (R 3.6.0)
#> rmarkdown 1.16 2019-10-01 [1] CRAN (R 3.6.0)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0)
#> sf * 0.8-0 2019-09-17 [1] CRAN (R 3.6.0)
#> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0)
#> testthat 2.2.1 2019-07-25 [1] CRAN (R 3.6.0)
#> units 0.6-5 2019-10-08 [1] CRAN (R 3.6.0)
#> usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.0)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0)
#> xfun 0.10 2019-10-01 [1] CRAN (R 3.6.0)
#> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.6.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library |
Attempts to
reverse_geocode()empty geometries should be recognized and trigger an error.This warning occurs because the
NAs are sent as coordinates to the API:Empty geometries should therefore be avoided in the input of
reverese_geocode()by checking thesfobject viast_is_empty()and an error should be thrown if some are detected.Session info