geocode_combine: Combine multiple geocoding queries

View source: R/geocode_combine.R

geocode_combineR Documentation

Combine multiple geocoding queries

Description

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.

Usage

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)

See Also

geo_combine geo geocode

Examples



library(dplyr, warn.conflicts = FALSE)

sample_addresses %>%
  geocode_combine(
    queries = list(list(method = "census"), list(method = "osm")),
    global_params = list(address = "addr"), cascade = TRUE
  )

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")
  )

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
  )


jessecambon/tidygeocoder documentation built on Jan. 26, 2023, 4:03 p.m.