Executes multiple geocoding queries on a dataframe input and combines the results. To use a character vector input instead, see the geo_combine function. Queries are executed by the geocode function. See example usage in vignette("tidygeocoder").

Query results are by default labelled to show which query produced each result. Labels are either placed in a query column (if return_list = FALSE) or used as the names of the returned list (if return_list = TRUE). By default the method parameter value of each query is used as a query label. If the same method is used in multiple queries then a number is added according to the order of the queries (ie. osm1, osm2, ...). To provide your own custom query labels use the query_names parameter.

geocode_combine(
  .tbl,
  queries,
  global_params = list(),
  return_list = FALSE,
  cascade = TRUE,
  query_names = NULL,
  lat = "lat",
  long = "long"
)

Arguments

.tbl

dataframe containing addresses

queries

a list of queries, each provided as a list of parameters. The queries are, executed by the geocode function in the order provided., (ex. list(list(method = 'osm'), list(method = 'census'), ...))

global_params

a list of parameters to be used for all queries, (ex. list(address = 'address', full_results = TRUE))

return_list

if TRUE then results from each service will be returned as separate dataframes. If FALSE (default) then all results will be combined into a single dataframe.

cascade

if TRUE (default) then only addresses that are not found by a geocoding service will be attempted by subsequent queries. If FALSE then all queries will attempt to geocode all addresses.

query_names

optional vector with one label for each query provided (ex. c('geocodio batch', 'geocodio single')).

lat

latitude column name. Can be quoted or unquoted (ie. lat or "lat").

long

longitude column name. Can be quoted or unquoted (ie. long or "long").

Value

tibble (dataframe)

Examples

# \donttest{

library(dplyr, warn.conflicts = FALSE)

sample_addresses %>%
  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: 0.2 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 "cen…
#> 2 Transamerica Pyramid 600 Montgomery St, San Francisco, CA … 37.8  -122.  "cen…
#> 3 NY Stock Exchange    11 Wall Street, New York, New York     40.7   -74.0 "cen…
#> 4 Willis Tower         233 S Wacker Dr, Chicago, IL 60606     41.9   -87.6 "cen…
#> 5 Chateau Frontenac    1 Rue des Carrieres, Quebec, QC G1R 4… NA      NA   ""   
#> 6 Nashville            Nashville, TN                          36.2   -86.8 "osm"
#> 7 Nairobi              Nairobi, Kenya                         -1.28   36.8 "osm"
#> 8 Istanbul             Istanbul, Turkey                       41.0    29.0 "osm"
#> 9 Tokyo                Tokyo, Japan                           35.7   140.  "osm"

more_addresses <- tibble::tribble(
  ~street_address, ~city, ~state, ~zip_cd,
  "624 W DAVIS ST #1D", "BURLINGTON", "NC", 27215,
  "201 E CENTER ST #268", "MEBANE", "NC", 27302,
  "100 Wall Street", "New York", "NY", 10005,
  "Bucharest", NA, NA, NA
)

more_addresses %>%
  geocode_combine(
    queries = list(
      list(method = "census", mode = "batch"),
      list(method = "census", mode = "single"),
      list(method = "osm")
    ),
    global_params = list(
      street = "street_address",
      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.1 seconds
#> Passing 3 addresses to the US Census single address geocoder
#> Query completed in: 11.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
#> 2 201 E CENTER ST #268 MEBANE     NC     27302  36.1  -79.3 census single
#> 3 100 Wall Street      New York   NY     10005  40.7  -74.0 census batch 
#> 4 Bucharest            NA         NA        NA  33.5 -117.  osm          

more_addresses %>%
  geocode_combine(
    queries = list(
      list(
        method = "census", mode = "batch", street = "street_address",
        city = "city", state = "state", postalcode = "zip_cd"
      ),
      list(method = "arcgis", address = "street_address")
    ),
    cascade = FALSE,
    return_list = TRUE
  )
#> 
#> 
#> Passing 4 addresses to the US Census batch geocoder
#> Query completed in: 0.2 seconds
#> Passing 4 addresses to the ArcGIS single address geocoder
#> Query completed in: 2.2 seconds
#> $census
#> # A tibble: 4 × 6
#>   street_address       city       state zip_cd   lat  long
#>   <chr>                <chr>      <chr>  <dbl> <dbl> <dbl>
#> 1 624 W DAVIS ST #1D   BURLINGTON NC     27215  NA    NA  
#> 2 201 E CENTER ST #268 MEBANE     NC     27302  NA    NA  
#> 3 100 Wall Street      New York   NY     10005  40.7 -74.0
#> 4 Bucharest            NA         NA        NA  NA    NA  
#> 
#> $arcgis
#> # A tibble: 4 × 6
#>   street_address       city       state zip_cd   lat    long
#>   <chr>                <chr>      <chr>  <dbl> <dbl>   <dbl>
#> 1 624 W DAVIS ST #1D   BURLINGTON NC     27215  62.1   -7.04
#> 2 201 E CENTER ST #268 MEBANE     NC     27302  45.9 -123.  
#> 3 100 Wall Street      New York   NY     10005  34.6  -86.8 
#> 4 Bucharest            NA         NA        NA  44.4   26.1 
#> 
# }