Learn R Programming

tidygeocoder (version 1.0.3)

reverse_geo: Reverse geocode coordinates

Description

Reverse geocodes geographic coordinates (latitude and longitude) given as numeric values. Latitude and longitude inputs are limited to possible values. Latitudes must be between -90 and 90 and longitudes must be between -180 and 180. Invalid values will not be sent to the geocoder service. The reverse_geocode function utilizes this function on coordinates contained in dataframes. See example usage in vignette("tidygeocoder").

Refer to api_parameter_reference, min_time_reference, and batch_limit_reference for more details on geocoder service parameters and usage.

This function uses the get_api_query, query_api, and extract_reverse_results functions to create, execute, and parse geocoder API queries.

Usage

reverse_geo(
  lat,
  long,
  method = "osm",
  address = address,
  limit = 1,
  min_time = NULL,
  api_url = NULL,
  timeout = 20,
  mode = "",
  full_results = FALSE,
  unique_only = FALSE,
  return_coords = TRUE,
  flatten = TRUE,
  batch_limit = NULL,
  verbose = FALSE,
  no_query = FALSE,
  custom_query = list(),
  iq_region = "us",
  geocodio_v = 1.6,
  mapbox_permanent = FALSE,
  here_request_id = NULL,
  mapquest_open = FALSE
)

Arguments

lat

latitude values (input data)

long

longitude values (input data)

method

the geocoder 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 line GEOCODIO_API_KEY="YourAPIKeyHere".

  • "osm": Nominatim.

  • "arcgis": ArcGIS.

  • "geocodio": Geocodio. Geographic coverage is limited to the United States and Canada. An API key must be stored in "GEOCODIO_API_KEY". Batch geocoding is supported.

  • "iq": Location IQ. An API key must be stored in "LOCATIONIQ_API_KEY".

  • "google": Google. An API key must be stored in "GOOGLEGEOCODE_API_KEY".

  • "opencage": OpenCage. An API key must be stored in "OPENCAGE_KEY".

  • "mapbox": Mapbox. An API key must be stored in "MAPBOX_API_KEY".

  • "here": HERE. An API key must be stored in "HERE_API_KEY". Batch geocoding is supported, but must be explicitly called with mode = "batch".

  • "tomtom": TomTom. An API key must be stored in "TOMTOM_API_KEY". Batch geocoding is supported.

  • "mapquest": MapQuest. An API key must be stored in "MAPQUEST_API_KEY". Batch geocoding is supported.

  • "bing": Bing. An API key must be stored in "BINGMAPS_API_KEY". Batch geocoding is supported, but must be explicitly called with mode = "batch".

address

name of the address column (in the output data)

limit

maximum number of results to return per input coordinate. For many geocoder services the maximum value of the limit parameter is 100. Pass limit = NULL to use the default limit value of the selected geocoder service. For batch geocoding, limit must be set to 1 (default) if return_coords = TRUE. Refer to api_parameter_reference for more details.

min_time

minimum amount of time for a query to take (in seconds). If NULL then min_time will be set to the default value specified in min_time_reference.

api_url

custom API URL. If specified, the default API URL will be overridden. This parameter can be used to specify a local Nominatim server, for instance.

timeout

query timeout (in minutes)

mode

set to 'batch' to force batch geocoding or 'single' to force single coordinate geocoding (one coordinate per query). If not specified then batch geocoding will be used if available (given method selected) when multiple coordinates are provided; otherwise single address geocoding will be used. For the "here" and "bing" methods the batch mode should be explicitly specified with mode = 'batch'.

full_results

returns all data from the geocoder service if TRUE. If FALSE then only a single address column will be returned from the geocoder service.

unique_only

only return results for unique inputs if TRUE

return_coords

return input coordinates with results if TRUE. Note that most services return the input coordinates with full_results = TRUE and setting return_coords to FALSE does not prevent this.

flatten

if TRUE then any nested dataframes in results are flattened if possible. Note that in some cases results are flattened regardless such as for Geocodio batch geocoding.

batch_limit

limit to the number of coordinates in a batch geocoding query. Defaults to the value in batch_limit_reference if not specified.

verbose

if TRUE then detailed logs are output to the console

no_query

if TRUE then no queries are sent to the geocoder service and verbose is set to TRUE. Used for testing.

custom_query

API-specific parameters to be used, passed as a named list (ie. list(extratags = 1).

iq_region

"us" (default) or "eu". Used for establishing the API URL for the "iq" method.

geocodio_v

version of geocodio API. Used for establishing the API URL for the "geocodio" method.

mapbox_permanent

if TRUE then the mapbox.places-permanent endpoint would be used. Note that this option should be used only if you have applied for a permanent account. Unsuccessful requests made by an account that does not have access to the endpoint may be billable.

here_request_id

This parameter would return a previous HERE batch job, identified by its RequestID. The RequestID of a batch job is displayed when verbose = TRUE. Note that this option would ignore the current lat, long parameters on the request, so return_coords needs to be FALSE.

mapquest_open

if TRUE then MapQuest would use the Open Geocoding endpoint, that relies solely on data contributed to OpenStreetMap.

Value

tibble (dataframe)

See Also

reverse_geocode api_parameter_reference min_time_reference batch_limit_reference

Examples

Run this code
# NOT RUN {
 reverse_geo(lat = 38.895865, long = -77.0307713, method = 'osm', verbose = TRUE)
 
 reverse_geo(
   lat = c(38.895865, 43.6534817, 300), 
   long = c(-77.0307713, -79.3839347, 600),
   method = 'osm', full_results = TRUE, verbose = TRUE
 )
 
# }

Run the code above in your browser using DataLab