-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslides-geocoding.qmd
160 lines (125 loc) · 2.38 KB
/
slides-geocoding.qmd
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
---
title: Geocoding
---
```{r}
#| echo: false
library(sf)
```
### {tidygeocoder}
![](assets/tidygeocoder.png)
### {tidygeocoder} {.inverse}
### Geocoding a Full Address
```{r}
library(tidyverse)
us_and_uk_head_residences <-
tribble(
~building,
~address,
"White House",
"1600 Pennsylvania Ave NW, Washington, DC 20500 United States",
"Number 10",
"10 Downing St, London SW1A 2AA, United Kingdom"
)
```
### Geocoding a Full Address
```{r}
library(tidygeocoder)
us_and_uk_head_residences |>
geocode(address)
```
### Geocoding a Full Address
```{r}
us_and_uk_head_residences_sf <-
us_and_uk_head_residences |>
geocode(address) |>
st_as_sf(
coords = c("long", "lat"),
crs = 4326
)
```
```{r}
us_and_uk_head_residences_sf
```
---
```{r}
us_and_uk_head_residences_sf |>
mapview::mapview()
```
### Geocoding Services {.inverse}
---
```{r}
us_and_uk_head_residences |>
geocode(
address,
method = "iq"
)
```
::: {.notes}
Both ArcGIS (https://location.arcgis.com/pricing/#geocoding) and Mapbox (https://www.mapbox.com/pricing) are paid for storing addresses
:::
---
```{r}
us_and_uk_head_residences <-
tribble(
~building,
~address,
~city,
~state,
~postal_code,
~country,
"White House",
"1600 Pennsylvania Ave NW",
"Washington",
"DC",
"20500",
"United States",
"Number 10",
"10 Downing St",
"London",
NA,
"SW1A 2AA",
"United Kingdom"
)
```
```{r}
us_and_uk_head_residences |>
geocode(
street = address,
city = city,
state = state,
postalcode = postal_code,
country = country
)
```
::: {.notes}
Doesn't work for Number 10, which is transition to talking about `method` argument
:::
---
```{r}
#| code-line-numbers: "8"
us_and_uk_head_residences |>
geocode(
street = address,
city = city,
state = state,
postalcode = postal_code,
country = country,
method = "iq"
)
```
### Your Turn {.your-turn}
- Create a tibble with the following starter code for your home address:
. . .
```{r}
#| eval: false
#| output-location: default
library(tidyverse)
my_address <-
tribble(
~address,
"Your address goes here"
)
```
### Your Turn {.your-turn}
- Use the {tidygeocoder} package to geocode your address
- Turn the result into an `sf` object with `st_as_sf()` and plot it on a map with `mapview::mapview()` to make sure it worked