-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.qmd
More file actions
260 lines (212 loc) · 8.68 KB
/
Copy pathindex.qmd
File metadata and controls
260 lines (212 loc) · 8.68 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
---
format: gfm
bibliography: inst/REFERENCES.bib
link-citations: true
nocite: '@*'
default-image-extension: ''
tbl-cap-location: bottom
knitr:
opts_chunk:
collapse: true
comment: "#>"
warning: false
message: false
dev: "ragg_png"
tidy: "styler"
fig.path: "man/figures/README-"
dpi: 150
out.width: "100%"
---
<!-- index.md is generated from index.qmd. Please edit that file -->
# geobounds <a href="https://dieghernan.github.io/geobounds/"><img src="man/figures/logo.png" alt="geobounds website" align="right" height="139"/></a>
<!-- badges: start -->
[](https://CRAN.R-project.org/package=geobounds)
[](https://cran.r-project.org/web/checks/check_results_geobounds.html)
[](https://CRAN.R-project.org/package=geobounds)
[](https://dieghernan.r-universe.dev/geobounds)
[](https://github.com/dieghernan/geobounds/actions/workflows/check-full.yaml)
[](https://app.codecov.io/gh/dieghernan/geobounds)
[](https://www.codefactor.io/repository/github/dieghernan/geobounds)
[](https://doi.org/10.32614/CRAN.package.geobounds)
[](https://www.repostatus.org/#active)
<!-- badges: end -->
## Why this package?
The **geobounds** package provides an **R**-friendly interface for downloading
administrative boundaries from
[**geoBoundaries**](https://www.geoboundaries.org/), the Global Database of
Political Administrative Boundaries. With **geobounds**, you can:
- Download individual country boundaries and global composite boundaries from
**geoBoundaries**.
- Use **tidyverse** and **sf** workflows in **R** to map, analyze and join
administrative boundaries with your own data.
- Work in an open-data context where attribution to **geoBoundaries** is
required.
In short, if you work with administrative boundaries in **R**, **geobounds**
simplifies downloading, cache management and integration with spatial data
workflows.
```{=html}
<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container"><i class="callout-icon"></i></div>
<div class="callout-title-container flex-fill">Important</div>
</div>
<div class="callout-body-container callout-body">
<p><a href="https://www.geoboundaries.org/index.html#usage" class="external-link">Attribution</a> is required when sharing
<strong>geoBoundaries</strong> boundaries or derived products.</p>
</div>
</div>
```
## Installation
Install **geobounds** from
[**CRAN**](https://CRAN.R-project.org/package=geobounds):
```{r}
#| eval: false
install.packages("geobounds")
```
::: pkgdown-devel
Check the documentation for the development version at
<https://dieghernan.github.io/geobounds/dev/>
You can install the development version of **geobounds** with:
```{r}
#| eval: false
# install.packages("pak")
pak::pak("dieghernan/geobounds")
```
Alternatively, you can install **geobounds** from
[**r-universe**](https://dieghernan.r-universe.dev/geobounds):
```{r}
#| eval: false
# Install geobounds.
install.packages(
"geobounds",
repos = c(
"https://dieghernan.r-universe.dev",
"https://cloud.r-project.org"
)
)
```
:::
## Example usage
```{r}
#| label: simple_plot
#| fig-cap: "ADM1, ADM2 and ADM3 boundaries for Sri Lanka."
library(geobounds)
sri_lanka_adm1 <- gb_get_adm1("Sri Lanka")
sri_lanka_adm2 <- gb_get_adm2("Sri Lanka")
sri_lanka_adm3 <- gb_get_adm3("Sri Lanka")
library(sf)
library(dplyr)
library(ggplot2)
ggplot(sri_lanka_adm3) +
geom_sf(fill = "#DFDFDF", color = "white") +
geom_sf(data = sri_lanka_adm2, fill = NA, color = "#F0B323") +
geom_sf(data = sri_lanka_adm1, fill = NA, color = "black") +
labs(
caption = paste(
"Sources: geoBoundaries, OpenStreetMap and Wambacher,",
"license: ODbL 1.0"
)
) +
theme_void()
```
## Release types
**geoBoundaries** provides three release types with different data sources,
validation processes and licensing terms:
- **gbOpen**: Openly licensed boundaries suitable for most uses. The original
license varies by boundary and may include ODbL, CC BY or CC BY-SA terms.
- **gbHumanitarian**: Boundaries mirrored from UN OCHA. Check the current
metadata for the applicable source, license and attribution terms.
- **gbAuthoritative**: Boundaries mirrored from UN SALB and verified through
in-country processes. These boundaries are restricted to non-commercial use.
Use the `release_type` argument to request a specific release type, for example,
`gb_get_adm1("Sri Lanka", release_type = "gbHumanitarian")`.
For coverage and boundary metadata by release type, see the **geobounds**
articles.
## Advanced usage
Map the highest available ADM level in **geoBoundaries** by country:
```{r}
#| label: map-coverage
#| fig-cap: "Highest available gbOpen ADM level by country."
library(geobounds)
library(ggplot2)
library(dplyr)
world <- gb_get_world()
max_lvl <- gb_get_max_adm_lvl(release_type = "gbOpen")
world_max <- world |>
mutate(boundaryISO = shapeGroup) |>
left_join(max_lvl) |>
mutate(max_lvl = factor(maxBoundaryType, levels = 0:5))
pal <- c("#0e221b", "#0f4a38", "#0b6e4f", "#719384", "#b9975a", "#936e28")
names(pal) <- levels(world_max$max_lvl)
ggplot(world_max) +
geom_sf(fill = "#e5e5e5", color = "#e5e5e5") +
geom_sf(aes(fill = max_lvl), color = "transparent") +
scale_fill_manual(values = pal, na.translate = FALSE, drop = FALSE) +
guides(fill = guide_legend(direction = "horizontal", nrow = 1)) +
coord_sf(expand = TRUE, crs = "+proj=robin") +
theme_void() +
theme(
plot.background = element_rect(fill = "white", color = NA),
text = element_text(family = "sans", face = "bold"),
legend.position = "bottom",
legend.title.position = "top",
legend.title = element_text(size = rel(0.75), face = "plain"),
legend.text = element_text(size = rel(1)),
legend.text.position = "right",
legend.key.height = unit(1, "line"),
legend.key.width = unit(1, "line"),
plot.caption = element_text(
size = rel(0.7),
margin = margin(r = 4)
)
) +
labs(
fill = "gbOpen: Highest available ADM level",
caption = "Source: geoBoundaries (CGAZ and gbOpen metadata)"
)
```
## Documentation and resources
- Visit the **pkgdown** site for full documentation:
<https://dieghernan.github.io/geobounds/>
- Articles on **geoBoundaries** release types:
- [gbOpen](https://dieghernan.github.io/geobounds/articles/gbopen.html)
- [gbHumanitarian](https://dieghernan.github.io/geobounds/articles/gbhumanitarian.html)
- [gbAuthoritative](https://dieghernan.github.io/geobounds/articles/gbauthoritative.html)
- Explore the **geoBoundaries** homepage: <https://www.geoboundaries.org/>
- Read the original paper describing the **geoBoundaries** dataset
[@10.1371/journal.pone.0231866].
- Report issues or contribute on
[**GitHub**](https://github.com/dieghernan/geobounds).
## License
The **geobounds** software is released under the [MIT
license](https://opensource.org/license/mit). This license does not cover
boundaries downloaded through the package or figures derived from those
boundaries.
Each boundary retains the original license reported by **geoBoundaries**. Before
reusing or redistributing boundaries, use `gb_get_metadata()` to check
`boundaryLicense`, `licenseDetail`, `licenseSource`, `boundarySource` and
`boundarySourceURL`. Attribute **geoBoundaries** and the original providers,
include the applicable license and indicate modifications when required.
`gbAuthoritative` contains UN SALB boundaries restricted to non-commercial use.
## Acknowledgments
- Thanks to the **geoBoundaries** team and the [William & Mary
geoLab](https://sites.google.com/view/wmgeolab/) for creating and maintaining
the dataset.
- Thanks to the **R** package community and all **geobounds** contributors.
- If you use **geobounds** with **geoBoundaries** boundaries, please cite both.
## Citation
```{r}
#| label: cit
#| echo: false
#| results: asis
print(citation("geobounds")[1], style = "html")
```
A **BibTeX** entry for **LaTeX** users:
```{r}
#| echo: false
#| comment: ''
toBibtex(citation("geobounds")[1])
```
## References