From 2ba55fdd583c14a7f2483391200834afc19b614d Mon Sep 17 00:00:00 2001 From: Jesse Cambon Date: Sun, 24 Oct 2021 09:30:17 -0400 Subject: [PATCH 1/3] tryCatch fix for #152 --- vignettes/tidygeocoder.Rmd | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/vignettes/tidygeocoder.Rmd b/vignettes/tidygeocoder.Rmd index fa9c2250..cb17da2f 100644 --- a/vignettes/tidygeocoder.Rmd +++ b/vignettes/tidygeocoder.Rmd @@ -15,6 +15,50 @@ options(tibble.print_min = 4L, tibble.print_max = 4L) set.seed(42) ``` +```{r, echo = FALSE, message = FALSE} +# check to make sure both the US Census and Nominatim endpoints are available +# (ie. we have an internet connection) + +# Check that US Census service is available +tryCatch( + expr = { + tidygeocoder::geo('1600 Pennsylvania Avenue NW, Washington, DC 20500', + method = 'census') + }, + error = function(e) { + stop(paste0('The US Census geocoding API is not available. ', + 'The following error was produced:\n', e), call. = FALSE) + }, + warning = function(w) { + stop(paste0('The US Census geocoding API is not available. ', + 'The following warning was produced:\n', w), call. = FALSE) + }, + finally = { + message('') + }) + +# Check that the Nominatim service is available +tryCatch( + expr = { + tidygeocoder::geo('London', method = 'osm') + tidygeocoder::reverse_geo(lat = 0, long = 0, method = 'osm') + }, + error = function(e) { + stop(paste0('The Nominatim ("osm") geocoding API is not available. ', + 'The following error was produced:\n', e), call. = FALSE) + }, + warning = function(w) { + stop(paste0('The Nominatim ("osm") geocoding API is not available. ', + 'The following warning was produced:\n', w), call. = FALSE) + }, + finally = { + message('') + }) + +#tidygeocoder::geo('London', method = 'osm') +``` + + ## Introduction Tidygeocoder provides a unified interface for performing both forward and reverse geocoding queries with a variety of geocoding services. In forward geocoding you provide an address to the geocoding service and you get latitude and longitude coordinates in return. In reverse geocoding you provide the latitude and longitude and the geocoding service will return that location's address. In both cases, other data about the location can be provided by the geocoding service. From 31b39764559d035170d1b0db99912c6aa1e3b012 Mon Sep 17 00:00:00 2001 From: Jesse Cambon Date: Sun, 24 Oct 2021 09:39:12 -0400 Subject: [PATCH 2/3] reconfigured vignette to execute locally #152 --- docs/articles/developer_notes.html | 2 +- docs/articles/tidygeocoder.html | 74 +++--- docs/pkgdown.yml | 2 +- docs/reference/geo.html | 4 +- docs/reference/geo_combine.html | 6 +- docs/reference/geocode.html | 4 +- docs/reference/geocode_combine.html | 6 +- docs/reference/reverse_geocode.html | 2 +- vignettes/tidygeocoder.Rmd | 347 ++++++++++++++++++++-------- vignettes/tidygeocoder.Rmd.orig | 306 ++++++++++++++++++++++++ 10 files changed, 605 insertions(+), 148 deletions(-) create mode 100644 vignettes/tidygeocoder.Rmd.orig diff --git a/docs/articles/developer_notes.html b/docs/articles/developer_notes.html index 3b883630..362484ec 100644 --- a/docs/articles/developer_notes.html +++ b/docs/articles/developer_notes.html @@ -162,7 +162,7 @@

#> limit : "1" #> format : "json" #> HTTP Status Code: 200 -#> Query completed in: 0.4 seconds +#> Query completed in: 0.3 seconds #> Total query time (including sleep): 1 seconds #> #> diff --git a/docs/articles/tidygeocoder.html b/docs/articles/tidygeocoder.html index e74dd0be..8f313696 100644 --- a/docs/articles/tidygeocoder.html +++ b/docs/articles/tidygeocoder.html @@ -170,7 +170,7 @@

#> format : "json" #> benchmark : "Public_AR_Current" #> vintage : "Current_Current" -#> Query completed in: 1.4 seconds +#> Query completed in: 1.2 seconds @@ -197,7 +197,7 @@

lat = latitude, long = longitude ) #> Passing 2 addresses to the Nominatim single address geocoder -#> Query completed in: 2 seconds +#> Query completed in: 2.1 seconds

singlelineaddress
@@ -222,7 +222,7 @@

census_c1 <- address_components %>% geocode(street = street, city = cty, state = st, method = "census") #> Passing 2 addresses to the US Census batch geocoder -#> Query completed in: 1.9 seconds +#> Query completed in: 1.8 seconds

address
@@ -255,7 +255,7 @@

method = "census", full_results = TRUE, api_options = list(census_return_type = 'geographies') ) #> Passing 2 addresses to the US Census batch geocoder -#> Query completed in: 1.6 seconds +#> Query completed in: 1.2 seconds

street
@@ -341,13 +341,13 @@

----++++-+ @@ -367,15 +367,15 @@

- - - - + + + + - - + + - +
addressSalzburg, Austria 47.79813 13.04648257918086relation8653847.7512115, 47.8543925, 12.9856478, 13.1272842214457node3496431447.6381346, 47.9581346, 12.8864806, 13.2064806 Salzburg, 5020, Österreichboundaryadministrativeplacecity 0.6854709https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.pnghttps://nominatim.openstreetmap.org/ui/mapicons//poi_place_city.p.20.png
@@ -393,7 +393,7 @@

rev1 <- lat_longs1 %>% reverse_geocode(lat = latitude, long = longitude, address = addr, method = "osm") #> Passing 2 coordinates to the Nominatim single coordinate geocoder -#> Query completed in: 2 seconds +#> Query completed in: 2.1 seconds @@ -433,9 +433,9 @@

#> Columns: 22 #> $ lat <dbl> 38.89587, 43.65348 #> $ long <dbl> -77.03077, -79.38393 -#> $ address <chr> "L’Enfant's plan, Pennsylvania Avenue, Washington, Dist… +#> $ address <chr> "L’Enfant's plan, Pennsylvania Avenue, Washington, District of Columbia, 20045, United S… #> $ place_id <int> 301711857, 137497520 -#> $ licence <chr> "Data © OpenStreetMap contributors, ODbL 1.0. https://o… +#> $ licence <chr> "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenSt… #> $ osm_type <chr> "way", "way" #> $ osm_id <int> 899927546, 198500761 #> $ osm_lat <chr> "38.895859599999994", "43.6536032" @@ -447,7 +447,7 @@

#> $ postcode <chr> "20045", "M5H 2N2" #> $ country <chr> "United States", "Canada" #> $ country_code <chr> "us", "ca" -#> $ boundingbox <list> <"38.8957273", "38.8959688", "-77.0311667", "-77.030189… +#> $ boundingbox <list> <"38.8957273", "38.8959688", "-77.0311667", "-77.0301895">, <"43.6529946", "43.6541458",… #> $ amenity <chr> NA, "Toronto City Hall" #> $ house_number <chr> NA, "100" #> $ neighbourhood <chr> NA, "Financial District" @@ -478,7 +478,7 @@

#> limit : "1" #> format : "json" #> HTTP Status Code: 200 -#> Query completed in: 0.4 seconds +#> Query completed in: 0.3 seconds #> Total query time (including sleep): 1 seconds #> #> @@ -583,7 +583,7 @@

) #> #> Passing 3 addresses to the US Census batch geocoder -#> Query completed in: 0.2 seconds +#> Query completed in: 0.1 seconds #> Passing 2 addresses to the Nominatim single address geocoder #> Query completed in: 2 seconds

@@ -693,19 +693,19 @@

glimpse(geo_limit) #> Rows: 6 #> Columns: 13 -#> $ address <chr> "Lima, Peru", "Lima, Peru", "Lima, Peru", "Cairo, Egypt",… -#> $ lat <dbl> -12.06211, -12.20011, -11.99997, 30.03521, 30.04439, 30.0… -#> $ long <dbl> -77.03653, -76.28506, -76.83322, 31.56337, 31.23573, 31.5… -#> $ place_id <int> 258244064, 258655931, 258306819, 258758158, 793757, 29897… -#> $ licence <chr> "Data © OpenStreetMap contributors, ODbL 1.0. https://osm… -#> $ osm_type <chr> "relation", "relation", "relation", "relation", "node", "… +#> $ address <chr> "Lima, Peru", "Lima, Peru", "Lima, Peru", "Cairo, Egypt", "Cairo, Egypt", "Cairo, Egypt" +#> $ lat <dbl> -12.06211, -12.20011, -11.99997, 30.03521, 30.04439, 30.03325 +#> $ long <dbl> -77.03653, -76.28506, -76.83322, 31.56337, 31.23573, 31.56216 +#> $ place_id <int> 258244064, 258655931, 258306819, 258758158, 793757, 298971141 +#> $ licence <chr> "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenStre… +#> $ osm_type <chr> "relation", "relation", "relation", "relation", "node", "relation" #> $ osm_id <int> 1944756, 1944659, 1944670, 5466227, 271613766, 4103336 -#> $ boundingbox <list> <"-12.0797663", "-12.0303496", "-77.0884555", "-77.001777… -#> $ display_name <chr> "Lima, Lima Metropolitana, Lima, Perú", "Lima, Perú", "L… -#> $ class <chr> "boundary", "boundary", "boundary", "place", "place", "bo… -#> $ type <chr> "administrative", "administrative", "administrative", "ci… -#> $ importance <dbl> 0.7830015, 0.6119761, 0.5934835, 0.6960286, 0.6960286, 0.… -#> $ icon <chr> "https://nominatim.openstreetmap.org/ui/mapicons//poi_bou… +#> $ boundingbox <list> <"-12.0797663", "-12.0303496", "-77.0884555", "-77.0017774">, <"-13.3235137", "-10.2741856… +#> $ display_name <chr> "Lima, Lima Metropolitana, Lima, Perú", "Lima, Perú", "Lima, Lima Metropolitana, Lima, Per… +#> $ class <chr> "boundary", "boundary", "boundary", "place", "place", "boundary" +#> $ type <chr> "administrative", "administrative", "administrative", "city", "city", "administrative" +#> $ importance <dbl> 0.7830015, 0.6119761, 0.5934835, 0.6960286, 0.6960286, 0.4835559 +#> $ icon <chr> "https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png", "…

