-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
245 lines (191 loc) · 8.14 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
---
output: github_document
bibliography: inst/REFERENCES.bib
link-citations: true
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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%"
)
```
# arcgeocoder <a href="https://dieghernan.github.io/arcgeocoder/"><img src="man/figures/logo.png" alt="arcgeocoder website" align="right" height="139"/></a>
<!-- badges: start -->
[![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)
[![R-hub](https://github.com/dieghernan/arcgeocoder/actions/workflows/rhub.yaml/badge.svg)](https://github.com/dieghernan/arcgeocoder/actions/workflows/rhub.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)
<!-- badges: end -->
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
<https://dieghernan.github.io/arcgeocoder/>
## 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, fig.cap="Example: Food places near the Eiffel Tower"}
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, fig.cap="Example: Food places near the Eiffel Tower using the sf package."}
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