-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.qmd
More file actions
558 lines (426 loc) · 13.1 KB
/
index.qmd
File metadata and controls
558 lines (426 loc) · 13.1 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
```{r}
#| label: setup
#| include: false
library(here)
here("R", ".setup.R") |> source()
```
## Overview {.first-h2}
:::: {style="display: grid; grid-template-columns: 1fr auto; gap: 1.5rem; align-items: start;"}
::: {}
This website hosts [PMTiles](https://docs.protomaps.com/pmtiles/) files for spatial visualization and analysis in Brazil.
[PMTiles](https://docs.protomaps.com/pmtiles/) is a format for storing and serving tiled geospatial data. It is designed to be efficient, scalable, and easy to use, making it ideal for web applications and data visualization.
We plan to move these files to a more permanent hosting solution in the future.
:::
::: {style="margin-top: -1rem;"}
{width="120"}
:::
::::
::: {.callout-note}
The map below shows Brazil municipality boundaries as PMTiles, sourced from the [`geobr`](https://ipeagit.github.io/geobr/) R package [@pereirab].
:::
::: {.callout-tip}
*Click and drag* to pan. *Right-click and drag* to rotate. *Hover* over a shape to see the municipality name. *Use the controls* to zoom, take a screenshot, or view in fullscreen.
:::
```{r}
#| label: Set the Environment
#| include: false
library(brandr)
library(checkmate)
library(cli)
library(dplyr)
library(fs)
library(geobr)
library(geodata)
library(httr2)
library(magrittr)
library(mapgl)
library(pmtiles) # github.com/walkerke/pmtiles
library(sf)
```
```{r}
#| include: false
here("R", "plot_maplibre.R") |> source()
```
```{r}
#| include: false
raw_data_dir <- here("data-raw")
data_dir <- here("pmtiles")
```
```{r}
#| include: false
for (i in c(data_dir, raw_data_dir)) {
if (!dir_exists(i)) {
dir_create(i, recurse = TRUE)
}
}
```
```{r}
#| label: column screen
#| include: false
file <- file.path(
"https://cem-usp.github.io/pmtilesbr",
"pmtiles",
"geobr-2024-read_municipality-simplified-min-zoom-2-max-zoom-10.pmtiles"
)
```
```{r}
#| include: false
municipality_data <- read_municipality(
year = 2024,
simplified = TRUE,
showProgress = FALSE,
keep_areas_operacionais = FALSE
)
```
```{r}
#| include: false
municipality_data |> glimpse()
```
```{r}
#| column: screen
#| echo: false
file |>
plot_maplibre(
column = "code_muni",
values = municipality_data |>
extract2("code_muni"),
tooltip = "name_muni",
hover_options = list(
fill_color = get_brand_color("gray-l50"),
fill_opacity = 1
),
line_width = 0.01,
scroll_zoom = FALSE,
seed = 1998
)
```
## Why Use PMTiles?
When working with complex geometries in web mapping applications like [Mapbox](https://www.mapbox.com/), [MapLibre](https://maplibre.org/), and [Leaflet](https://leafletjs.com/), performance can become [a real problem](https://walker-data.com/posts/pmtiles-texas-blocks/). Shapes with many vertices make rendering slow, bloat file sizes, and generally make life harder. [PMTiles](https://docs.protomaps.com/pmtiles/) addresses this by letting you serve precompiled tiles directly from the web, rather than bundling them into your application.
## Files
::: {.callout-note}
See the code repository [README](https://github.com/cem-usp/pmtilesbr#pmtilesbr-) to learn more about how the files were created.
:::
::: {.callout-tip}
Unless you really need to, use the simplified versions of the files, which are smaller and faster to load. The non-simplified versions are available for those who need the highest level of detail, but they may not be necessary for most applications.
:::
::: {.panel-tabset .map-tabset}
## `geobr::read_country()`
Sourced from the [`geobr`](https://ipeagit.github.io/geobr/) R package [@pereirab].
#### Parameters
- Year: 2020
- Layer: `"read_country"`
- Simplified: `TRUE`/`FALSE`
- Minimum Zoom: 2
- Maximum Zoom: 10
#### Files
- [`geobr-2020-read_country-min-zoom-2-max-zoom-10.pmtiles`](pmtiles/geobr-2020-read_country-min-zoom-2-max-zoom-10.pmtiles)
- [`geobr-2020-read_country-simplified-min-zoom-2-max-zoom-10.pmtiles`](pmtiles/geobr-2020-read_country-simplified-min-zoom-2-max-zoom-10.pmtiles)
#### View
```{r}
#| label: geobr::read_country()
#| include: false
file <- file.path(
"https://cem-usp.github.io/pmtilesbr",
"pmtiles",
"geobr-2020-read_country-simplified-min-zoom-2-max-zoom-10.pmtiles"
)
```
```{r}
#| include: false
#| eval: false
pm_show(file, tilejson = TRUE)
```
```{r}
#| echo: false
file |>
plot_maplibre(
column = "code_muni",
fill_color = get_brand_color("red"),
line_width = 1
)
```
## `geobr::read_region()`
Sourced from the [`geobr`](https://ipeagit.github.io/geobr/) R package [@pereirab].
#### Parameters
- Year: 2020
- Layer: `"read_region"`
- Simplified: `TRUE`/`FALSE`
- Minimum Zoom: 2
- Maximum Zoom: 10
#### Files
- [`geobr-2020-read_region-min-zoom-2-max-zoom-10.pmtiles`](pmtiles/geobr-2020-read_region-min-zoom-2-max-zoom-10.pmtiles)
- [`geobr-2020-read_region-simplified-min-zoom-2-max-zoom-10.pmtiles`](pmtiles/geobr-2020-read_region-simplified-min-zoom-2-max-zoom-10.pmtiles)
#### View
```{r}
#| label: geobr::read_region()
#| include: false
file <- file.path(
"https://cem-usp.github.io/pmtilesbr",
"pmtiles",
"geobr-2020-read_region-simplified-min-zoom-2-max-zoom-10.pmtiles"
)
```
```{r}
#| include: false
#| eval: false
pm_show(file, tilejson = TRUE)
```
```{r}
#| include: false
region_data <- read_region(
year = 2020,
simplified = TRUE,
showProgress = FALSE
)
```
```{r}
#| include: false
region_data |> glimpse()
```
```{r}
#| echo: false
file |>
plot_maplibre(
column = "code_region",
values = region_data |>
extract2("code_region"),
tooltip = "name_region_en",
hover_options = list(
fill_color = get_brand_color("gray-l50"),
fill_opacity = 1
),
line_width = 1,
seed = 2013
)
```
## `geobr::read_state()`
Sourced from the [`geobr`](https://ipeagit.github.io/geobr/) R package [@pereirab].
#### Parameters
- Year: 2020
- Layer: `"read_state"`
- Simplified: `TRUE`/`FALSE`
- Minimum Zoom: 2
- Maximum Zoom: 10
#### Files
- [`geobr-2020-read_state-min-zoom-2-max-zoom-10.pmtiles`](pmtiles/geobr-2020-read_state-min-zoom-2-max-zoom-10.pmtiles)
- [`geobr-2020-read_state-simplified-min-zoom-2-max-zoom-10.pmtiles`](pmtiles/geobr-2020-read_state-simplified-min-zoom-2-max-zoom-10.pmtiles)
#### View
```{r}
#| label: geobr::read_state()
#| include: false
file <- file.path(
"https://cem-usp.github.io/pmtilesbr",
"pmtiles",
"geobr-2020-read_state-simplified-min-zoom-2-max-zoom-10.pmtiles"
)
```
```{r}
#| include: false
#| eval: false
pm_show(file, tilejson = TRUE)
```
```{r}
#| include: false
state_data <- read_state(
year = 2020,
simplified = TRUE,
showProgress = FALSE
)
```
```{r}
#| include: false
state_data |> glimpse()
```
```{r}
#| echo: false
file |>
plot_maplibre(
column = "code_state",
values = state_data |>
extract2("code_state"),
tooltip = "name_state",
hover_options = list(
fill_color = get_brand_color("gray-l50"),
fill_opacity = 1
),
line_width = 1,
seed = 2000
)
```
## `geobr::read_municipality()`
Sourced from the [`geobr`](https://ipeagit.github.io/geobr/) R package [@pereirab].
#### Parameters
- Year: 2024
- Layer: `"read_municipality"`
- Simplified: `TRUE`/`FALSE`
- Minimum Zoom: 2
- Maximum Zoom: 10
#### Files
- [`geobr-2024-read_municipality-min-zoom-2-max-zoom-10.pmtiles`](pmtiles/geobr-2024-read_municipality-min-zoom-2-max-zoom-10.pmtiles)
- [`geobr-2024-read_municipality-simplified-min-zoom-2-max-zoom-10.pmtiles`](pmtiles/geobr-2024-read_municipality-simplified-min-zoom-2-max-zoom-10.pmtiles)
#### View
```{r}
#| label: geobr::read_municipality()
#| include: false
file <- file.path(
"https://cem-usp.github.io/pmtilesbr",
"pmtiles",
"geobr-2024-read_municipality-simplified-min-zoom-2-max-zoom-10.pmtiles"
)
```
```{r}
#| include: false
#| eval: false
pm_show(file, tilejson = TRUE)
```
```{r}
#| eval: false
#| include: false
municipality_data <- read_municipality(
year = 2024,
simplified = TRUE,
showProgress = FALSE,
keep_areas_operacionais = FALSE
)
```
```{r}
#| include: false
municipality_data |> glimpse()
```
```{r}
#| echo: false
file |>
plot_maplibre(
column = "code_muni",
values = municipality_data |>
extract2("code_muni"),
tooltip = "name_muni",
hover_options = list(
fill_color = get_brand_color("gray-l50"),
fill_opacity = 1
),
line_width = 0.01,
seed = 1998
)
```
## `geodata::world()`
Sourced from the [`geodata`](https://rspatial.github.io/geodata/) R package [@hijmans2024].
#### Parameters
- Layer: `"world"`
- Resolution: 5
- Level: 0
- Version: `"latest"` (created in 2026)
- Minimum Zoom: 0
- Maximum Zoom: 6/10
#### Files
- [`gadm-world-resolution-5-level-0-version-latest-min-zoom-0-max-zoom-6.pmtiles`](pmtiles/gadm-world-resolution-5-level-0-version-latest-min-zoom-0-max-zoom-6.pmtiles)
- [`gadm-world-resolution-5-level-0-version-latest-min-zoom-0-max-zoom-10.pmtiles`](pmtiles/gadm-world-resolution-5-level-0-version-latest-min-zoom-0-max-zoom-10.pmtiles)
#### View
```{r}
#| label: geodata::world()
#| include: false
file <- file.path(
"https://cem-usp.github.io/pmtilesbr",
"pmtiles",
paste0(
"gadm-world-resolution-5-level-0-version-latest-",
"min-zoom-0-max-zoom-6.pmtiles"
)
)
```
```{r}
#| include: false
#| eval: false
pm_show(file, tilejson = TRUE)
```
```{r}
#| include: false
world_data <- world(
resolution = 5,
level = 0,
path = raw_data_dir,
version = "latest"
) |>
st_as_sf()
```
```{r}
#| include: false
world_data |> glimpse()
```
```{r}
#| echo: false
file |>
plot_maplibre(
column = "GID_0",
values = world_data |>
extract2("GID_0"),
bounds = c(-175, -75, 180, 85),
tooltip = "NAME_0",
hover_options = list(
fill_color = get_brand_color("gray-l50"),
fill_opacity = 1
),
line_width = 0.5,
seed = 2025
)
```
:::
## Citation
::: {.callout-important}
When using this data, you must also cite the original data sources.
:::
To cite this work, please use the following format:
Vartanian, D., Fernandes, C. N., & Giannotti, M. A. (2026). *PMTilesBR: Tiled geospatial data for Brazil* \[Computer software\]. Center for Metropolitan Studies, University of São Paulo. <https://doi.org/10.5281/zenodo.19157888>
A BibLaTeX entry for LaTeX users is:
```latex
@software{vartanian2026,
title = {PMTilesBR: Tiled geospatial data for Brazil},
author = {{Daniel Vartanian} and {Camila Nastari Fernandes} and {Mariana Abrantes Giannotti}},
year = {2026},
address = {São Paulo},
institution = {Center for Metropolitan Studies, University of São Paulo},
langid = {en},
doi = {https://doi.org/10.5281/zenodo.19157888}
}
```
## License
::: {style="text-align: left;"}
[](https://www.gnu.org/licenses/gpl-3.0)
[](https://creativecommons.org/licenses/by-nc-sa/4.0/)
:::
::: {.callout-important}
The original data sources may be subject to their own licensing terms and conditions.
:::
The code in this repository is licensed under the [GNU General Public License Version 3](https://www.gnu.org/licenses/gpl-3.0), while the files are available under the [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/) license.
```
Copyright (C) 2026 Center for Metropolitan Studies
The code in this report is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
```
## Acknowledgments
:::: {.columns style="display: flex; align-items: center; margin: 1em; padding-top: 0em;"}
::: {.column style="width: 30%; text-align: center;"}
[{width="190"}](https://centrodametropole.fflch.usp.br)
:::
::: {.column style="width: 70%; display: flex; align-items: center;"}
This work was developed with support from the Center for Metropolitan Studies ([CEM](https://centrodametropole.fflch.usp.br)) based at the School of Philosophy, Letters and Human Sciences ([FFLCH](https://www.fflch.usp.br/)) of the University of São Paulo ([USP](https://usp.br/)) and at the Brazilian Center for Analysis and Planning ([CEBRAP](https://cebrap.org.br/)).
:::
::::
:::: {.columns style="display: flex; align-items: center; margin: 1em; padding-top: 0em;"}
::: {.column style="width: 30%; text-align: center;"}
[{width="160"}](https://fapesp.br/)
:::
::: {.column style="width: 70%; display: flex; align-items: center;"}
This study was financed, in part, by the São Paulo Research Foundation ([FAPESP](https://fapesp.br/)), Brazil. Process Number [2025/17879-2](https://bv.fapesp.br/en/bolsas/231507/geospatial-data-science-applied-to-food-policies/).
:::
::::
## References {.unnumbered}
::: {#refs}
:::