To directly specify specific API parameters for a given method you can use the custom_query parameter. For example, the Nominatim (OSM) geocoder has a ‘polygon_geojson’ argument that can be used to return GeoJSON geometry content. To pass this parameter you can insert it with a named list using the custom_query argument:

 cairo_geo <- geo("Cairo, Egypt",
@@ -735,15 +735,15 @@ 

#> $ lat <dbl> 30.03521 #> $ long <dbl> 31.56337 #> $ place_id <int> 258758158 -#> $ licence <chr> "Data © OpenStreetMap contributors, ODbL 1.0. http… +#> $ licence <chr> "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright" #> $ osm_type <chr> "relation" #> $ osm_id <int> 5466227 -#> $ boundingbox <list> <"29.7483062", "30.3209168", "31.2200331", "31.909… +#> $ boundingbox <list> <"29.7483062", "30.3209168", "31.2200331", "31.9090054"> #> $ display_name <chr> "القاهرة, محافظة القاهرة, مصر" #> $ class <chr> "place" #> $ type <chr> "city" #> $ importance <dbl> 0.6960286 -#> $ icon <chr> "https://nominatim.openstreetmap.org/ui/mapicons//… +#> $ icon <chr> "https://nominatim.openstreetmap.org/ui/mapicons//poi_place_city.p.20.png" #> $ geojson.type <chr> "Polygon" #> $ geojson.coordinates <list> <<array[1 x 119 x 2]>>

To test a query without sending any data to a geocoding service, you can use no_query = TRUE (NA results are returned).

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index c0612128..f979d890 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -5,7 +5,7 @@ articles: developer_notes: developer_notes.html geocoder_services: geocoder_services.html tidygeocoder: tidygeocoder.html -last_built: 2021-10-22T20:20Z +last_built: 2021-10-24T13:36Z urls: reference: https://jessecambon.github.io/tidygeocoder/reference article: https://jessecambon.github.io/tidygeocoder/articles diff --git a/docs/reference/geo.html b/docs/reference/geo.html index e7daee44..ff671cad 100644 --- a/docs/reference/geo.html +++ b/docs/reference/geo.html @@ -468,7 +468,7 @@

Examp
# \donttest{ geo(street = "600 Peachtree Street NE", city = "Atlanta", state = "Georgia", method = "census") -
#> Passing 1 address to the US Census single address geocoder
#> Query completed in: 11 seconds
#> # A tibble: 1 × 5 +
#> Passing 1 address to the US Census single address geocoder
#> Query completed in: 4.4 seconds
#> # A tibble: 1 × 5 #> street city state lat long #> <chr> <chr> <chr> <dbl> <dbl> #> 1 600 Peachtree Street NE Atlanta Georgia 33.8 -84.4
@@ -482,7 +482,7 @@

Examp #> 3 Nairobi, Kenya -1.30 36.8

geo("100 Main St New York, NY", full_results = TRUE, method = "census", api_options = list(census_return_type = 'geographies')) -
#> Passing 1 address to the US Census single address geocoder
#> Query completed in: 2 seconds
#> # A tibble: 1 × 28 +
#> Passing 1 address to the US Census single address geocoder
#> Query completed in: 1.5 seconds
#> # A tibble: 1 × 28 #> address lat long matchedAddress tigerLine.tiger… tigerLine.side #> <chr> <dbl> <dbl> <chr> <chr> <chr> #> 1 100 Main St New York, NY 40.7 -74.0 100 MAIN ST, … 59662602 R diff --git a/docs/reference/geo_combine.html b/docs/reference/geo_combine.html index f99c0922..50a5817e 100644 --- a/docs/reference/geo_combine.html +++ b/docs/reference/geo_combine.html @@ -282,7 +282,7 @@

Examp address = example_addresses, global_params = list(address = 'address') ) -

#>
#>
#> Passing 3 addresses to the US Census batch geocoder
#> Query completed in: 0.4 seconds
#> Passing 2 addresses to the Nominatim single address geocoder
#> Query completed in: 2 seconds
#> # A tibble: 3 × 4 +
#>
#>
#> Passing 3 addresses to the US Census batch geocoder
#> Query completed in: 0.3 seconds
#> Passing 2 addresses to the Nominatim single address geocoder
#> Query completed in: 2 seconds
#> # A tibble: 3 × 4 #> address lat long query #> <chr> <dbl> <dbl> <chr> #> 1 100 Main St New York, NY 40.7 -74.0 "census" @@ -299,7 +299,7 @@

Examp cascade = FALSE, return_list = TRUE ) -

#>
#>
#>
#> Passing 3 addresses to the ArcGIS single address geocoder
#> Query completed in: 0.3 seconds
#> Passing 3 addresses to the US Census single address geocoder
#> Query completed in: 1.4 seconds
#> Passing 3 addresses to the US Census batch geocoder
#> Query completed in: 0.3 seconds
#> $arcgis +
#>
#>
#>
#> Passing 3 addresses to the ArcGIS single address geocoder
#> Query completed in: 1.2 seconds
#> Passing 3 addresses to the US Census single address geocoder
#> Query completed in: 1 seconds
#> Passing 3 addresses to the US Census batch geocoder
#> Query completed in: 0.2 seconds
#> $arcgis #> # A tibble: 3 × 3 #> address lat long #> <chr> <dbl> <dbl> @@ -332,7 +332,7 @@

Examp country = c('Japan', 'United States'), cascade = FALSE ) -

#>
#>
#> Passing 2 addresses to the ArcGIS single address geocoder
#> Query completed in: 1.4 seconds
#> Passing 2 addresses to the Nominatim single address geocoder
#> Query completed in: 2 seconds
#> # A tibble: 4 × 5 +
#>
#>
#> Passing 2 addresses to the ArcGIS single address geocoder
#> Query completed in: 0.2 seconds
#> Passing 2 addresses to the Nominatim single address geocoder
#> Query completed in: 2 seconds
#> # A tibble: 4 × 5 #> city country lat long query #> <chr> <chr> <dbl> <dbl> <chr> #> 1 Tokyo Japan 35.7 140. arcgis diff --git a/docs/reference/geocode.html b/docs/reference/geocode.html index b06a2f64..3ea6c8be 100644 --- a/docs/reference/geocode.html +++ b/docs/reference/geocode.html @@ -302,7 +302,7 @@

Examp library(dplyr, warn.conflicts = FALSE) sample_addresses %>% slice(1:2) %>% geocode(addr, method = 'arcgis') -

#> Passing 2 addresses to the ArcGIS single address geocoder
#> Query completed in: 0.2 seconds
#> # A tibble: 2 × 4 +
#> Passing 2 addresses to the ArcGIS single address geocoder
#> Query completed in: 1.1 seconds
#> # A tibble: 2 × 4 #> name addr lat long #> <chr> <chr> <dbl> <dbl> #> 1 White House 1600 Pennsylvania Ave NW Washington, DC 38.9 -77.0 @@ -310,7 +310,7 @@

Examp louisville %>% head(2) %>% geocode(street = street, city = city, state = state, postalcode = zip, method = 'census', full_results = TRUE) -

#> Passing 2 addresses to the US Census batch geocoder
#> Query completed in: 0.3 seconds
#> # A tibble: 2 × 15 +
#> Passing 2 addresses to the US Census batch geocoder
#> Query completed in: 0.2 seconds
#> # A tibble: 2 × 15 #> street city state zip latitude longitude lat long id input_address #> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <chr> #> 1 2722 ELLIOTT AVE Loui… Kent… 40211 38.3 -85.8 38.3 -85.8 1 2722 ELLIOTT… diff --git a/docs/reference/geocode_combine.html b/docs/reference/geocode_combine.html index a4d3917a..45b296ce 100644 --- a/docs/reference/geocode_combine.html +++ b/docs/reference/geocode_combine.html @@ -269,7 +269,7 @@

Examp geocode_combine( queries = list(list(method = 'census'), list(method = 'osm')), global_params = list(address = 'addr'), cascade = TRUE) -

#>
#>
#> Passing 9 addresses to the US Census batch geocoder
#> Query completed in: 2.1 seconds
#> Passing 5 addresses to the Nominatim single address geocoder
#> Query completed in: 5 seconds
#> # A tibble: 9 × 5 +
#>
#>
#> Passing 9 addresses to the US Census batch geocoder
#> Query completed in: 1.1 seconds
#> Passing 5 addresses to the Nominatim single address geocoder
#> Query completed in: 5 seconds
#> # A tibble: 9 × 5 #> name addr lat long query #> <chr> <chr> <dbl> <dbl> <chr> #> 1 White House 1600 Pennsylvania Ave NW Washington, … 38.9 -77.0 cens… @@ -300,7 +300,7 @@

Examp city = 'city', state = 'state', postalcode = 'zip_cd'), query_names = c('census batch', 'census single', 'osm') ) -

#>
#>
#>
#> Passing 4 addresses to the US Census batch geocoder
#> Query completed in: 0.6 seconds
#> Passing 3 addresses to the US Census single address geocoder
#> Query completed in: 2 seconds
#> Passing 1 address to the Nominatim single address geocoder
#> Query completed in: 1 seconds
#> # A tibble: 4 × 7 +
#>
#>
#>
#> Passing 4 addresses to the US Census batch geocoder
#> Query completed in: 0.3 seconds
#> Passing 3 addresses to the US Census single address geocoder
#> Query completed in: 1.6 seconds
#> Passing 1 address to the Nominatim single address geocoder
#> Query completed in: 1 seconds
#> # A tibble: 4 × 7 #> street_address city state zip_cd lat long query #> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr> #> 1 624 W DAVIS ST #1D BURLINGTON NC 27215 36.1 -79.4 census single @@ -317,7 +317,7 @@

Examp cascade = FALSE, return_list = TRUE ) -

#>
#>
#> Passing 4 addresses to the US Census batch geocoder
#> Query completed in: 0.4 seconds
#> Passing 4 addresses to the ArcGIS single address geocoder
#> Query completed in: 2.3 seconds
#> $census +
#>
#>
#> Passing 4 addresses to the US Census batch geocoder
#> Query completed in: 0.3 seconds
#> Passing 4 addresses to the ArcGIS single address geocoder
#> Query completed in: 1.2 seconds
#> $census #> # A tibble: 4 × 6 #> street_address city state zip_cd lat long #> <chr> <chr> <chr> <dbl> <dbl> <dbl> diff --git a/docs/reference/reverse_geocode.html b/docs/reference/reverse_geocode.html index ccc3b661..254bd3d8 100644 --- a/docs/reference/reverse_geocode.html +++ b/docs/reference/reverse_geocode.html @@ -285,7 +285,7 @@

Examp louisville %>% head(3) %>% reverse_geocode(lat = latitude, long = longitude, method = 'arcgis') -

