Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dieghernan/arcgeocoder
Lite interface for geocoding with ArcGIS REST API
https://github.com/dieghernan/arcgeocoder
api-rest arcgis arcgis-api cran-r geocoding gis r r-package reverse-geocoding
Last synced: 2 months ago
JSON representation
Lite interface for geocoding with ArcGIS REST API
- Host: GitHub
- URL: https://github.com/dieghernan/arcgeocoder
- Owner: dieghernan
- License: other
- Created: 2024-01-05T15:54:29.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-09-11T13:46:18.000Z (3 months ago)
- Last Synced: 2024-09-21T22:41:35.784Z (3 months ago)
- Topics: api-rest, arcgis, arcgis-api, cran-r, geocoding, gis, r, r-package, reverse-geocoding
- Language: R
- Homepage: https://dieghernan.github.io/arcgeocoder/
- Size: 25.1 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Citation: CITATION.cff
- Codemeta: codemeta.json
Awesome Lists containing this project
README
---
output: github_document
bibliography: inst/REFERENCES.bib
link-citations: true
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
warning = FALSE,
message = FALSE,
dev = "ragg_png",
tidy = "styler",
fig.path = "man/figures/README-",
dpi = 120,
out.width = "100%"
)
```[![CRAN
status](https://www.r-pkg.org/badges/version/arcgeocoder)](https://CRAN.R-project.org/package=arcgeocoder)
[![CRAN
results](https://badges.cranchecks.info/worst/arcgeocoder.svg)](https://cran.r-project.org/web/checks/check_results_arcgeocoder.html)
[![Downloads](https://cranlogs.r-pkg.org/badges/arcgeocoder)](https://CRAN.R-project.org/package=arcgeocoder)
[![R-CMD-check](https://github.com/dieghernan/arcgeocoder/actions/workflows/check-full.yaml/badge.svg)](https://github.com/dieghernan/arcgeocoder/actions/workflows/check-full.yaml)
[![codecov](https://codecov.io/gh/dieghernan/arcgeocoder/graph/badge.svg)](https://app.codecov.io/gh/dieghernan/arcgeocoder)
[![r-universe](https://dieghernan.r-universe.dev/badges/arcgeocoder)](https://dieghernan.r-universe.dev/arcgeocoder)
[![CodeFactor](https://www.codefactor.io/repository/github/dieghernan/arcgeocoder/badge)](https://www.codefactor.io/repository/github/dieghernan/arcgeocoder)
[![Project Status: Active -- The project has reached a stable, usable state and
is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![DOI](https://img.shields.io/badge/DOI-10.32614/CRAN.package.arcgeocoder-blue)](https://doi.org/10.32614/CRAN.package.arcgeocoder)
[![status](https://tinyverse.netlify.app/status/arcgeocoder)](https://CRAN.R-project.org/package=arcgeocoder)The goal of **arcgeocoder** is to provide a light interface for geocoding
addresses and reverse geocoding location trough the [ArcGIS REST API Geocoding
Service](https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm).Full site with examples and vignettes on
## Why **arcgeocoder**?
**arcgeocoder** is a package that provides a lightweight interface for geocoding
and reverse geocoding with the ArcGIS REST API service. The goal of
**arcgeocoder** is to access the ArcGIS REST API with fewer dependencies, such
as **curl**. In some situations, **curl** may not be available or accessible, so
**arcgeocoder** uses base functions to overcome this limitation.The interface of **apigeocoder** is built with the aim of easing the access to
all the features provided by the API. The API endpoints used by **arcgeocoder**
are `findAddressCandidates` and `reverseGeocode`, which can be accessed
[**without**]{.underline} the need for an [**API key**]{.underline}.## Recommended packages
There are other packages much more complete and mature than **arcgeocoder**,
that presents similar features:- [**tidygeocoder**](https://jessecambon.github.io/tidygeocoder/)
[@R-tidygeocoder]. Allows to interface with ArcGIS, Nominatim
(OpenStreetMaps), Google, TomTom, Mapbox, etc. for geocoding and reverse
geocoding.
- [**nominatimlite**](https://dieghernan.github.io/nominatimlite/)
[@R-nominatimlite]. Similar to **arcgeocoder** but using data from
OpenStreetMaps trough the [Nominatim
API](https://nominatim.org/release-docs/latest/) service.## Installation
Install **arcgeocoder** from
[**CRAN**](https://CRAN.R-project.org/package=arcgeocoder) with:```{r, eval=FALSE}
install.packages("arcgeocoder")
```You can install the developing version of **arcgeocoder** with:
```{r, eval=FALSE}
remotes::install_github("dieghernan/arcgeocoder")
```Alternatively, you can install **arcgeocoder** using the
[r-universe](https://dieghernan.r-universe.dev/arcgeocoder):```{r, eval=FALSE}
# Install arcgeocoder in R:
install.packages("arcgeocoder",
repos = c(
"https://dieghernan.r-universe.dev",
"https://cloud.r-project.org"
)
)
```## Usage
### Geocoding and reverse geocoding
*Note: examples adapted from **tidygeocoder** package*
In this first example we will geocode a few addresses using the `arc_geo()`
function. Note that **arcgeocoder** works straight away, and you don't need to
provide any API key to start geocoding!```{r example}
library(arcgeocoder)
library(dplyr)# create a dataframe with addresses
some_addresses <- tribble(
~name, ~addr,
"White House", "1600 Pennsylvania Ave NW, Washington, DC",
"Transamerica Pyramid", "600 Montgomery St, San Francisco, CA 94111",
"Willis Tower", "233 S Wacker Dr, Chicago, IL 60606"
)# geocode the addresses
lat_longs <- arc_geo(some_addresses$addr, lat = "latitude", long = "longitude")
```Only a few fields are returned from the geocoder service in this example, but
`full_results = TRUE` can be used to return all of the data from the geocoder
service.```{r echo=FALSE}
knitr::kable(lat_longs)
```To perform reverse geocoding (obtaining addresses from geographic coordinates),
we can use the `arc_reverse_geo()` function. The arguments are similar to the
`arc_geo()` function, but now we specify the input data columns with the `x` and
`y` arguments. The dataset used here is from the geocoder query above. The
single line address is returned in a column named by the `address`.```{r}
reverse <- arc_reverse_geo(
x = lat_longs$longitude,
y = lat_longs$latitude,
address = "address_found"
)
``````{r, echo = FALSE}
knitr::kable(reverse)
```It is possible also to search for specific locations within or near a reference
are or location using [category
filtering](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-category-filtering.htm).
See more information in the documentation of the data base `arc_categories`.In the following example we would look for POIs related with food (i.e.
Restaurants, Coffee Shops, Bakeries) near the Eiffel Tower in France.```{r eiffel}
library(ggplot2) # For plotting# Step 1: Locate Eiffel Tower, using multifield query
eiffel_tower <- arc_geo_multi(
address = "Tour Eiffel",
city = "Paris",
countrycode = "FR",
langcode = "FR",
custom_query = list(outFields = "LongLabel")
)# Display results
eiffel_tower %>%
select(lon, lat, LongLabel)# Use lon,lat to boots the search and using category = Food
food_eiffel <- arc_geo_categories("Food",
x = eiffel_tower$lon,
y = eiffel_tower$lat,
limit = 50, full_results = TRUE
)# Plot by Food Type
ggplot(eiffel_tower, aes(x, y)) +
geom_point(shape = 17, color = "red", size = 4) +
geom_point(data = food_eiffel, aes(x, y, color = Type)) +
labs(
title = "Food near the Eiffel Tower",
subtitle = "Using arcgecoder",
color = "Type of place",
x = "",
y = "",
caption = "Data from ArcGIS REST API services"
)
```### **arcgeocoder** and **r-spatial**
It is straightforward to convert the results of **arcgeocoder** to an **sf**
object (geospatial format):```{r eiffel_sf}
library(sf)food_eiffel_sf <- st_as_sf(food_eiffel,
coords = c("lon", "lat"),
# The CRS of the resulting coords is here
crs = eiffel_tower$wkid
)food_eiffel_sf
ggplot(food_eiffel_sf) +
geom_sf(aes(color = Type)) +
coord_sf(crs = 3035)
```See additional articles showing how **arcgeocoder** can be use in combination
with **leaflet** to create [dynamic
maps](https://dieghernan.github.io/arcgeocoder/articles/ex_leaflet.html) and
with **sf** and **terra** to create [static
maps](https://dieghernan.github.io/arcgeocoder/articles/ex_static.html).## Citation
```{r echo=FALSE, results='asis'}
print(citation("arcgeocoder"), style = "html")
```A BibTeX entry for LaTeX users is
```{r echo=FALSE, comment=""}
toBibtex(citation("arcgeocoder"))
```## References