Takes a dataframe containing addresses as an input and returns
the results from a specified geocoding service in a dataframe format using the
geo function. See example usage in vignette("tidygeocoder")
.
This function passes all additional parameters (...
) to the
geo function, so you can refer to its documentation for more details
on possible arguments.
Note that the arguments used for specifying address columns (address
,
street
, city
, county
, state
, postalcode
, and country
) accept either
quoted or unquoted column names (ie. "address_col"
and address_col
are
both acceptable).
geocode(
.tbl,
address = NULL,
street = NULL,
city = NULL,
county = NULL,
state = NULL,
postalcode = NULL,
country = NULL,
lat = "lat",
long = "long",
return_input = TRUE,
limit = 1,
return_addresses = NULL,
unique_only = FALSE,
...
)
dataframe containing addresses
single line street address column name. Do not combine with
address component arguments (street
, city
, county
, state
, postalcode
, country
)
street address column name
city column name
county column name
state column name
postal code column name (zip code if in the United States)
country column name
latitude column name. Can be quoted or unquoted (ie. lat
or "lat"
).
longitude column name. Can be quoted or unquoted (ie. long
or "long"
).
if TRUE then the input dataset will be combined with the geocoder query results and returned. If FALSE only the geocoder results will be returned.
maximum number of results to return per input address. For many geocoding services the maximum value of the limit parameter is 100. Pass limit = NULL
to use the default limit
value of the selected geocoding service. For batch geocoding, limit must be set to 1 (default) if return_addresses = TRUE
.To use limit > 1
or limit = NULL
set return_input to FALSE. Refer to api_parameter_reference for more details.
if TRUE return input addresses. Defaults to TRUE if return_input
is FALSE
and FALSE if return_input
is TRUE. This argument is passed to the geo()
function.
if TRUE then only unique results will be returned and return_input will be set to FALSE.
arguments passed to the geo function
tibble (dataframe)
# \donttest{
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
#> name addr lat long
#> <chr> <chr> <dbl> <dbl>
#> 1 White House 1600 Pennsylvania Ave NW Washington, DC 38.9 -77.0
#> 2 Transamerica Pyramid 600 Montgomery St, San Francisco, CA 94111 37.8 -122.
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.1 seconds
#> # A tibble: 2 × 15
#> street city state zip latit…¹ longi…² lat long id input…³ match…⁴
#> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <chr> <chr>
#> 1 2722 ELLI… Loui… Kent… 40211 38.3 -85.8 38.3 -85.8 1 2722 E… Match
#> 2 850 WASHB… Loui… Kent… 40222 38.3 -85.6 38.3 -85.6 2 850 WA… Match
#> # … with 4 more variables: match_type <chr>, matched_address <chr>,
#> # tiger_line_id <int>, tiger_side <chr>, and abbreviated variable names
#> # ¹latitude, ²longitude, ³input_address, ⁴match_indicator
sample_addresses %>%
slice(8:9) %>%
geocode(addr,
method = "osm", limit = 2,
return_input = FALSE, full_results = TRUE
)
#> Passing 2 addresses to the Nominatim single address geocoder
#> Query completed in: 2 seconds
#> # A tibble: 4 × 13
#> address lat long place…¹ licence osm_t…² osm_id bound…³ displ…⁴ class type
#> <chr> <dbl> <dbl> <int> <chr> <chr> <dbl> <list> <chr> <chr> <chr>
#> 1 Istanb… 41.0 29.0 1.69e7 Data ©… node 1.88e9 <chr> İstanb… place city
#> 2 Istanb… 41.1 29.1 2.98e8 Data ©… relati… 2.23e5 <chr> İstanb… boun… admi…
#> 3 Tokyo,… 35.7 140. 2.98e8 Data ©… relati… 1.54e6 <chr> 東京都… boun… admi…
#> 4 Tokyo,… 35.7 140. 6.90e7 Data ©… node 6.40e9 <chr> 東京, … rail… stat…
#> # … with 2 more variables: importance <dbl>, icon <chr>, and abbreviated
#> # variable names ¹place_id, ²osm_type, ³boundingbox, ⁴display_name
sample_addresses %>%
slice(4:5) %>%
geocode(addr,
method = "arcgis",
lat = latitude, long = longitude,
full_results = TRUE
)
#> Passing 2 addresses to the ArcGIS single address geocoder
#> Query completed in: 0.2 seconds
#> # A tibble: 2 × 70
#> name addr latit…¹ longi…² arcgi…³ score locat…⁴ locat…⁵ attri…⁶ attri…⁷
#> <chr> <chr> <dbl> <dbl> <chr> <int> <dbl> <dbl> <chr> <chr>
#> 1 Willis To… 233 … 41.9 -87.6 233 S … 100 -87.6 41.9 World M
#> 2 Chateau F… 1 Ru… 46.8 -71.2 1 Rue … 100 -71.2 46.8 World M
#> # … with 60 more variables: attributes.Score <int>,
#> # attributes.Match_addr <chr>, attributes.LongLabel <chr>,
#> # attributes.ShortLabel <chr>, attributes.Addr_type <chr>,
#> # attributes.Type <chr>, attributes.PlaceName <chr>,
#> # attributes.Place_addr <chr>, attributes.Phone <chr>, attributes.URL <chr>,
#> # attributes.Rank <int>, attributes.AddBldg <chr>, attributes.AddNum <chr>,
#> # attributes.AddNumFrom <chr>, attributes.AddNumTo <chr>, …
# }