Use tidygeocoder to convert an address or data frame with an address column to an sf object
Source:R/sf_to_df.R
address_to_sf.Rd
Wraps tidygeocoder::geo()
and tidygeocoder::geocode()
to convert a
character string or a data frame with an address column. Additional
parameters passed to tidygeocoder::geocode()
which passes ...
parameters to
tidygeocoder::geo()
.
Usage
address_to_sf(
x,
address = "address",
method = "osm",
coords = c("lon", "lat"),
remove_coords = FALSE,
crs = NULL,
full_results = FALSE,
...,
call = caller_env()
)
Arguments
- x
Data frame with an address column. Multiple address columns are not currently supported.
- address
Address column name, Default: 'address'
- method
the geocoding service to be used. API keys are loaded from environmental variables. Run
usethis::edit_r_environ()
to open your .Renviron file and add an API key as an environmental variable. For example, add the lineGEOCODIO_API_KEY="YourAPIKeyHere"
."osm"
: Nominatim."census"
: US Census. Geographic coverage is limited to the United States. Batch geocoding is supported."arcgis"
: ArcGIS."geocodio"
: Geocodio. Geographic coverage is limited to the United States and Canada. An API key must be stored in the environmental variable "GEOCODIO_API_KEY". Batch geocoding is supported."iq"
: Location IQ. An API key must be stored in the environmental variable "LOCATIONIQ_API_KEY"."google"
: Google. An API key must be stored in the environmental variable "GOOGLEGEOCODE_API_KEY"."opencage"
: OpenCage. An API key must be stored in the environmental variable "OPENCAGE_KEY"."mapbox"
: Mapbox. An API key must be stored in the environmental variable "MAPBOX_API_KEY"."here"
: HERE. An API key must be stored in the environmental variable "HERE_API_KEY". Batch geocoding is supported, but must be explicitly called withmode = "batch"
."tomtom"
: TomTom. An API key must be stored in the environmental variable "TOMTOM_API_KEY". Batch geocoding is supported."mapquest"
: MapQuest. An API key must be stored in the environmental variable "MAPQUEST_API_KEY". Batch geocoding is supported."bing"
: Bing. An API key must be stored in the environmental variable "BINGMAPS_API_KEY". Batch geocoding is supported, but must be explicitly called withmode = "batch"
."geoapify"
: Geoapify. An API key must be stored in the environmental variable "GEOAPIFY_KEY"."cascade"
use geocode_combine or geo_combine instead. The "cascade" method first uses one geocoding service and then uses a second geocoding service if the first service didn't return results. The services and order is specified by the cascade_order argument. Note that this is not compatible withfull_results = TRUE
as geocoding services have different columns that they return.
- coords
Coordinate columns for input data.frame or output sf object (if geometry is 'centroid' or 'point') Default: c("lon", "lat").
- remove_coords
For
df_to_sf()
, ifTRUE
, remove the coordinate columns after converting a data frame to simple feature object; defaults toFALSE
.- crs
Cordinate reference system to return, Default: 4326 for
sf_to_df()
andNULL
fordf_to_sf()
.- full_results
returns all available data from the geocoding service if TRUE. If FALSE (default) then only latitude and longitude columns are returned from the geocoding service.
- ...
Arguments passed on to
tidygeocoder::geocode
.tbl
dataframe containing addresses
street
street address column name
city
city column name
county
county column name
state
state column name
postalcode
postalcode column name (zip code if in the United States)
country
country column name
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').
return_input
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.
limit
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 defaultlimit
value of the selected geocoding service. For batch geocoding, limit must be set to 1 (default) ifreturn_addresses = TRUE
. To uselimit > 1
orlimit = NULL
set return_input to FALSE. Refer to api_parameter_reference for more details.return_addresses
if TRUE return input addresses. Defaults to TRUE if
return_input
is FALSE and FALSE ifreturn_input
is TRUE. This argument is passed to thegeo()
function.unique_only
if TRUE then only unique results will be returned and return_input will be set to FALSE.
- call
The execution environment of a currently running function, e.g.
caller_env()
. The function will be mentioned in error messages as the source of the error. See thecall
argument ofabort()
for more information.