Reverse geocoding

Share:

Description

Reverse geocoding, from latitude and longitude to placename(s).

Usage

1
2
3
opencage_reverse(latitude, longitude, key = opencage_key(), bounds = NULL,
  countrycode = NULL, language = NULL, limit = 10,
  min_confidence = NULL, no_annotations = NULL, no_dedupe = NULL)

Arguments

latitude

Latitude.

longitude

Longitude.

key

Your OpenCage key.

bounds

Provides the geocoder with a hint to the region that the query resides in. This value will restrict the possible results to the supplied region. The bounds parameter should be specified as 4 coordinate points forming the south-west and north-east corners of a bounding box. For example, bounds = c(-0.563160, 51.280430, 0.278970, 51.683979) (min long, min lat, max long, max lat).

countrycode

Restricts the results to the given country. The country code is a two letter code as defined by the ISO 3166-1 Alpha 2 standard. E.g. "GB" for the United Kingdom, "FR" for France, "US" for United States.

language

An IETF format language code (such as "es" for Spanish or "pt-BR" for Brazilian Portuguese). If no language is explicitly specified, we will look for an HTTP Accept-Language header like those sent by a brower and use the first language specified and if none are specified "en" (English) will be assumed.

limit

How many results should be returned (1-100). Default is 10.

min_confidence

An integer from 1-10. Only results with at least this confidence will be returned.

no_annotations

Logical (default FALSE), when TRUE the output will not contain annotations.

no_dedupe

Logical (default FALSE), when TRUE the output will not be deduplicated.

Details

To get an API key to access OpenCage geocoding, register at https://geocoder.opencagedata.com/pricing. The free API key provides up to 2,500 calls a day. For ease of use, save your API key as an environment variable as described at https://stat545-ubc.github.io/bit003_api-key-env-var.html. Both functions of the package will conveniently look for your API key using Sys.getenv("OPENCAGE_KEY") so if your API key is an environment variable called "OPENCAGE_KEY" you don't need to input it manually.

The underlying data at OpenCage is updated about once a day. Note that the package uses 'memoise' with no timeout argument so that results are cached inside an active R session.

Value

A list with

  • results as a data.frame ('dplyr' 'tbl_df') called results with one line per results,

  • the number of results as an integer,

  • the timestamp as a POSIXct object,

  • rate_info data.frame ('dplyr' 'tbl_df') with the maximal number of API calls per day for the used key, the number of remaining calls for the day and the time at which the number of remaining calls with be reset.

Examples

1
2
3
4
5
## Not run: 
opencage_reverse(latitude = 0, longitude = 0,
limit = 2)

## End(Not run)