#> Passing 3 coordinates to the ArcGIS single coordinate geocoder
#> Query completed in: 0.2 seconds
#> # A tibble: 3 × 7 +
#> Passing 3 coordinates to the ArcGIS single coordinate geocoder
#> Query completed in: 2.3 seconds
#> # A tibble: 3 × 7 #> street city state zip latitude longitude address #> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr> #> 1 2722 ELLIOTT AVE Louisville Kentucky 40211 38.3 -85.8 2722 Elliott Av… diff --git a/vignettes/tidygeocoder.Rmd b/vignettes/tidygeocoder.Rmd index cb17da2f..17aed3dc 100644 --- a/vignettes/tidygeocoder.Rmd +++ b/vignettes/tidygeocoder.Rmd @@ -9,54 +9,9 @@ vignette: > \usepackage[utf8]{inputenc} --- -```{r, echo = FALSE, message = FALSE} -knitr::opts_chunk$set(collapse = TRUE, comment = "#>") -options(tibble.print_min = 4L, tibble.print_max = 4L) -set.seed(42) -``` -```{r, echo = FALSE, message = FALSE} -# check to make sure both the US Census and Nominatim endpoints are available -# (ie. we have an internet connection) - -# Check that US Census service is available -tryCatch( - expr = { - tidygeocoder::geo('1600 Pennsylvania Avenue NW, Washington, DC 20500', - method = 'census') - }, - error = function(e) { - stop(paste0('The US Census geocoding API is not available. ', - 'The following error was produced:\n', e), call. = FALSE) - }, - warning = function(w) { - stop(paste0('The US Census geocoding API is not available. ', - 'The following warning was produced:\n', w), call. = FALSE) - }, - finally = { - message('') - }) - -# Check that the Nominatim service is available -tryCatch( - expr = { - tidygeocoder::geo('London', method = 'osm') - tidygeocoder::reverse_geo(lat = 0, long = 0, method = 'osm') - }, - error = function(e) { - stop(paste0('The Nominatim ("osm") geocoding API is not available. ', - 'The following error was produced:\n', e), call. = FALSE) - }, - warning = function(w) { - stop(paste0('The Nominatim ("osm") geocoding API is not available. ', - 'The following warning was produced:\n', w), call. = FALSE) - }, - finally = { - message('') - }) - -#tidygeocoder::geo('London', method = 'osm') -``` + + ## Introduction @@ -67,7 +22,8 @@ The `geocode()` and `geo()` functions are for forward geocoding while the `rever ## Forward Geocoding -```{r setup, warning = FALSE, message = FALSE} + +```r library(tibble) library(dplyr) library(tidygeocoder) @@ -85,49 +41,78 @@ address_components <- tribble( You can use the `address` argument to specify single-line addresses. Note that when multiple addresses are provided, the batch geocoding functionality of the Census geocoding service is used. Additionally, `verbose = TRUE` displays logs to the console. -```{r} + +```r census_s1 <- address_single %>% geocode(address = singlelineaddress, method = "census", verbose = TRUE) +#> +#> Number of Unique Addresses: 2 +#> Executing batch geocoding... +#> Batch limit: 10,000 +#> Passing 2 addresses to the US Census batch geocoder +#> Querying API URL: https://geocoding.geo.census.gov/geocoder/locations/addressbatch +#> Passing the following parameters to the API: +#> format : "json" +#> benchmark : "Public_AR_Current" +#> vintage : "Current_Current" +#> Query completed in: 1.2 seconds ``` -```{r, echo = FALSE} -knitr::kable(census_s1) -``` + +|singlelineaddress | lat| long| +|:-----------------------------------------|--------:|---------:| +|11 Wall St, NY, NY | 40.70747| -74.01122| +|600 Peachtree Street NE, Atlanta, Georgia | 33.77085| -84.38505| Alternatively you can run the same query with the `geo()` function by passing the address values from the dataframe directly. In either `geo()` or `geocode()`, the `lat` and `long` arguments are used to name the resulting latitude and longitude fields. Here the `method` argument is used to specify the "osm" (Nominatim) geocoding service. Refer to the `geo()` function documentation for the possible values of the `method` argument. -```{r} + +```r osm_s1 <- geo( address = address_single$singlelineaddress, method = "osm", lat = latitude, long = longitude ) +#> Passing 2 addresses to the Nominatim single address geocoder +#> Query completed in: 2.1 seconds ``` -```{r, echo = FALSE} -knitr::kable(osm_s1) -``` + +|address | latitude| longitude| +|:-----------------------------------------|--------:|---------:| +|11 Wall St, NY, NY | 40.90805| -73.01708| +|600 Peachtree Street NE, Atlanta, Georgia | 33.77086| -84.38614| Instead of single-line addresses, you can use any combination of the following arguments to specify your addresses: `street`, `city`, `state`, `county`, `postalcode`, and `country`. -```{r} + +```r census_c1 <- address_components %>% geocode(street = street, city = cty, state = st, method = "census") +#> Passing 2 addresses to the US Census batch geocoder +#> Query completed in: 1.8 seconds ``` -```{r, echo = FALSE} -knitr::kable(census_c1) -``` + +|street |cty |st | lat| long| +|:-----------------------|:-------|:--|--------:|---------:| +|11 Wall St |NY |NY | 40.70747| -74.01122| +|600 Peachtree Street NE |Atlanta |GA | 33.77085| -84.38505| To return the full geocoding service results (not just latitude and longitude), specify `full_results = TRUE`. Additionally, for the Census geocoder you can get fields for geographies such as Census tracts by specifying `api_options = list(census_return_type = 'geographies')`. Be sure to use `full_results = TRUE` with the "geographies" return type in order to allow the Census geography columns to be returned. -```{r} + +```r census_full1 <- address_single %>% geocode( address = singlelineaddress, method = "census", full_results = TRUE, api_options = list(census_return_type = 'geographies') ) +#> Passing 2 addresses to the US Census batch geocoder +#> Query completed in: 1.2 seconds ``` -```{r, echo = FALSE} -knitr::kable(census_full1) -``` + +|singlelineaddress | lat| long| id|input_address |match_indicator |match_type |matched_address |tiger_line_id |tiger_side |state_fips |county_fips |census_tract |census_block | +|:-----------------------------------------|--------:|---------:|--:|:----------------------------------------------|:---------------|:----------|:------------------------------------|:-------------|:----------|:----------|:-----------|:------------|:------------| +|11 Wall St, NY, NY | 40.70747| -74.01122| 1|11 Wall St, NY, NY, , , |Match |Exact |11 WALL ST, NEW YORK, NY, 10005 |59659656 |R |36 |061 |000700 |1004 | +|600 Peachtree Street NE, Atlanta, Georgia | 33.77085| -84.38505| 2|600 Peachtree Street NE, Atlanta, Georgia, , , |Match |Non_Exact |600 PEACHTREE ST, ATLANTA, GA, 30308 |17343689 |L |13 |121 |001902 |2003 | As mentioned earlier, the `geocode()` function passes addresses in dataframes to the `geo()` function for geocoding so we can also directly use the `geo()` function in a similar way: @@ -135,14 +120,18 @@ As mentioned earlier, the `geocode()` function passes addresses in dataframes to Removing the licence column is done just to prevent a note from occurring in automated CRAN checks for an improper/old link. --> -```{r} + +```r salz <- geo("Salzburg, Austria", method = "osm", full_results = TRUE) %>% select(-licence) +#> Passing 1 address to the Nominatim single address geocoder +#> Query completed in: 1 seconds ``` -```{r, echo = FALSE} -knitr::kable(salz) -``` + +|address | lat| long| place_id|osm_type | osm_id|boundingbox |display_name |class |type | importance|icon | +|:-----------------|--------:|--------:|--------:|:--------|--------:|:----------------------------------------------|:--------------------------|:-----|:----|----------:|:------------------------------------------------------------------------| +|Salzburg, Austria | 47.79813| 13.04648| 214457|node | 34964314|47.6381346, 47.9581346, 12.8864806, 13.2064806 |Salzburg, 5020, Österreich |place |city | 0.6854709|https://nominatim.openstreetmap.org/ui/mapicons//poi_place_city.p.20.png | ## Reverse Geocoding @@ -150,7 +139,8 @@ For reverse geocoding you'll use `reverse_geocode()` instead of `geocode()` and Below, the `reverse_geocode()` function is used to geocode coordinates in a dataframe. The `lat` and `long` arguments specify the columns that contain the latitude and longitude data. The `address` argument can be used to specify the single line address column name that is returned from the geocoder. Just as with forward geocoding, the `method` argument is used to specify the geocoding service. -```{r} + +```r lat_longs1 <- tibble( latitude = c(38.895865, 43.6534817), longitude = c(-77.0307713, -79.3839347) @@ -158,23 +148,53 @@ lat_longs1 <- tibble( rev1 <- lat_longs1 %>% reverse_geocode(lat = latitude, long = longitude, address = addr, method = "osm") +#> Passing 2 coordinates to the Nominatim single coordinate geocoder +#> Query completed in: 2.1 seconds ``` -```{r, echo = FALSE} -knitr::kable(rev1) -``` + +| latitude| longitude|addr | +|--------:|---------:|:--------------------------------------------------------------------------------------------------------------------------------------------------| +| 38.89587| -77.03077|L’Enfant's plan, Pennsylvania Avenue, Washington, District of Columbia, 20045, United States | +| 43.65348| -79.38393|Toronto City Hall, 100, Queen Street West, Financial District, Spadina—Fort York, Old Toronto, Toronto, Golden Horseshoe, Ontario, M5H 2N2, Canada | The same query can also be performed by passing the latitude and longitudes directly to the `reverse_geo()` function. Here we will use `full_results = TRUE` so that the full results are returned (not just the single line address column). -```{r} + +```r rev2 <- reverse_geo( lat = lat_longs1$latitude, long = lat_longs1$longitude, method = "osm", full_results = TRUE ) - +#> Passing 2 coordinates to the Nominatim single coordinate geocoder +#> Query completed in: 2 seconds glimpse(rev2) +#> Rows: 2 +#> Columns: 22 +#> $ lat 38.89587, 43.65348 +#> $ long -77.03077, -79.38393 +#> $ address "L’Enfant's plan, Pennsylvania Avenue, Washington, District of Columbia, 20045, United S… +#> $ place_id 301711857, 137497520 +#> $ licence "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenSt… +#> $ osm_type "way", "way" +#> $ osm_id 899927546, 198500761 +#> $ osm_lat "38.895859599999994", "43.6536032" +#> $ osm_lon "-77.0306779870984", "-79.38400546703345" +#> $ tourism "L’Enfant's plan", NA +#> $ road "Pennsylvania Avenue", "Queen Street West" +#> $ city "Washington", "Old Toronto" +#> $ state "District of Columbia", "Ontario" +#> $ postcode "20045", "M5H 2N2" +#> $ country "United States", "Canada" +#> $ country_code "us", "ca" +#> $ boundingbox <"38.8957273", "38.8959688", "-77.0311667", "-77.0301895">, <"43.6529946", "43.6541458",… +#> $ amenity NA, "Toronto City Hall" +#> $ house_number NA, "100" +#> $ neighbourhood NA, "Financial District" +#> $ quarter NA, "Spadina—Fort York" +#> $ state_district NA, "Golden Horseshoe" ``` ## Working With Messy Data @@ -183,7 +203,8 @@ Only unique input data (either addresses or coordinates) is passed to geocoding Below is an example of how duplicate and missing data is handled by tidygeocoder. As the console messages shows, only the two unique addresses are passed to the geocoding service. -```{r} + +```r # create a dataset with duplicate and NA addresses duplicate_addrs <- address_single %>% bind_rows(address_single) %>% @@ -191,21 +212,59 @@ duplicate_addrs <- address_single %>% duplicates_geocoded <- duplicate_addrs %>% geocode(singlelineaddress, verbose = TRUE) +#> +#> Number of Unique Addresses: 2 +#> Passing 2 addresses to the Nominatim single address geocoder +#> +#> Number of Unique Addresses: 1 +#> Querying API URL: https://nominatim.openstreetmap.org/search +#> Passing the following parameters to the API: +#> q : "11 Wall St, NY, NY" +#> limit : "1" +#> format : "json" +#> HTTP Status Code: 200 +#> Query completed in: 0.3 seconds +#> Total query time (including sleep): 1 seconds +#> +#> +#> Number of Unique Addresses: 1 +#> Querying API URL: https://nominatim.openstreetmap.org/search +#> Passing the following parameters to the API: +#> q : "600 Peachtree Street NE, Atlanta, Georgia" +#> limit : "1" +#> format : "json" +#> HTTP Status Code: 200 +#> Query completed in: 0.2 seconds +#> Total query time (including sleep): 1 seconds +#> +#> Query completed in: 2 seconds ``` -```{r, echo = FALSE} -knitr::kable(duplicates_geocoded) -``` + +|singlelineaddress | lat| long| +|:-----------------------------------------|--------:|---------:| +|11 Wall St, NY, NY | 40.90805| -73.01708| +|600 Peachtree Street NE, Atlanta, Georgia | 33.77086| -84.38614| +|11 Wall St, NY, NY | 40.90805| -73.01708| +|600 Peachtree Street NE, Atlanta, Georgia | 33.77086| -84.38614| +|NA | NA| NA| +|NA | NA| NA| +|NA | NA| NA| As shown above, duplicates will not be removed from your results by default. However, you can return only unique results by using `unique_only = TRUE`. Note that passing `unique_only = TRUE` to `geocode()` or `reverse_geocode()` will result in the original dataframe format (including column names) to be discarded in favor of the standard field names (ie. "address", 'lat, 'long', etc.). -```{r} + +```r uniqueonly1 <- duplicate_addrs %>% geocode(singlelineaddress, unique_only = TRUE) +#> Passing 2 addresses to the Nominatim single address geocoder +#> Query completed in: 2 seconds ``` -```{r, echo = FALSE} -knitr::kable(uniqueonly1) -``` + +|address | lat| long| +|:-----------------------------------------|--------:|---------:| +|11 Wall St, NY, NY | 40.90805| -73.01708| +|600 Peachtree Street NE, Atlanta, Georgia | 33.77086| -84.38614| ## Combining Multiple Queries @@ -214,7 +273,8 @@ The `geocode_combine()` function allows you to execute and combine the results o In the first example below, the US Census service is used for the first query while the Nominatim ("osm") service is used for the second query. The `global_params` argument passes the `address` column from the input dataset to both queries. -```{r} + +```r addresses_combine <- tibble( address = c('100 Wall Street NY, NY', 'Paris', 'Not An Address') ) @@ -227,15 +287,24 @@ cascade_results1 <- addresses_combine %>% ), global_params = list(address = 'address') ) +#> +#> Passing 3 addresses to the US Census batch geocoder +#> Query completed in: 0.1 seconds +#> Passing 2 addresses to the Nominatim single address geocoder +#> Query completed in: 2 seconds ``` -```{r, echo = FALSE} -knitr::kable(cascade_results1) -``` + +|address | lat| long|query | +|:----------------------|--------:|----------:|:------| +|100 Wall Street NY, NY | 40.70516| -74.007350|census | +|Paris | 48.85670| 2.351462|osm | +|Not An Address | NA| NA| | If `cascade` is set to FALSE then all addresses are attempted by each query regardless of if the address was found initially or not. -```{r} + +```r no_cascade_results1 <- addresses_combine %>% geocode_combine( queries = list( @@ -245,11 +314,22 @@ no_cascade_results1 <- addresses_combine %>% global_params = list(address = 'address'), cascade = FALSE ) +#> +#> Passing 3 addresses to the US Census batch geocoder +#> Query completed in: 0.1 seconds +#> Passing 3 addresses to the Nominatim single address geocoder +#> Query completed in: 3 seconds ``` -```{r, echo = FALSE} -knitr::kable(no_cascade_results1) -``` + +|address | lat| long|query | +|:----------------------|--------:|----------:|:------| +|100 Wall Street NY, NY | 40.70516| -74.007350|census | +|100 Wall Street NY, NY | 40.70522| -74.006800|osm | +|Paris | NA| NA|census | +|Paris | 48.85670| 2.351462|osm | +|Not An Address | NA| NA|census | +|Not An Address | NA| NA|osm | Additionally, the results from each query can be returned in separate list items by setting `return_list = TRUE`. @@ -257,38 +337,109 @@ Additionally, the results from each query can be returned in separate list items The `limit` argument can be specified to allow multiple results (rows) per input if available. The maximum value for the `limit` argument is often 100 for geocoding services. To use the default `limit` value for the selected geocoding service you can use `limit = NULL` which will prevent the limit parameter from being included in the query. -```{r} + +```r geo_limit <- geo( c("Lima, Peru", "Cairo, Egypt"), method = "osm", limit = 3, full_results = TRUE ) - +#> Passing 2 addresses to the Nominatim single address geocoder +#> Query completed in: 2 seconds glimpse(geo_limit) +#> Rows: 6 +#> Columns: 13 +#> $ address "Lima, Peru", "Lima, Peru", "Lima, Peru", "Cairo, Egypt", "Cairo, Egypt", "Cairo, Egypt" +#> $ lat -12.06211, -12.20011, -11.99997, 30.03521, 30.04439, 30.03325 +#> $ long -77.03653, -76.28506, -76.83322, 31.56337, 31.23573, 31.56216 +#> $ place_id 258244064, 258655931, 258306819, 258758158, 793757, 298971141 +#> $ licence "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenStre… +#> $ osm_type "relation", "relation", "relation", "relation", "node", "relation" +#> $ osm_id 1944756, 1944659, 1944670, 5466227, 271613766, 4103336 +#> $ boundingbox <"-12.0797663", "-12.0303496", "-77.0884555", "-77.0017774">, <"-13.3235137", "-10.2741856… +#> $ display_name "Lima, Lima Metropolitana, Lima, Perú", "Lima, Perú", "Lima, Lima Metropolitana, Lima, Per… +#> $ class "boundary", "boundary", "boundary", "place", "place", "boundary" +#> $ type "administrative", "administrative", "administrative", "city", "city", "administrative" +#> $ importance 0.7830015, 0.6119761, 0.5934835, 0.6960286, 0.6960286, 0.4835559 +#> $ icon "https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png", "… ``` To directly specify specific API parameters for a given `method` you can use the `custom_query` parameter. For example, [the Nominatim (OSM) geocoder has a 'polygon_geojson' argument](https://nominatim.org/release-docs/develop/api/Details/#parameters) that can be used to return GeoJSON geometry content. To pass this parameter you can insert it with a named list using the `custom_query` argument: -```{r} + +```r cairo_geo <- geo("Cairo, Egypt", method = "osm", full_results = TRUE, custom_query = list(polygon_geojson = 1), verbose = TRUE ) - +#> +#> Number of Unique Addresses: 1 +#> Passing 1 address to the Nominatim single address geocoder +#> +#> Number of Unique Addresses: 1 +#> Querying API URL: https://nominatim.openstreetmap.org/search +#> Passing the following parameters to the API: +#> q : "Cairo, Egypt" +#> limit : "1" +#> polygon_geojson : "1" +#> format : "json" +#> HTTP Status Code: 200 +#> Query completed in: 0.2 seconds +#> Total query time (including sleep): 1 seconds +#> +#> Query completed in: 1 seconds glimpse(cairo_geo) +#> Rows: 1 +#> Columns: 15 +#> $ address "Cairo, Egypt" +#> $ lat 30.03521 +#> $ long 31.56337 +#> $ place_id 258758158 +#> $ licence "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright" +#> $ osm_type "relation" +#> $ osm_id 5466227 +#> $ boundingbox <"29.7483062", "30.3209168", "31.2200331", "31.9090054"> +#> $ display_name "القاهرة, محافظة القاهرة, مصر" +#> $ class "place" +#> $ type "city" +#> $ importance 0.6960286 +#> $ icon "https://nominatim.openstreetmap.org/ui/mapicons//poi_place_city.p.20.png" +#> $ geojson.type "Polygon" +#> $ geojson.coordinates <> ``` To test a query without sending any data to a geocoding service, you can use `no_query = TRUE` (NA results are returned). -```{r} + +```r noquery1 <- geo(c("Vancouver, Canada", "Las Vegas, NV"), no_query = TRUE, method = "arcgis" ) +#> +#> Number of Unique Addresses: 2 +#> Passing 2 addresses to the ArcGIS single address geocoder +#> +#> Number of Unique Addresses: 1 +#> Querying API URL: https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates +#> Passing the following parameters to the API: +#> SingleLine : "Vancouver, Canada" +#> maxLocations : "1" +#> f : "json" +#> +#> Number of Unique Addresses: 1 +#> Querying API URL: https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates +#> Passing the following parameters to the API: +#> SingleLine : "Las Vegas, NV" +#> maxLocations : "1" +#> f : "json" +#> Query completed in: 0 seconds ``` -```{r, echo = FALSE} -knitr::kable(noquery1) -``` + +|address | lat| long| +|:-----------------|---:|----:| +|Vancouver, Canada | NA| NA| +|Las Vegas, NV | NA| NA| Additional usage notes for the `geocode()`, `geo()`, `reverse_geocode()`, and `reverse_geo()` functions: diff --git a/vignettes/tidygeocoder.Rmd.orig b/vignettes/tidygeocoder.Rmd.orig new file mode 100644 index 00000000..9599866c --- /dev/null +++ b/vignettes/tidygeocoder.Rmd.orig @@ -0,0 +1,306 @@ +--- +title: "Getting Started" +output: rmarkdown::html_vignette +description: > + Start here if this is your first time using tidygeocder. +vignette: > + %\VignetteIndexEntry{Getting Started} + %\VignetteEngine{knitr::rmarkdown} + \usepackage[utf8]{inputenc} +--- + +```{r, echo = FALSE, message = FALSE} +# INSTRUCTIONS: execute this vignette with this command: +# knitr::knit("vignettes/tidygeocoder.Rmd.orig", output = "vignettes/tidygeocoder.Rmd") +# +# See these instructions for more detail: +# https://ropensci.org/blog/2019/12/08/precompute-vignettes/ + +knitr::opts_chunk$set(collapse = TRUE, comment = "#>") +options(tibble.print_min = 4L, tibble.print_max = 4L) +set.seed(42) +``` + +```{r, echo = FALSE, message = FALSE, eval = FALSE} +# check to make sure both the US Census and Nominatim endpoints are available +# (ie. we have an internet connection) +# These checks are no longer necessary as this vignette is executed locally + +# Check that US Census service is available +tryCatch( + expr = { + tidygeocoder::geo('1600 Pennsylvania Avenue NW, Washington, DC 20500', + method = 'census') + }, + error = function(e) { + stop(paste0('The US Census geocoding API is not available. ', + 'The following error was produced:\n', e), call. = FALSE) + }, + warning = function(w) { + stop(paste0('The US Census geocoding API is not available. ', + 'The following warning was produced:\n', w), call. = FALSE) + }, + finally = { + message('') + }) + +# Check that the Nominatim service is available +tryCatch( + expr = { + tidygeocoder::geo('London', method = 'osm') + tidygeocoder::reverse_geo(lat = 0, long = 0, method = 'osm') + }, + error = function(e) { + stop(paste0('The Nominatim ("osm") geocoding API is not available. ', + 'The following error was produced:\n', e), call. = FALSE) + }, + warning = function(w) { + stop(paste0('The Nominatim ("osm") geocoding API is not available. ', + 'The following warning was produced:\n', w), call. = FALSE) + }, + finally = { + message('') + }) +``` + +## Introduction + +Tidygeocoder provides a unified interface for performing both forward and reverse geocoding queries with a variety of geocoding services. In forward geocoding you provide an address to the geocoding service and you get latitude and longitude coordinates in return. In reverse geocoding you provide the latitude and longitude and the geocoding service will return that location's address. In both cases, other data about the location can be provided by the geocoding service. + +The `geocode()` and `geo()` functions are for forward geocoding while the `reverse_geocode()` and `reverse_geo()` functions perform reverse geocoding. The `geocode()` and `reverse_geocode()` functions extract either addresses (forward geocoding) or coordinates (reverse geocoding) from the input dataframe and pass this data to the `geo()` and `reverse_geo()` functions respectively which execute the geocoding queries. All extra arguments (`...`) given to `geocode()` are passed to `geo()` and extra arguments given to `reverse_geocode()` are passed to `reverse_geo()`. + +## Forward Geocoding + +```{r setup, warning = FALSE, message = FALSE} +library(tibble) +library(dplyr) +library(tidygeocoder) + +address_single <- tibble(singlelineaddress = c( + "11 Wall St, NY, NY", + "600 Peachtree Street NE, Atlanta, Georgia" +)) +address_components <- tribble( + ~street, ~cty, ~st, + "11 Wall St", "NY", "NY", + "600 Peachtree Street NE", "Atlanta", "GA" +) +``` + +You can use the `address` argument to specify single-line addresses. Note that when multiple addresses are provided, the batch geocoding functionality of the Census geocoding service is used. Additionally, `verbose = TRUE` displays logs to the console. + +```{r} +census_s1 <- address_single %>% + geocode(address = singlelineaddress, method = "census", verbose = TRUE) +``` + +```{r, echo = FALSE} +knitr::kable(census_s1) +``` + +Alternatively you can run the same query with the `geo()` function by passing the address values from the dataframe directly. In either `geo()` or `geocode()`, the `lat` and `long` arguments are used to name the resulting latitude and longitude fields. Here the `method` argument is used to specify the "osm" (Nominatim) geocoding service. Refer to the `geo()` function documentation for the possible values of the `method` argument. + +```{r} +osm_s1 <- geo( + address = address_single$singlelineaddress, method = "osm", + lat = latitude, long = longitude +) +``` +```{r, echo = FALSE} +knitr::kable(osm_s1) +``` + +Instead of single-line addresses, you can use any combination of the following arguments to specify your addresses: `street`, `city`, `state`, `county`, `postalcode`, and `country`. + +```{r} +census_c1 <- address_components %>% + geocode(street = street, city = cty, state = st, method = "census") +``` +```{r, echo = FALSE} +knitr::kable(census_c1) +``` + +To return the full geocoding service results (not just latitude and longitude), specify `full_results = TRUE`. Additionally, for the Census geocoder you can get fields for geographies such as Census tracts by specifying `api_options = list(census_return_type = 'geographies')`. Be sure to use `full_results = TRUE` with the "geographies" return type in order to allow the Census geography columns to be returned. + +```{r} +census_full1 <- address_single %>% geocode( + address = singlelineaddress, + method = "census", full_results = TRUE, api_options = list(census_return_type = 'geographies') +) +``` + +```{r, echo = FALSE} +knitr::kable(census_full1) +``` + +As mentioned earlier, the `geocode()` function passes addresses in dataframes to the `geo()` function for geocoding so we can also directly use the `geo()` function in a similar way: + + +```{r} +salz <- geo("Salzburg, Austria", method = "osm", full_results = TRUE) %>% + select(-licence) +``` + +```{r, echo = FALSE} +knitr::kable(salz) +``` + +## Reverse Geocoding + +For reverse geocoding you'll use `reverse_geocode()` instead of `geocode()` and `reverse_geo()` instead of `geo()`. Note that the reverse geocoding functions are structured very similarly to the forward geocoding functions and share many of the same arguments (`method`, `limit`, `full_results`, etc.). For reverse geocoding you will provide latitude and longitude coordinates as inputs and the location's address will be returned by the geocoding service. + +Below, the `reverse_geocode()` function is used to geocode coordinates in a dataframe. The `lat` and `long` arguments specify the columns that contain the latitude and longitude data. The `address` argument can be used to specify the single line address column name that is returned from the geocoder. Just as with forward geocoding, the `method` argument is used to specify the geocoding service. + +```{r} +lat_longs1 <- tibble( + latitude = c(38.895865, 43.6534817), + longitude = c(-77.0307713, -79.3839347) +) + +rev1 <- lat_longs1 %>% + reverse_geocode(lat = latitude, long = longitude, address = addr, method = "osm") +``` + +```{r, echo = FALSE} +knitr::kable(rev1) +``` + +The same query can also be performed by passing the latitude and longitudes directly to the `reverse_geo()` function. Here we will use `full_results = TRUE` so that the full results are returned (not just the single line address column). + +```{r} +rev2 <- reverse_geo( + lat = lat_longs1$latitude, + long = lat_longs1$longitude, + method = "osm", + full_results = TRUE +) + +glimpse(rev2) +``` + +## Working With Messy Data + +Only unique input data (either addresses or coordinates) is passed to geocoding services even if your data contains duplicates. NA and blank inputs are excluded from queries. Input latitudes and longitudes are also limited to the range of possible values. + +Below is an example of how duplicate and missing data is handled by tidygeocoder. As the console messages shows, only the two unique addresses are passed to the geocoding service. + +```{r} +# create a dataset with duplicate and NA addresses +duplicate_addrs <- address_single %>% + bind_rows(address_single) %>% + bind_rows(tibble(singlelineaddress = rep(NA, 3))) + +duplicates_geocoded <- duplicate_addrs %>% + geocode(singlelineaddress, verbose = TRUE) +``` + +```{r, echo = FALSE} +knitr::kable(duplicates_geocoded) +``` + +As shown above, duplicates will not be removed from your results by default. However, you can return only unique results by using `unique_only = TRUE`. Note that passing `unique_only = TRUE` to `geocode()` or `reverse_geocode()` will result in the original dataframe format (including column names) to be discarded in favor of the standard field names (ie. "address", 'lat, 'long', etc.). + +```{r} +uniqueonly1 <- duplicate_addrs %>% + geocode(singlelineaddress, unique_only = TRUE) +``` +```{r, echo = FALSE} +knitr::kable(uniqueonly1) +``` + + +## Combining Multiple Queries + +The `geocode_combine()` function allows you to execute and combine the results of multiple geocoding queries. The queries are specified as a list of lists with the `queries` parameter and are executed in the order provided. By default only addresses that are not found are passed to the next query, but this behavior can be toggled with the `cascade` argument. + +In the first example below, the US Census service is used for the first query while the Nominatim ("osm") service is used for the second query. The `global_params` argument passes the `address` column from the input dataset to both queries. + +```{r} +addresses_combine <- tibble( + address = c('100 Wall Street NY, NY', 'Paris', 'Not An Address') +) + +cascade_results1 <- addresses_combine %>% + geocode_combine( + queries = list( + list(method = 'census'), + list(method = 'osm') + ), + global_params = list(address = 'address') + ) +``` + +```{r, echo = FALSE} +knitr::kable(cascade_results1) +``` + +If `cascade` is set to FALSE then all addresses are attempted by each query regardless of if the address was found initially or not. + +```{r} +no_cascade_results1 <- addresses_combine %>% + geocode_combine( + queries = list( + list(method = 'census'), + list(method = 'osm') + ), + global_params = list(address = 'address'), + cascade = FALSE + ) +``` + +```{r, echo = FALSE} +knitr::kable(no_cascade_results1) +``` + +Additionally, the results from each query can be returned in separate list items by setting `return_list = TRUE`. + +## Customizing Queries + +The `limit` argument can be specified to allow multiple results (rows) per input if available. The maximum value for the `limit` argument is often 100 for geocoding services. To use the default `limit` value for the selected geocoding service you can use `limit = NULL` which will prevent the limit parameter from being included in the query. + +```{r} +geo_limit <- geo( + c("Lima, Peru", "Cairo, Egypt"), + method = "osm", + limit = 3, full_results = TRUE +) + +glimpse(geo_limit) +``` + +To directly specify specific API parameters for a given `method` you can use the `custom_query` parameter. For example, [the Nominatim (OSM) geocoder has a 'polygon_geojson' argument](https://nominatim.org/release-docs/develop/api/Details/#parameters) that can be used to return GeoJSON geometry content. To pass this parameter you can insert it with a named list using the `custom_query` argument: + +```{r} +cairo_geo <- geo("Cairo, Egypt", + method = "osm", full_results = TRUE, + custom_query = list(polygon_geojson = 1), verbose = TRUE +) + +glimpse(cairo_geo) +``` + +To test a query without sending any data to a geocoding service, you can use `no_query = TRUE` (NA results are returned). + +```{r} +noquery1 <- geo(c("Vancouver, Canada", "Las Vegas, NV"), + no_query = TRUE, + method = "arcgis" +) +``` +```{r, echo = FALSE} +knitr::kable(noquery1) +``` + +Additional usage notes for the `geocode()`, `geo()`, `reverse_geocode()`, and `reverse_geo()` functions: + +- Set `quiet = TRUE` to silence console logs displayed by default (how many inputs were submitted, to what geocoding service, and the elapsed time). +- Use the `progress_bar` argument to control if a progress bar is displayed. +- The `verbose`, `quiet`, and `progress_bar` arguments can be set globally with `options`. For instance `options(tidygeocoder.verbose = TRUE)` will set verbose to `TRUE` for all queries by default. +- To customize the API endpoint, use the `api_options` or `api_url` arguments. See `?geo` or `?reverse_geo` for details. +- If not specified manually, the `min_time` argument will default to a value based on the maximum query rate of the given geocoding service. If you are using a local Nominatim server or have a commercial geocoder plan that has less restrictive usage limits then you can manually set `min_time` to a lower value (such as 0). +- The `mode` argument can be used to specify whether the batch geocoding or single address/coordinate geocoding should be used. By default batch geocoding will be used if available when more than one address or coordinate is provided (with some noted exceptions for slower batch geocoding services). +- The `return_addresses` and `return_coords` parameters (for forward and reverse geocoding respectively) can be used to toggle whether the input addresses or coordinates are returned. Setting these parameters to `FALSE` is necessary to use batch geocoding if `limit` is greater than 1 or NULL. +- For the `reverse_geocode()` and `geocode()` functions, the `return_input` argument can be used to toggle if the input dataset is included in the returned dataframe. From 8852b415056e3f2f44392cd646bb1e5d91d74975 Mon Sep 17 00:00:00 2001 From: Jesse Cambon Date: Sun, 24 Oct 2021 15:00:15 -0400 Subject: [PATCH 3/3] add vignette precomute fix to news and other tweaks --- NEWS.md | 2 ++ R/geo.R | 10 +++++----- docs/articles/developer_notes.html | 16 +++++++++++----- docs/articles/tidygeocoder.html | 26 +++++++++++++------------- docs/news/index.html | 1 + docs/pkgdown.yml | 2 +- docs/reference/geo.html | 14 +++++++------- docs/reference/geo_combine.html | 6 +++--- docs/reference/geocode.html | 2 +- docs/reference/geocode_combine.html | 6 +++--- docs/reference/reverse_geo.html | 10 +++++----- docs/reference/reverse_geocode.html | 2 +- man/geo.Rd | 10 +++++----- man/reverse_geo.Rd | 10 +++++----- vignettes/developer_notes.Rmd | 15 +++++++++------ vignettes/tidygeocoder.Rmd | 27 +++++++++++++-------------- vignettes/tidygeocoder.Rmd.orig | 17 ++++++++++------- 17 files changed, 95 insertions(+), 81 deletions(-) diff --git a/NEWS.md b/NEWS.md index 798aca8d..e16b9721 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # tidygeocoder (development version) - Corrected documentation for `quiet` parameter in `geo()` and `reverse_geo()` +- Reconfigured the vignette so that it is precomputed and is not executed during +`R CMD check` (ie. `devtools::check()`). Also added a check at the beginning of the vignette to check for the availability of APIs. This fixes an issue that occurred on Mac CRAN checks ([#152](https://github.com/jessecambon/tidygeocoder/issues/152)). # tidygeocoder 1.0.4 diff --git a/R/geo.R b/R/geo.R index c84c671f..1dc1eb1b 100644 --- a/R/geo.R +++ b/R/geo.R @@ -71,19 +71,19 @@ progress_geo <- function(pb = NULL, ...) { #' #' @param min_time minimum amount of time for a query to take (in seconds). If NULL #' then min_time will be set to the default value specified in [min_time_reference]. -#' @param progress_bar if TRUE then a progress bar will be displayed to track query -#' progress for single input geocoding (1 input per query). By default the progress bar +#' @param progress_bar if TRUE then a progress bar will be displayed +#' for single input geocoding (1 input per query). By default the progress bar #' will not be shown for code executed when knitting R Markdown files or code within #' an RStudio notebook chunk. Can be set permanently with `options(tidygeocoder.progress_bar = FALSE)`. #' @param quiet if TRUE then console messages that are displayed by default -#' regarding queries will be suppressed. Can be set permanently with `options(tidygeocoder.quiet = TRUE)`. +#' regarding queries will be suppressed. FALSE is default. +#' Can be set permanently with `options(tidygeocoder.quiet = TRUE)`. #' @param api_url custom API URL. If specified, the default API URL will be overridden. #' This parameter can be used to specify a local Nominatim server, for instance. #' @param timeout query timeout (in minutes) #' #' @param flatten if TRUE (default) then any nested dataframes in results are flattened if possible. -#' Note that in some cases results are flattened regardless such as for -#' Geocodio batch geocoding. +#' Note that in some cases results are flattened regardless such as for Geocodio batch geocoding. #' @param batch_limit `r get_batch_limit_documentation(reverse = FALSE)` #' @param batch_limit_error `r lifecycle::badge("deprecated")` `r get_batch_limit_error_documentation(reverse = FALSE)` #' @param verbose if TRUE then detailed logs are output to the console. FALSE is default. Can be set diff --git a/docs/articles/developer_notes.html b/docs/articles/developer_notes.html index 362484ec..fadad31a 100644 --- a/docs/articles/developer_notes.html +++ b/docs/articles/developer_notes.html @@ -162,7 +162,7 @@

