Skip to content

Commit 0a8f403

Browse files
committed
Update documentation
1 parent c8d7d37 commit 0a8f403

16 files changed

Lines changed: 627 additions & 291 deletions

β€Ž.vscode/settings.jsonβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
"github",
4646
"Grolemund",
4747
"hijmansa",
48+
"httr",
4849
"knitr",
4950
"langid",
5051
"lightbox",
5152
"magrittr",
53+
"Mapbox",
5254
"mapgl",
5355
"maplibre",
5456
"mercator",

β€ŽR/plot_maplibre.Rβ€Ž

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
library(brandr)
2+
library(checkmate)
3+
library(cli)
4+
library(geobr)
5+
library(httr2)
6+
library(magrittr)
7+
library(mapgl)
8+
library(pmtiles) # github.com/walkerke/pmtiles
9+
10+
plot_maplibre <- function(
11+
file,
12+
column,
13+
values = NULL,
14+
id = hash_md5(runif(1)),
15+
style = carto_style("voyager"),
16+
projection = "mercator",
17+
bounds = NULL,
18+
fill_color = NULL,
19+
tooltip = NULL,
20+
hover_options = NULL,
21+
line_width = NULL,
22+
scroll_zoom = TRUE,
23+
seed = 1998,
24+
...
25+
) {
26+
assert_string(file, pattern = "\\.pmtiles$")
27+
assert_string(column)
28+
assert_vector(values, null.ok = TRUE)
29+
assert_string(id)
30+
assert_string(style, pattern = "\\.json$")
31+
assert_choice(projection, c("mercator", "globe"))
32+
assert_numeric(bounds, len = 4, null.ok = TRUE)
33+
assert_multi_class(fill_color, c("character", "list"), null.ok = TRUE)
34+
assert_string(tooltip, null.ok = TRUE)
35+
assert_list(hover_options, null.ok = TRUE)
36+
assert_number(line_width, lower = 0, null.ok = TRUE)
37+
assert_flag(scroll_zoom)
38+
assert_int(seed)
39+
40+
if (!is_online()) {
41+
cli_abort(
42+
paste0(
43+
"No internet connection detected. ",
44+
"Please check your connection and try again."
45+
)
46+
)
47+
}
48+
49+
if (is.null(values) && is.null(fill_color)) {
50+
cli_abort(
51+
paste0(
52+
"{.strong {col_red('values')}} cannot be {.code NULL} when ",
53+
"{.strong {col_yellow('fill_color')}} is not provided."
54+
)
55+
)
56+
}
57+
58+
pmtiles_metadata <-
59+
file |>
60+
pm_show(tilejson = TRUE)
61+
62+
pmtiles_layer <-
63+
pmtiles_metadata |>
64+
extract2("vector_layers") |>
65+
extract2(1) |>
66+
extract2("id")
67+
68+
if (is.null(bounds)) {
69+
bounds <-
70+
pmtiles_metadata |>
71+
extract2("bounds") |>
72+
unlist()
73+
}
74+
75+
set.seed(seed)
76+
77+
if (is.null(fill_color)) {
78+
fill_color <- match_expr(
79+
column = column,
80+
values = values,
81+
stops = c(
82+
get_brand_color("red"),
83+
get_brand_color("black"),
84+
get_brand_color("yellow")
85+
) |>
86+
sample(
87+
size = values |> length(),
88+
replace = TRUE,
89+
prob = c(7, 1, 2)
90+
),
91+
default = get_brand_color("gray")
92+
)
93+
}
94+
95+
out <-
96+
maplibre(
97+
style = style,
98+
bounds = bounds,
99+
projection = projection,
100+
scrollZoom = scroll_zoom,
101+
...
102+
) |>
103+
add_pmtiles_source(
104+
id = id,
105+
url = file,
106+
source_type = "vector"
107+
) |>
108+
add_fill_layer(
109+
id = paste0(id, "_fill"),
110+
source = id,
111+
source_layer = pmtiles_layer,
112+
fill_color = fill_color,
113+
fill_opacity = 1,
114+
tooltip = tooltip,
115+
hover_options = hover_options
116+
) |>
117+
add_navigation_control() |>
118+
add_screenshot_control() |>
119+
add_fullscreen_control() |>
120+
add_reset_control(
121+
position = "top-right",
122+
animate = TRUE,
123+
duration = NULL
124+
)
125+
126+
if (!is.null(line_width)) {
127+
out <-
128+
out |>
129+
add_line_layer(
130+
id = paste0(id, "_line"),
131+
source = id,
132+
source_layer = pmtiles_layer,
133+
line_color = get_brand_color("white"),
134+
line_width = line_width
135+
)
136+
}
137+
138+
out
139+
}

