Opencage
:globe_with_meridians: R package for the OpenCage API -- both forward and reverse geocoding :globe_with_meridians:
Install / Use
/learn @ropensci/OpencageREADME
opencage
<!-- badges: start --> <!-- badges: end -->Geocode with the OpenCage API, either from place name to longitude and latitude (forward geocoding) or from longitude and latitude to the name and address of the location (reverse geocoding).
Installation
You can install {opencage} from CRAN, R-universe or GitHub like this:
-
Release version from CRAN
install.packages("opencage") -
Development version from R-universe
install.packages( "opencage", repos = c("https://ropensci.r-universe.dev", getOption("repos")) ) -
Development version from GitHub with {pak}
pak::pak("ropensci/opencage")or with {remotes}
remotes::install_github("ropensci/opencage")
Quickstart
For the best experience, we recommend that you read through the
“Introduction to
opencage”
vignette (vignette("opencage")), but if you are in a hurry:
- Register at opencagedata.com/users/sign_up.
- Generate an API key at the OpenCage dashboard.
- Save your API key as an environment
variable like
OPENCAGE_KEY=yourkeyin.Renviron. Seehelp(oc_config)for alternative ways to set your OpenCage API key.
Now you are ready to turn place names into latitude and longitude coordinates:
library(opencage)
oc_forward_df(placename = "Sarzeau")
<div class="kable-table">
| placename | oc_lat | oc_lng | oc_formatted | |:----------|---------:|--------:|:----------------------| | Sarzeau | 47.52877 | -2.7642 | 56370 Sarzeau, France |
</div>Or turn a set of coordinates into the name and address of the location:
oc_reverse_df(latitude = 51.5034070, longitude = -0.1275920)
<div class="kable-table">
| latitude | longitude | oc_formatted | |---:|---:|:---| | 51.50341 | -0.127592 | 10 Downing Street, Westminster, London, SW1A 2AA, United Kingdom |
</div>But remember, the vignettes are really great! We have:
- “Introduction to
opencage”
vignette("opencage") - “Customise your
query”
vignette("customise_query") - “Output
options”
vignette("output_options")
About OpenCage
The OpenCage API supports forward and reverse geocoding. Sources of OpenCage are open geospatial data including OpenStreetMap, DataScienceToolkit, GeoPlanet, Natural Earth Data, libpostal, GeoNames, and Flickr’s shapefiles plus a whole lot more besides. Refer to the current full list of credits.
Code of Conduct
Please note that this package is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