#> limit : "1" #> format : "json" #> HTTP Status Code: 200 -#> Query completed in: 0.3 seconds +#> Query completed in: 0.4 seconds #> Total query time (including sleep): 1 seconds #> #> @@ -302,7 +302,13 @@

  • external/create_logo.Rmd
      -
    • Create the package logo.
    • +
    • Creates the package logo.
    • +
    +
  • +
  • +vignettes/tidygeocoder.Rmd.orig +
      +
    • This file produces the vignette. See the knit command and comments at the top of this file.
  • @@ -311,9 +317,9 @@

    Testing

      -
    • Test out the new service with verbose = TRUE to make sure it behaves as expected. You can reference tests available the ‘sandbox’ folder for reference.
    • -
    • Run devtools::check() to make sure the package still passes all tests and the vignette runs properly. To only run the package tests use devtools::test(), but note these tests do not query the geocoding services to avoid external dependencies.
    • -
    • Run external/online_tests.R to test making queries to the geocoding services. These tests are not included in the internal package tests (devtools::test()) because they require API keys which would not exist on all systems and are dependent on the geocoding services being online at that the time of the test.
    • +
    • Test out the new service to make sure it behaves as expected. You can reference tests and example code in the ‘sandbox’ folder.
    • +
    • Run devtools::check() to make sure the package still passes all tests and checks. To only run the package tests use devtools::test(), but note these tests do not query the geocoding services to avoid external dependencies.
    • +
    • As a final check, run external/online_tests.R to test making queries to the geocoding services. These tests are not included in the internal package tests (devtools::test()) because they require API keys which would not exist on all systems and are dependent on the geocoding services being online at that the time of the test.
    • Run the commands detailed in cran-comments.md to test the package on other environments. Note that these tests should also be included in the automated GitHub actions tests for pull requests.
    • When prepping for a release, use urlchecker::url_check() to check all package URLs.
    diff --git a/docs/articles/tidygeocoder.html b/docs/articles/tidygeocoder.html index 8f313696..1082a64c 100644 --- a/docs/articles/tidygeocoder.html +++ b/docs/articles/tidygeocoder.html @@ -197,7 +197,7 @@

    lat = latitude, long = longitude ) #> Passing 2 addresses to the Nominatim single address geocoder -#> Query completed in: 2.1 seconds

    +#> Query completed in: 2 seconds

    @@ -222,7 +222,7 @@

    census_c1 <- address_components %>% geocode(street = street, city = cty, state = st, method = "census") #> Passing 2 addresses to the US Census batch geocoder -#> Query completed in: 1.8 seconds +#> Query completed in: 1.4 seconds

    address
    @@ -255,7 +255,7 @@

    method = "census", full_results = TRUE, api_options = list(census_return_type = 'geographies') ) #> Passing 2 addresses to the US Census batch geocoder -#> Query completed in: 1.2 seconds +#> Query completed in: 1.5 seconds

    street
    @@ -393,7 +393,7 @@

    rev1 <- lat_longs1 %>% reverse_geocode(lat = latitude, long = longitude, address = addr, method = "osm") #> Passing 2 coordinates to the Nominatim single coordinate geocoder -#> Query completed in: 2.1 seconds +#> Query completed in: 2 seconds

    @@ -433,9 +433,9 @@

    #> Columns: 22 #> $ lat <dbl> 38.89587, 43.65348 #> $ long <dbl> -77.03077, -79.38393 -#> $ address <chr> "L’Enfant's plan, Pennsylvania Avenue, Washington, District of Columbia, 20045, United S… +#> $ address <chr> "L’Enfant's plan, Pennsylvania Avenue, Washington, District of Columbia, 20045, United States", "Toronto City Hall, 100, Queen Str… #> $ place_id <int> 301711857, 137497520 -#> $ licence <chr> "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenSt… +#> $ licence <chr> "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenStreetMap contributors, ODbL 1.0. https://os… #> $ osm_type <chr> "way", "way" #> $ osm_id <int> 899927546, 198500761 #> $ osm_lat <chr> "38.895859599999994", "43.6536032" @@ -447,7 +447,7 @@

    #> $ postcode <chr> "20045", "M5H 2N2" #> $ country <chr> "United States", "Canada" #> $ country_code <chr> "us", "ca" -#> $ boundingbox <list> <"38.8957273", "38.8959688", "-77.0311667", "-77.0301895">, <"43.6529946", "43.6541458",… +#> $ boundingbox <list> <"38.8957273", "38.8959688", "-77.0311667", "-77.0301895">, <"43.6529946", "43.6541458", "-79.3848438", "-79.3830415"> #> $ amenity <chr> NA, "Toronto City Hall" #> $ house_number <chr> NA, "100" #> $ neighbourhood <chr> NA, "Financial District" @@ -583,7 +583,7 @@

    ) #> #> Passing 3 addresses to the US Census batch geocoder -#> Query completed in: 0.1 seconds +#> Query completed in: 0.2 seconds #> Passing 2 addresses to the Nominatim single address geocoder #> Query completed in: 2 seconds

    @@ -697,15 +697,15 @@

    #> $ lat <dbl> -12.06211, -12.20011, -11.99997, 30.03521, 30.04439, 30.03325 #> $ long <dbl> -77.03653, -76.28506, -76.83322, 31.56337, 31.23573, 31.56216 #> $ place_id <int> 258244064, 258655931, 258306819, 258758158, 793757, 298971141 -#> $ licence <chr> "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenStre… +#> $ licence <chr> "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.… #> $ osm_type <chr> "relation", "relation", "relation", "relation", "node", "relation" #> $ osm_id <int> 1944756, 1944659, 1944670, 5466227, 271613766, 4103336 -#> $ boundingbox <list> <"-12.0797663", "-12.0303496", "-77.0884555", "-77.0017774">, <"-13.3235137", "-10.2741856… -#> $ display_name <chr> "Lima, Lima Metropolitana, Lima, Perú", "Lima, Perú", "Lima, Lima Metropolitana, Lima, Per… +#> $ boundingbox <list> <"-12.0797663", "-12.0303496", "-77.0884555", "-77.0017774">, <"-13.3235137", "-10.2741856", "-77.8863105", "-75.5075">, <"-12.51993… +#> $ display_name <chr> "Lima, Lima Metropolitana, Lima, Perú", "Lima, Perú", "Lima, Lima Metropolitana, Lima, Perú", "القاهرة, محافظة القاهرة, مصر", "القاه… #> $ class <chr> "boundary", "boundary", "boundary", "place", "place", "boundary" #> $ type <chr> "administrative", "administrative", "administrative", "city", "city", "administrative" #> $ importance <dbl> 0.7830015, 0.6119761, 0.5934835, 0.6960286, 0.6960286, 0.4835559 -#> $ icon <chr> "https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png", "… +#> $ icon <chr> "https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png", "https://nominatim.openstreetmap.org/ui/map…

    To directly specify specific API parameters for a given method you can use the custom_query parameter. For example, the Nominatim (OSM) geocoder has a ‘polygon_geojson’ argument that can be used to return GeoJSON geometry content. To pass this parameter you can insert it with a named list using the custom_query argument:

     cairo_geo <- geo("Cairo, Egypt",
    @@ -724,7 +724,7 @@ 

    #> polygon_geojson : "1" #> format : "json" #> HTTP Status Code: 200 -#> Query completed in: 0.2 seconds +#> Query completed in: 0.1 seconds #> Total query time (including sleep): 1 seconds #> #> Query completed in: 1 seconds diff --git a/docs/news/index.html b/docs/news/index.html index 55fa30f9..c8e4c876 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -181,6 +181,7 @@

    • Corrected documentation for quiet parameter in geo() and reverse_geo()
    • +
    • Reconfigured the vignette so that it is precomputed and is not executed during R CMD check (ie. devtools::check()). Also added a check at the beginning of the vignette to check for the availability of APIs. This fixes an issue that occurred on Mac CRAN checks (#152).

    diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index f979d890..fdf0fff2 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -5,7 +5,7 @@ articles: developer_notes: developer_notes.html geocoder_services: geocoder_services.html tidygeocoder: tidygeocoder.html -last_built: 2021-10-24T13:36Z +last_built: 2021-10-24T18:49Z urls: reference: https://jessecambon.github.io/tidygeocoder/reference article: https://jessecambon.github.io/tidygeocoder/articles diff --git a/docs/reference/geo.html b/docs/reference/geo.html index ff671cad..cb6563da 100644 --- a/docs/reference/geo.html +++ b/docs/reference/geo.html @@ -349,15 +349,16 @@

    Arg

    - +regarding queries will be suppressed. FALSE is default. +Can be set permanently with options(tidygeocoder.quiet = TRUE).

    @@ -371,8 +372,7 @@

    Arg

    +Note that in some cases results are flattened regardless such as for Geocodio batch geocoding.

    @@ -468,7 +468,7 @@

    Examp
    # \donttest{ geo(street = "600 Peachtree Street NE", city = "Atlanta", state = "Georgia", method = "census") -
    #> Passing 1 address to the US Census single address geocoder
    #> Query completed in: 4.4 seconds
    #> # A tibble: 1 × 5 +
    #> Passing 1 address to the US Census single address geocoder
    #> Query completed in: 5.6 seconds
    #> # A tibble: 1 × 5 #> street city state lat long #> <chr> <chr> <chr> <dbl> <dbl> #> 1 600 Peachtree Street NE Atlanta Georgia 33.8 -84.4
    @@ -482,7 +482,7 @@

    Examp #> 3 Nairobi, Kenya -1.30 36.8

    geo("100 Main St New York, NY", full_results = TRUE, method = "census", api_options = list(census_return_type = 'geographies')) -
    #> Passing 1 address to the US Census single address geocoder
    #> Query completed in: 1.5 seconds
    #> # A tibble: 1 × 28 +
    #> Passing 1 address to the US Census single address geocoder
    #> Query completed in: 1.8 seconds
    #> # A tibble: 1 × 28 #> address lat long matchedAddress tigerLine.tiger… tigerLine.side #> <chr> <dbl> <dbl> <chr> <chr> <chr> #> 1 100 Main St New York, NY 40.7 -74.0 100 MAIN ST, … 59662602 R diff --git a/docs/reference/geo_combine.html b/docs/reference/geo_combine.html index 50a5817e..72f798f0 100644 --- a/docs/reference/geo_combine.html +++ b/docs/reference/geo_combine.html @@ -282,7 +282,7 @@

    Examp address = example_addresses, global_params = list(address = 'address') ) -

    #>
    #>
    #> Passing 3 addresses to the US Census batch geocoder
    #> Query completed in: 0.3 seconds
    #> Passing 2 addresses to the Nominatim single address geocoder
    #> Query completed in: 2 seconds
    #> # A tibble: 3 × 4 +
    #>
    #>
    #> Passing 3 addresses to the US Census batch geocoder
    #> Query completed in: 0.2 seconds
    #> Passing 2 addresses to the Nominatim single address geocoder
    #> Query completed in: 2 seconds
    #> # A tibble: 3 × 4 #> address lat long query #> <chr> <dbl> <dbl> <chr> #> 1 100 Main St New York, NY 40.7 -74.0 "census" @@ -299,7 +299,7 @@

    Examp cascade = FALSE, return_list = TRUE ) -

    #>
    #>
    #>
    #> Passing 3 addresses to the ArcGIS single address geocoder
    #> Query completed in: 1.2 seconds
    #> Passing 3 addresses to the US Census single address geocoder
    #> Query completed in: 1 seconds
    #> Passing 3 addresses to the US Census batch geocoder
    #> Query completed in: 0.2 seconds
    #> $arcgis +
    #>
    #>
    #>
    #> Passing 3 addresses to the ArcGIS single address geocoder
    #> Query completed in: 2.5 seconds
    #> Passing 3 addresses to the US Census single address geocoder
    #> Query completed in: 1.5 seconds
    #> Passing 3 addresses to the US Census batch geocoder
    #> Query completed in: 0.3 seconds
    #> $arcgis #> # A tibble: 3 × 3 #> address lat long #> <chr> <dbl> <dbl> @@ -332,7 +332,7 @@

    Examp country = c('Japan', 'United States'), cascade = FALSE ) -

    #>
    #>
    #> Passing 2 addresses to the ArcGIS single address geocoder
    #> Query completed in: 0.2 seconds
    #> Passing 2 addresses to the Nominatim single address geocoder
    #> Query completed in: 2 seconds
    #> # A tibble: 4 × 5 +
    #>
    #>
    #> Passing 2 addresses to the ArcGIS single address geocoder
    #> Query completed in: 1.2 seconds
    #> Passing 2 addresses to the Nominatim single address geocoder
    #> Query completed in: 2 seconds
    #> # A tibble: 4 × 5 #> city country lat long query #> <chr> <chr> <dbl> <dbl> <chr> #> 1 Tokyo Japan 35.7 140. arcgis diff --git a/docs/reference/geocode.html b/docs/reference/geocode.html index 3ea6c8be..8766d13a 100644 --- a/docs/reference/geocode.html +++ b/docs/reference/geocode.html @@ -302,7 +302,7 @@

    Examp library(dplyr, warn.conflicts = FALSE) sample_addresses %>% slice(1:2) %>% geocode(addr, method = 'arcgis') -

    #> Passing 2 addresses to the ArcGIS single address geocoder
    #> Query completed in: 1.1 seconds
    #> # A tibble: 2 × 4 +
    #> Passing 2 addresses to the ArcGIS single address geocoder
    #> Query completed in: 0.2 seconds
    #> # A tibble: 2 × 4 #> name addr lat long #> <chr> <chr> <dbl> <dbl> #> 1 White House 1600 Pennsylvania Ave NW Washington, DC 38.9 -77.0 diff --git a/docs/reference/geocode_combine.html b/docs/reference/geocode_combine.html index 45b296ce..90d03d9b 100644 --- a/docs/reference/geocode_combine.html +++ b/docs/reference/geocode_combine.html @@ -269,7 +269,7 @@

    Examp geocode_combine( queries = list(list(method = 'census'), list(method = 'osm')), global_params = list(address = 'addr'), cascade = TRUE) -

    #>
    #>
    #> Passing 9 addresses to the US Census batch geocoder
    #> Query completed in: 1.1 seconds
    #> Passing 5 addresses to the Nominatim single address geocoder
    #> Query completed in: 5 seconds
    #> # A tibble: 9 × 5 +
    #>
    #>
    #> Passing 9 addresses to the US Census batch geocoder
    #> Query completed in: 1.4 seconds
    #> Passing 5 addresses to the Nominatim single address geocoder
    #> Query completed in: 5 seconds
    #> # A tibble: 9 × 5 #> name addr lat long query #> <chr> <chr> <dbl> <dbl> <chr> #> 1 White House 1600 Pennsylvania Ave NW Washington, … 38.9 -77.0 cens… @@ -300,7 +300,7 @@

    Examp city = 'city', state = 'state', postalcode = 'zip_cd'), query_names = c('census batch', 'census single', 'osm') ) -

    #>
    #>
    #>
    #> Passing 4 addresses to the US Census batch geocoder
    #> Query completed in: 0.3 seconds
    #> Passing 3 addresses to the US Census single address geocoder
    #> Query completed in: 1.6 seconds
    #> Passing 1 address to the Nominatim single address geocoder
    #> Query completed in: 1 seconds
    #> # A tibble: 4 × 7 +
    #>
    #>
    #>
    #> Passing 4 addresses to the US Census batch geocoder
    #> Query completed in: 0.7 seconds
    #> Passing 3 addresses to the US Census single address geocoder
    #> Query completed in: 2.2 seconds
    #> Passing 1 address to the Nominatim single address geocoder
    #> Query completed in: 1 seconds
    #> # A tibble: 4 × 7 #> street_address city state zip_cd lat long query #> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr> #> 1 624 W DAVIS ST #1D BURLINGTON NC 27215 36.1 -79.4 census single @@ -317,7 +317,7 @@

    Examp cascade = FALSE, return_list = TRUE ) -

    #>
    #>
    #> Passing 4 addresses to the US Census batch geocoder
    #> Query completed in: 0.3 seconds
    #> Passing 4 addresses to the ArcGIS single address geocoder
    #> Query completed in: 1.2 seconds
    #> $census +
    #>
    #>
    #> Passing 4 addresses to the US Census batch geocoder
    #> Query completed in: 0.6 seconds
    #> Passing 4 addresses to the ArcGIS single address geocoder
    #> Query completed in: 1.4 seconds
    #> $census #> # A tibble: 4 × 6 #> street_address city state zip_cd lat long #> <chr> <chr> <chr> <dbl> <dbl> <dbl> diff --git a/docs/reference/reverse_geo.html b/docs/reference/reverse_geo.html index 8deb1b59..ab8a000c 100644 --- a/docs/reference/reverse_geo.html +++ b/docs/reference/reverse_geo.html @@ -298,15 +298,16 @@

    Arg

    - +regarding queries will be suppressed. FALSE is default. +Can be set permanently with options(tidygeocoder.quiet = TRUE).

    @@ -320,8 +321,7 @@

    Arg

    +Note that in some cases results are flattened regardless such as for Geocodio batch geocoding.

    diff --git a/docs/reference/reverse_geocode.html b/docs/reference/reverse_geocode.html index 254bd3d8..ccc3b661 100644 --- a/docs/reference/reverse_geocode.html +++ b/docs/reference/reverse_geocode.html @@ -285,7 +285,7 @@

    Examp louisville %>% head(3) %>% reverse_geocode(lat = latitude, long = longitude, method = 'arcgis') -
    #> Passing 3 coordinates to the ArcGIS single coordinate geocoder
    #> Query completed in: 2.3 seconds
    #> # A tibble: 3 × 7 +
    #> Passing 3 coordinates to the ArcGIS single coordinate geocoder
    #> Query completed in: 0.2 seconds
    #> # A tibble: 3 × 7 #> street city state zip latitude longitude address #> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr> #> 1 2722 ELLIOTT AVE Louisville Kentucky 40211 38.3 -85.8 2722 Elliott Av… diff --git a/man/geo.Rd b/man/geo.Rd index 7edfcc24..2f92675e 100644 --- a/man/geo.Rd +++ b/man/geo.Rd @@ -114,13 +114,14 @@ return_addresses to FALSE does not prevent this.} \item{min_time}{minimum amount of time for a query to take (in seconds). If NULL then min_time will be set to the default value specified in \link{min_time_reference}.} -\item{progress_bar}{if TRUE then a progress bar will be displayed to track query -progress for single input geocoding (1 input per query). By default the progress bar +\item{progress_bar}{if TRUE then a progress bar will be displayed +for single input geocoding (1 input per query). By default the progress bar will not be shown for code executed when knitting R Markdown files or code within an RStudio notebook chunk. Can be set permanently with \code{options(tidygeocoder.progress_bar = FALSE)}.} \item{quiet}{if TRUE then console messages that are displayed by default -regarding queries will be suppressed. Can be set permanently with \code{options(tidygeocoder.quiet = TRUE)}.} +regarding queries will be suppressed. FALSE is default. +Can be set permanently with \code{options(tidygeocoder.quiet = TRUE)}.} \item{api_url}{custom API URL. If specified, the default API URL will be overridden. This parameter can be used to specify a local Nominatim server, for instance.} @@ -128,8 +129,7 @@ This parameter can be used to specify a local Nominatim server, for instance.} \item{timeout}{query timeout (in minutes)} \item{flatten}{if TRUE (default) then any nested dataframes in results are flattened if possible. -Note that in some cases results are flattened regardless such as for -Geocodio batch geocoding.} +Note that in some cases results are flattened regardless such as for Geocodio batch geocoding.} \item{batch_limit}{limit to the number of addresses in a batch geocoding query. Defaults to the value in \link{batch_limit_reference} if not specified.} diff --git a/man/reverse_geo.Rd b/man/reverse_geo.Rd index bc6a1362..4b1c95fc 100644 --- a/man/reverse_geo.Rd +++ b/man/reverse_geo.Rd @@ -79,13 +79,14 @@ most services return the input coordinates with \code{full_results = TRUE} and s \item{min_time}{minimum amount of time for a query to take (in seconds). If NULL then min_time will be set to the default value specified in \link{min_time_reference}.} -\item{progress_bar}{if TRUE then a progress bar will be displayed to track query -progress for single input geocoding (1 input per query). By default the progress bar +\item{progress_bar}{if TRUE then a progress bar will be displayed +for single input geocoding (1 input per query). By default the progress bar will not be shown for code executed when knitting R Markdown files or code within an RStudio notebook chunk. Can be set permanently with \code{options(tidygeocoder.progress_bar = FALSE)}.} \item{quiet}{if TRUE then console messages that are displayed by default -regarding queries will be suppressed. Can be set permanently with \code{options(tidygeocoder.quiet = TRUE)}.} +regarding queries will be suppressed. FALSE is default. +Can be set permanently with \code{options(tidygeocoder.quiet = TRUE)}.} \item{api_url}{custom API URL. If specified, the default API URL will be overridden. This parameter can be used to specify a local Nominatim server, for instance.} @@ -93,8 +94,7 @@ This parameter can be used to specify a local Nominatim server, for instance.} \item{timeout}{query timeout (in minutes)} \item{flatten}{if TRUE (default) then any nested dataframes in results are flattened if possible. -Note that in some cases results are flattened regardless such as for -Geocodio batch geocoding.} +Note that in some cases results are flattened regardless such as for Geocodio batch geocoding.} \item{batch_limit}{limit to the number of coordinates in a batch geocoding query. Defaults to the value in \link{batch_limit_reference} if not specified.} diff --git a/vignettes/developer_notes.Rmd b/vignettes/developer_notes.Rmd index 1684b102..852a6d0b 100644 --- a/vignettes/developer_notes.Rmd +++ b/vignettes/developer_notes.Rmd @@ -92,6 +92,7 @@ This section documents how to add support for a new geocoding service to the pac These files don't necessarily need to be updated. However, you might need to make changes to these files if the service you are implementing requires some non-standard workarounds. + * **[R/query_factory.R](https://github.com/jessecambon/tidygeocoder/blob/main/R/query_factory.R)** * Houses the functions used to create and execute API queries. * **[R/documentation.R](https://github.com/jessecambon/tidygeocoder/blob/main/R/documentation.R)** @@ -103,12 +104,14 @@ These files don't necessarily need to be updated. However, you might need to mak * **[R/input_handling.R](https://github.com/jessecambon/tidygeocoder/blob/main/R/input_handling.R)** * Handles the deduplication of input data. * **[external/create_logo.Rmd](https://github.com/jessecambon/tidygeocoder/blob/main/external/create_logo.Rmd)** - * Create the package logo. + * Creates the package logo. +* **[vignettes/tidygeocoder.Rmd.orig](vignettes/tidygeocoder.Rmd.orig)** + * This file produces the vignette. See the knit command and comments at the top of this file. ### Testing -* Test out the new service with `verbose = TRUE` to make sure it behaves as expected. You can reference tests available [the 'sandbox' folder](https://github.com/jessecambon/tidygeocoder/tree/main/sandbox) for reference. -* Run `devtools::check()` to make sure the package still passes all tests and the vignette runs properly. To only run the package tests use `devtools::test()`, but note these tests do not query the geocoding services to avoid external dependencies. -* Run **[external/online_tests.R](https://github.com/jessecambon/tidygeocoder/blob/main/external/online_tests.R)** to test making queries to the geocoding services. These tests are not included in the internal package tests (`devtools::test()`) because they require API keys which would not exist on all systems and are dependent on the geocoding services being online at that the time of the test. -* Run the commands detailed in **[cran-comments.md](https://github.com/jessecambon/tidygeocoder/blob/main/cran-comments.md)** to test the package on other environments. Note that these tests should also be included in the automated GitHub actions tests for pull requests. -* When prepping for a release, use `urlchecker::url_check()` to check all package URLs. \ No newline at end of file +- Test out the new service to make sure it behaves as expected. You can reference tests and example code in [the 'sandbox' folder](https://github.com/jessecambon/tidygeocoder/tree/main/sandbox). +- Run `devtools::check()` to make sure the package still passes all tests and checks. To only run the package tests use `devtools::test()`, but note these tests do not query the geocoding services to avoid external dependencies. +- As a final check, run **[external/online_tests.R](https://github.com/jessecambon/tidygeocoder/blob/main/external/online_tests.R)** to test making queries to the geocoding services. These tests are not included in the internal package tests (`devtools::test()`) because they require API keys which would not exist on all systems and are dependent on the geocoding services being online at that the time of the test. +- Run the commands detailed in **[cran-comments.md](https://github.com/jessecambon/tidygeocoder/blob/main/cran-comments.md)** to test the package on other environments. Note that these tests should also be included in the automated GitHub actions tests for pull requests. +- When prepping for a release, use `urlchecker::url_check()` to check all package URLs. \ No newline at end of file diff --git a/vignettes/tidygeocoder.Rmd b/vignettes/tidygeocoder.Rmd index 17aed3dc..ca063bd5 100644 --- a/vignettes/tidygeocoder.Rmd +++ b/vignettes/tidygeocoder.Rmd @@ -13,7 +13,6 @@ vignette: > - ## Introduction Tidygeocoder provides a unified interface for performing both forward and reverse geocoding queries with a variety of geocoding services. In forward geocoding you provide an address to the geocoding service and you get latitude and longitude coordinates in return. In reverse geocoding you provide the latitude and longitude and the geocoding service will return that location's address. In both cases, other data about the location can be provided by the geocoding service. @@ -73,7 +72,7 @@ osm_s1 <- geo( lat = latitude, long = longitude ) #> Passing 2 addresses to the Nominatim single address geocoder -#> Query completed in: 2.1 seconds +#> Query completed in: 2 seconds ``` |address | latitude| longitude| @@ -88,7 +87,7 @@ Instead of single-line addresses, you can use any combination of the following a census_c1 <- address_components %>% geocode(street = street, city = cty, state = st, method = "census") #> Passing 2 addresses to the US Census batch geocoder -#> Query completed in: 1.8 seconds +#> Query completed in: 1.4 seconds ``` |street |cty |st | lat| long| @@ -105,7 +104,7 @@ census_full1 <- address_single %>% geocode( method = "census", full_results = TRUE, api_options = list(census_return_type = 'geographies') ) #> Passing 2 addresses to the US Census batch geocoder -#> Query completed in: 1.2 seconds +#> Query completed in: 1.5 seconds ``` @@ -149,7 +148,7 @@ lat_longs1 <- tibble( rev1 <- lat_longs1 %>% reverse_geocode(lat = latitude, long = longitude, address = addr, method = "osm") #> Passing 2 coordinates to the Nominatim single coordinate geocoder -#> Query completed in: 2.1 seconds +#> Query completed in: 2 seconds ``` @@ -175,9 +174,9 @@ glimpse(rev2) #> Columns: 22 #> $ lat 38.89587, 43.65348 #> $ long -77.03077, -79.38393 -#> $ address "L’Enfant's plan, Pennsylvania Avenue, Washington, District of Columbia, 20045, United S… +#> $ address "L’Enfant's plan, Pennsylvania Avenue, Washington, District of Columbia, 20045, United States", "Toronto City Hall, 100, Queen Str… #> $ place_id 301711857, 137497520 -#> $ licence "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenSt… +#> $ licence "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenStreetMap contributors, ODbL 1.0. https://os… #> $ osm_type "way", "way" #> $ osm_id 899927546, 198500761 #> $ osm_lat "38.895859599999994", "43.6536032" @@ -189,7 +188,7 @@ glimpse(rev2) #> $ postcode "20045", "M5H 2N2" #> $ country "United States", "Canada" #> $ country_code "us", "ca" -#> $ boundingbox <"38.8957273", "38.8959688", "-77.0311667", "-77.0301895">, <"43.6529946", "43.6541458",… +#> $ boundingbox <"38.8957273", "38.8959688", "-77.0311667", "-77.0301895">, <"43.6529946", "43.6541458", "-79.3848438", "-79.3830415"> #> $ amenity NA, "Toronto City Hall" #> $ house_number NA, "100" #> $ neighbourhood NA, "Financial District" @@ -289,7 +288,7 @@ cascade_results1 <- addresses_combine %>% ) #> #> Passing 3 addresses to the US Census batch geocoder -#> Query completed in: 0.1 seconds +#> Query completed in: 0.2 seconds #> Passing 2 addresses to the Nominatim single address geocoder #> Query completed in: 2 seconds ``` @@ -353,15 +352,15 @@ glimpse(geo_limit) #> $ lat -12.06211, -12.20011, -11.99997, 30.03521, 30.04439, 30.03325 #> $ long -77.03653, -76.28506, -76.83322, 31.56337, 31.23573, 31.56216 #> $ place_id 258244064, 258655931, 258306819, 258758158, 793757, 298971141 -#> $ licence "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenStre… +#> $ licence "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.… #> $ osm_type "relation", "relation", "relation", "relation", "node", "relation" #> $ osm_id 1944756, 1944659, 1944670, 5466227, 271613766, 4103336 -#> $ boundingbox <"-12.0797663", "-12.0303496", "-77.0884555", "-77.0017774">, <"-13.3235137", "-10.2741856… -#> $ display_name "Lima, Lima Metropolitana, Lima, Perú", "Lima, Perú", "Lima, Lima Metropolitana, Lima, Per… +#> $ boundingbox <"-12.0797663", "-12.0303496", "-77.0884555", "-77.0017774">, <"-13.3235137", "-10.2741856", "-77.8863105", "-75.5075">, <"-12.51993… +#> $ display_name "Lima, Lima Metropolitana, Lima, Perú", "Lima, Perú", "Lima, Lima Metropolitana, Lima, Perú", "القاهرة, محافظة القاهرة, مصر", "القاه… #> $ class "boundary", "boundary", "boundary", "place", "place", "boundary" #> $ type "administrative", "administrative", "administrative", "city", "city", "administrative" #> $ importance 0.7830015, 0.6119761, 0.5934835, 0.6960286, 0.6960286, 0.4835559 -#> $ icon "https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png", "… +#> $ icon "https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png", "https://nominatim.openstreetmap.org/ui/map… ``` To directly specify specific API parameters for a given `method` you can use the `custom_query` parameter. For example, [the Nominatim (OSM) geocoder has a 'polygon_geojson' argument](https://nominatim.org/release-docs/develop/api/Details/#parameters) that can be used to return GeoJSON geometry content. To pass this parameter you can insert it with a named list using the `custom_query` argument: @@ -384,7 +383,7 @@ cairo_geo <- geo("Cairo, Egypt", #> polygon_geojson : "1" #> format : "json" #> HTTP Status Code: 200 -#> Query completed in: 0.2 seconds +#> Query completed in: 0.1 seconds #> Total query time (including sleep): 1 seconds #> #> Query completed in: 1 seconds diff --git a/vignettes/tidygeocoder.Rmd.orig b/vignettes/tidygeocoder.Rmd.orig index 9599866c..be46c6fb 100644 --- a/vignettes/tidygeocoder.Rmd.orig +++ b/vignettes/tidygeocoder.Rmd.orig @@ -10,26 +10,29 @@ vignette: > --- ```{r, echo = FALSE, message = FALSE} -# INSTRUCTIONS: execute this vignette with this command: +############################ INSTRUCTIONS ########################################### +# 1. Make all changes to tidygeocder.Rmd.orig +# 2. Knit the vignette with this command: +# # knitr::knit("vignettes/tidygeocoder.Rmd.orig", output = "vignettes/tidygeocoder.Rmd") # # See these instructions for more detail: # https://ropensci.org/blog/2019/12/08/precompute-vignettes/ +##################################################################################### knitr::opts_chunk$set(collapse = TRUE, comment = "#>") options(tibble.print_min = 4L, tibble.print_max = 4L) set.seed(42) ``` -```{r, echo = FALSE, message = FALSE, eval = FALSE} +```{r, echo = FALSE, message = FALSE} # check to make sure both the US Census and Nominatim endpoints are available -# (ie. we have an internet connection) -# These checks are no longer necessary as this vignette is executed locally +# (ie. we have an internet connection and neither service is down) # Check that US Census service is available tryCatch( expr = { - tidygeocoder::geo('1600 Pennsylvania Avenue NW, Washington, DC 20500', + no_output <- tidygeocoder::geo('1600 Pennsylvania Avenue NW, Washington, DC 20500', method = 'census') }, error = function(e) { @@ -47,8 +50,8 @@ tryCatch( # Check that the Nominatim service is available tryCatch( expr = { - tidygeocoder::geo('London', method = 'osm') - tidygeocoder::reverse_geo(lat = 0, long = 0, method = 'osm') + no_output <- tidygeocoder::geo('London', method = 'osm') + no_output <- tidygeocoder::reverse_geo(lat = 0, long = 0, method = 'osm') }, error = function(e) { stop(paste0('The Nominatim ("osm") geocoding API is not available. ',

    progress_bar

    if TRUE then a progress bar will be displayed to track query -progress for single input geocoding (1 input per query). By default the progress bar +

    if TRUE then a progress bar will be displayed +for single input geocoding (1 input per query). By default the progress bar will not be shown for code executed when knitting R Markdown files or code within an RStudio notebook chunk. Can be set permanently with options(tidygeocoder.progress_bar = FALSE).

    quiet

    if TRUE then console messages that are displayed by default -regarding queries will be suppressed. Can be set permanently with options(tidygeocoder.quiet = TRUE).

    api_url
    flatten

    if TRUE (default) then any nested dataframes in results are flattened if possible. -Note that in some cases results are flattened regardless such as for -Geocodio batch geocoding.

    batch_limit
    progress_bar

    if TRUE then a progress bar will be displayed to track query -progress for single input geocoding (1 input per query). By default the progress bar +

    if TRUE then a progress bar will be displayed +for single input geocoding (1 input per query). By default the progress bar will not be shown for code executed when knitting R Markdown files or code within an RStudio notebook chunk. Can be set permanently with options(tidygeocoder.progress_bar = FALSE).

    quiet

    if TRUE then console messages that are displayed by default -regarding queries will be suppressed. Can be set permanently with options(tidygeocoder.quiet = TRUE).

    api_url
    flatten

    if TRUE (default) then any nested dataframes in results are flattened if possible. -Note that in some cases results are flattened regardless such as for -Geocodio batch geocoding.

    batch_limit