β€ŽREADME.mdβ€Ž

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@ This repository hosts [PMTiles](https://docs.protomaps.com/pmtilesbr/) files for
1313

1414
[PMTiles](https://docs.protomaps.com/pmtilesbr/) 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.
1515

16-
We plan to move these files to a more permanent hosting solution in the future, but for now, they are available here for public use.
16+
We plan to move these files to a more permanent hosting solution in the future.
17+
18+
## Why Use PMTiles?
19+
20+
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. Shapes with many vertices make rendering slow, bloat file sizes, and generally make life harder. PMTiles addresses this by letting you serve precompiled tiles directly from the web, rather than bundling them into your application.
1721

1822
## Usage
1923

20-
Tiles are available in the [`pmtiles`](pmtiles) directory and are hosted at [cem-usp.github.io/pmtilesbr](https://cem-usp.github.io/pmtilesbr/). For descriptions and metadata for each file, visit the project site: <https://cem-usp.github.io/pmtilesbr>
24+
Tiles are available in the [`pmtiles`](pmtiles) directory and are hosted at [cem-usp.github.io/pmtilesbr](https://cem-usp.github.io/pmtilesbr/). For descriptions and metadata for each file, visit the project site.
2125

2226
To load a file, pass its URL to your application. For example, using [R](https://www.r-project.org/):
2327

2428
```r
29+
library(geobr)
2530
library(magrittr)
2631
library(mapgl)
2732
library(pmtiles) # github.com/walkerke/pmtiles
@@ -31,7 +36,7 @@ library(pmtiles) # github.com/walkerke/pmtiles
3136
pmtiles_file <- file.path(
3237
"https://cem-usp.github.io/pmtilesbr",
3338
"pmtiles",
34-
"geobr-2020-read_state-simplified-min-zoom-2-max-zoom-10.pmtiles"
39+
"geobr-2024-read_municipality-simplified-min-zoom-2-max-zoom-10.pmtiles"
3540
)
3641
```
3742

@@ -56,46 +61,64 @@ pmtiles_bbox <-
5661
unlist()
5762
```
5863

59-
<!-- set.seed(1998) -->
64+
```r
65+
municipality_data <- read_municipality(
66+
year = 2024,
67+
simplified = TRUE,
68+
showProgress = TRUE,
69+
keep_areas_operacionais = FALSE
70+
)
71+
```
6072

6173
```r
74+
set.seed(1998)
75+
6276
scale_fill_mapgl <- match_expr(
63-
column = "code_state",
64-
values = 11:53,
77+
column = "code_muni",
78+
values = municipality_data |>
79+
extract2("code_muni"),
6580
stops = c("#db5025", "#070808", "#efd46a") |>
6681
sample(
67-
length(11:53),
82+
municipality_data |>
83+
extract2("code_muni") |>
84+
length(),
6885
replace = TRUE,
69-
prob = c(7,1, 2)
86+
prob = c(7, 1, 2)
7087
),
7188
default = "#868489"
7289
)
7390
```
7491

7592
```r
7693
pmtiles_bbox |>
77-
maplibre(
94+
maplibre(
7895
bounds = _,
79-
projection = "mercator"
96+
projection = "mercator",
8097
) |>
8198
add_pmtiles_source(
82-
id = "brazil_state_borders",
99+
id = "municipality_borders",
83100
url = pmtiles_file,
84101
source_type = "vector"
85102
) |>
86103
add_fill_layer(
87-
id = "example",
88-
source = "brazil_state_borders",
104+
id = "screen_fill",
105+
source = "municipality_borders",
106+
source_layer = pmtiles_layer,
107+
fill_color = scale_fill_mapgl
108+
) |>
109+
add_line_layer(
110+
id = "screen_outline",
111+
source = "municipality_borders",
89112
source_layer = pmtiles_layer,
90-
fill_color = scale_fill_mapgl,
91-
fill_outline_color = "white"
113+
line_color = "white",
114+
line_width = 0.01
92115
)
93116
```
94117

95-
![Brazil State Boundaries](images/mapgl-brazil-states.png)
118+
![Brazil Municipality Boundaries](images/mapgl-brazil-municipalities.png)
96119

97120
> [!TIP]
98-
> Use [pmtilesbr.io](https://pmtilesbr.io/#url=https%3A%2F%2Fcem-usp.github.io%2Fpmtiles%2Fpmtiles%2Fgeobr-2020-brazil-min-zoom-2-max-zoom-10-simplified.pmtilesbr&map=3.42/-16.49/-48.41) to easily see and inspect each PMTiles file before using.
121+
> Use [pmtilesbr.io](https://pmtiles.io/#url=https%3A%2F%2Fcem-usp.github.io%2Fpmtilesbr%2Fpmtiles%2Fgeobr-2024-read_municipality-simplified-min-zoom-2-max-zoom-10.pmtiles&map=3.87/-15.13/-51.42) to easily inspect each PMTiles file before using.
99122
100123
## Rendering
101124

@@ -104,7 +127,7 @@ The files were processed using the [Quarto](https://quarto.org/) publishing syst
104127
After installing the dependencies mentioned above, follow these steps to render the tiles:
105128

106129
1. **Clone** this repository to your local machine.
107-
2. **Open** the project in your preferred IDE.
130+
2. **Open** the project in your preferred [IDE](https://en.wikipedia.org/wiki/Integrated_development_environment).
108131
3. **Install package dependencies** by running [`renv::restore()`](https://rstudio.github.io/renv/reference/restore.html) in the R console. This will install all required software dependencies.
109132
4. **Open** the Quarto notebooks in the [`qmd`](qmd) directory and run the code as described .
110133

β€Ždocs/index.htmlβ€Ž

Lines changed: 61 additions & 23 deletions
Large diffs are not rendered by default.

β€Ždocs/search.jsonβ€Ž

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,28 @@
44
"href": "index.html",
55
"title": "PMTilesBR",
66
"section": "",
7-
"text": "This website hosts PMTiles files for spatial visualization and analysis in Brazil.\nPMTiles 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.\nWe plan to move these files to a more permanent hosting solution in the future, but for now, they are available here for public use."
7+
"text": "This website hosts PMTiles files for spatial visualization and analysis in Brazil.\nPMTiles 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.\nWe plan to move these files to a more permanent hosting solution in the future.\n\n\n\n\n\n\n\n\n\n\n\nThe map below shows Brazil municipality boundaries as PMTiles, sourced from the geobr R package (Pereira & Goncalves, n.d.).\n\n\n\n\n\n\n\n\n\nClick 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."
8+
},
9+
{
10+
"objectID": "index.html#overview",
11+
"href": "index.html#overview",
12+
"title": "PMTilesBR",
13+
"section": "",
14+
"text": "This website hosts PMTiles files for spatial visualization and analysis in Brazil.\nPMTiles 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.\nWe plan to move these files to a more permanent hosting solution in the future.\n\n\n\n\n\n\n\n\n\n\n\nThe map below shows Brazil municipality boundaries as PMTiles, sourced from the geobr R package (Pereira & Goncalves, n.d.).\n\n\n\n\n\n\n\n\n\nClick 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."
15+
},
16+
{
17+
"objectID": "index.html#why-use-pmtiles",
18+
"href": "index.html#why-use-pmtiles",
19+
"title": "PMTilesBR",
20+
"section": "Why Use PMTiles?",
21+
"text": "Why Use PMTiles?\nWhen working with complex geometries in web mapping applications like Mapbox, MapLibre, and Leaflet, performance can become a real problem. Shapes with many vertices make rendering slow, bloat file sizes, and generally make life harder. PMTiles addresses this by letting you serve precompiled tiles directly from the web, rather than bundling them into your application."
822
},
923
{
1024
"objectID": "index.html#files",
1125
"href": "index.html#files",
1226
"title": "PMTilesBR",
1327
"section": "Files",
14-
"text": "Files\n\n\n\n\n\n\nSee the code repository README to learn more about how the files were created.\n\n\n\n\n\n\n\n\n\nUnless 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.\n\n\n\n\n\ngeobr::read_country()\ngeobr::read_region()\ngeobr::read_state()\ngeobr::read_municipality()\ngeodata::world()\n\n\n\nSourced from the geobr R package (Pereira & Goncalves, n.d.).\nParameters\n\nYear: 2020\nLayer: \"read_country\"\n\nSimplified: TRUE/FALSE\n\nMinimum Zoom: 2\nMaximum Zoom: 10\nFiles\n\ngeobr-2020-read_country-min-zoom-2-max-zoom-10.pmtiles\ngeobr-2020-read_country-simplified-min-zoom-2-max-zoom-10.pmtiles\nView\n\n\n\nSourced from the geobr R package (Pereira & Goncalves, n.d.).\nParameters\n\nYear: 2020\nLayer: \"read_region\"\n\nSimplified: TRUE/FALSE\n\nMinimum Zoom: 2\nMaximum Zoom: 10\nFiles\n\ngeobr-2020-read_region-min-zoom-2-max-zoom-10.pmtiles\ngeobr-2020-read_region-simplified-min-zoom-2-max-zoom-10.pmtiles\nView\n\n\n\nSourced from the geobr R package (Pereira & Goncalves, n.d.).\nParameters\n\nYear: 2020\nLayer: \"read_state\"\n\nSimplified: TRUE/FALSE\n\nMinimum Zoom: 2\nMaximum Zoom: 10\nFiles\n\ngeobr-2020-read_state-min-zoom-2-max-zoom-10.pmtiles\ngeobr-2020-read_state-simplified-min-zoom-2-max-zoom-10.pmtiles\n\n\n\nSourced from the geobr R package (Pereira & Goncalves, n.d.).\nParameters\n\nYear: 2024\nLayer: \"read_municipality\"\n\nSimplified: TRUE/FALSE\n\nMinimum Zoom: 2\nMaximum Zoom: 10\nFiles\n\ngeobr-2024-read_municipality-min-zoom-2-max-zoom-10.pmtiles\ngeobr-2024-read_municipality-simplified-min-zoom-2-max-zoom-10.pmtiles\nView\n\n\n\nSourced from the geodata R package (Hijmans, n.d.).\nParameters\n\nLayer: \"world\"\n\nResolution: 5\nVersion: \"latest\" (created in 2026)\nMinimum Zoom: 2\nMaximum Zoom: 10\nFiles\n\ngadm-world-resolution-5-version-latest-2026-min-zoom-2-max-zoom-10.pmtiles\nView"
28+
"text": "Files\n\n\n\n\n\n\nSee the code repository README to learn more about how the files were created.\n\n\n\n\n\n\n\n\n\nUnless 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.\n\n\n\n\n\ngeobr::read_country()\ngeobr::read_region()\ngeobr::read_state()\ngeobr::read_municipality()\ngeodata::world()\n\n\n\nSourced from the geobr R package (Pereira & Goncalves, n.d.).\nParameters\n\nYear: 2020\nLayer: \"read_country\"\n\nSimplified: TRUE/FALSE\n\nMinimum Zoom: 2\nMaximum Zoom: 10\nFiles\n\ngeobr-2020-read_country-min-zoom-2-max-zoom-10.pmtiles\ngeobr-2020-read_country-simplified-min-zoom-2-max-zoom-10.pmtiles\nView\n\n\n\n\n\n\n\n\n\nSourced from the geobr R package (Pereira & Goncalves, n.d.).\nParameters\n\nYear: 2020\nLayer: \"read_region\"\n\nSimplified: TRUE/FALSE\n\nMinimum Zoom: 2\nMaximum Zoom: 10\nFiles\n\ngeobr-2020-read_region-min-zoom-2-max-zoom-10.pmtiles\ngeobr-2020-read_region-simplified-min-zoom-2-max-zoom-10.pmtiles\nView\n\n\n\n\n\n\n\n\n\nSourced from the geobr R package (Pereira & Goncalves, n.d.).\nParameters\n\nYear: 2020\nLayer: \"read_state\"\n\nSimplified: TRUE/FALSE\n\nMinimum Zoom: 2\nMaximum Zoom: 10\nFiles\n\ngeobr-2020-read_state-min-zoom-2-max-zoom-10.pmtiles\ngeobr-2020-read_state-simplified-min-zoom-2-max-zoom-10.pmtiles\nView\n\n\n\n\n\n\n\n\n\nSourced from the geobr R package (Pereira & Goncalves, n.d.).\nParameters\n\nYear: 2024\nLayer: \"read_municipality\"\n\nSimplified: TRUE/FALSE\n\nMinimum Zoom: 2\nMaximum Zoom: 10\nFiles\n\ngeobr-2024-read_municipality-min-zoom-2-max-zoom-10.pmtiles\ngeobr-2024-read_municipality-simplified-min-zoom-2-max-zoom-10.pmtiles\nView\n\n\n\n\n\n\n\n\n\nSourced from the geodata R package (Hijmans, n.d.).\nParameters\n\nLayer: \"world\"\n\nResolution: 5\nVersion: \"latest\" (created in 2026)\nMinimum Zoom: 0\nMaximum Zoom: 6/10\nFiles\n\ngadm-world-resolution-5-version-latest-2026-min-zoom-0-max-zoom-6.pmtiles\ngadm-world-resolution-5-version-latest-2026-min-zoom-0-max-zoom-10.pmtiles\nView"
1529
},
1630
{
1731
"objectID": "index.html#citation",

docs/site_libs/bootstrap/bootstrap-0d9958c3282d917ed745a8317d7b2b78.min.css renamed to docs/site_libs/bootstrap/bootstrap-6a1a623381677fa17a8e9c61da79323c.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/site_libs/bootstrap/bootstrap-dark-d7a637c0abd67513a13cfd2258c56698.min.css renamed to docs/site_libs/bootstrap/bootstrap-dark-50e2de44b40f650d66b0f6943db2ff74.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ždocs/sitemap.xmlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
33
<url>
44
<loc>https://cem-usp.github.io/pmtilesbr/index.html</loc>
5-
<lastmod>2026-03-22T00:44:42.474Z</lastmod>
5+
<lastmod>2026-03-22T03:17:00.732Z</lastmod>
66
</url>
77
</urlset>
214 KB
Loading

0 commit comments

Comments
Β (0)