This function allows you to download the latest version of the geometry and ubigeos corresponding to the official political division of the district boundaries of Peru. For more information, you can visit the following page INEI Spatial Data Portal.
Usage
get_districts(
departamento = NULL,
provincia = NULL,
distrito = NULL,
dsn = NULL,
timeout = 60,
show_progress = TRUE,
quiet = TRUE
)Arguments
- departamento
Character. Name of the level-1 administrative boundary (department) to query. The input is case-insensitive.
- provincia
Character. Name of the level-2 administrative boundary (province) to query. The input is case-insensitive.
- distrito
Character. Name of the level-3 administrative boundary (district) to query. The input is case-insensitive.
- dsn
Character. Path to the output
.gpkgfile or a directory where the file will be saved. If a directory is provided, the file will be saved asDISTRITO.gpkginside it. IfNULL, a temporary file will be created. If the path contains multiple subdirectories, they will be created automatically if they do not exist.- timeout
Seconds. Number of seconds to wait for a response until giving up. Cannot be less than 1 ms. Default is 60.
- show_progress
Logical. Suppress bar progress.
- quiet
Logical. Suppress info message.
Examples
# \donttest{
library(geoidep)
library(mapgl)
# Download all district boundaries (entire country)
dist <- get_districts(show_progress = FALSE)
head(dist)
#> Simple feature collection with 6 features and 8 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -78.13785 ymin: -12.89987 xmax: -74.61245 ymax: -5.82357
#> Geodetic CRS: WGS 84
#> ccdd ccpp ccdi ubigeo nombdist fuente nombdep
#> 1 09 02 03 090203 ANTA V Censo Nacional Economico HUANCAVELICA
#> 2 01 01 01 010101 CHACHAPOYAS V Censo Nacional Economico AMAZONAS
#> 3 01 01 06 010106 CHUQUIBAMBA V Censo Nacional Economico AMAZONAS
#> 4 01 03 01 010301 JUMBILLA V Censo Nacional Economico AMAZONAS
#> 5 01 05 03 010503 COCABAMBA V Censo Nacional Economico AMAZONAS
#> 6 01 01 10 010110 LEIMEBAMBA V Censo Nacional Economico AMAZONAS
#> nombprov geom
#> 1 ACOBAMBA MULTIPOLYGON (((-74.65993 -...
#> 2 CHACHAPOYAS MULTIPOLYGON (((-77.8858 -6...
#> 3 CHACHAPOYAS MULTIPOLYGON (((-77.86211 -...
#> 4 BONGARA MULTIPOLYGON (((-77.84223 -...
#> 5 LUYA MULTIPOLYGON (((-77.99757 -...
#> 6 CHACHAPOYAS MULTIPOLYGON (((-77.74017 -...
# Download all district boundaries for Lima
lima <- get_districts(departamento = 'lima', provincia = 'lima',show_progress = FALSE)
head(lima)
#> Simple feature collection with 6 features and 8 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -77.12635 ymin: -12.14591 xmax: -76.67339 ymax: -11.72878
#> Geodetic CRS: WGS 84
#> ccdd ccpp ccdi ubigeo nombdist fuente nombdep
#> 214 15 01 06 150106 CARABAYLLO V Censo Nacional Economico LIMA
#> 216 15 01 09 150109 CIENEGUILLA V Censo Nacional Economico LIMA
#> 217 15 01 10 150110 COMAS V Censo Nacional Economico LIMA
#> 218 15 01 11 150111 EL AGUSTINO V Censo Nacional Economico LIMA
#> 343 15 01 14 150114 LA MOLINA V Censo Nacional Economico LIMA
#> 495 15 01 25 150125 PUENTE PIEDRA V Censo Nacional Economico LIMA
#> nombprov geom
#> 214 LIMA MULTIPOLYGON (((-76.80487 -...
#> 216 LIMA MULTIPOLYGON (((-76.72596 -...
#> 217 LIMA MULTIPOLYGON (((-77.04905 -...
#> 218 LIMA MULTIPOLYGON (((-76.94638 -...
#> 343 LIMA MULTIPOLYGON (((-76.94449 -...
#> 495 LIMA MULTIPOLYGON (((-77.09076 -...
# Visualization
maplibre(bounds = lima) |>
add_fill_layer(id = "lima", source = lima, fill_color = "blue", fill_opacity = 0.5)
# }