
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.RdWraps 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 with
full_results = TRUEas 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()andNULLfordf_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.tbldataframe containing addresses
streetstreet address column name
citycity column name
countycounty column name
statestate column name
postalcodepostalcode column name (zip code if in the United States)
countrycountry column name
latlatitude column name. Can be quoted or unquoted (ie. lat or 'lat').
longlongitude column name. Can be quoted or unquoted (ie. long or 'long').
return_inputif TRUE then the input dataset will be combined with the geocoder query results and returned. If FALSE only the geocoder results will be returned.
limitmaximum number of results to return per input address. For many geocoding services the maximum value of the limit parameter is 100. Pass
limit = NULLto use the defaultlimitvalue of the selected geocoding service. For batch geocoding, limit must be set to 1 (default) ifreturn_addresses = TRUE. To uselimit > 1orlimit = NULLset return_input to FALSE. Refer to api_parameter_reference for more details.return_addressesif TRUE return input addresses. Defaults to TRUE if
return_inputis FALSE and FALSE ifreturn_inputis TRUE. This argument is passed to thegeo()function.unique_onlyif 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 thecallargument ofabort()for more information.