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
.gpkg
file or a directory where the file will be saved. If a directory is provided, the file will be saved asDISTRITO.gpkg
inside 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 12 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -73.6546 ymin: -14.08649 xmax: -73.02175 ymax: -13.70798
#> Geodetic CRS: WGS 84
#> id objectid ubigeo ccdd ccpp ccdi nombdep nombprov
#> 1 1 1 030220 03 02 20 APURIMAC ANDAHUAYLAS
#> 2 2 2 030415 03 04 15 APURIMAC AYMARAES
#> 3 3 3 030409 03 04 09 APURIMAC AYMARAES
#> 4 4 4 030214 03 02 14 APURIMAC ANDAHUAYLAS
#> 5 5 5 030206 03 02 06 APURIMAC ANDAHUAYLAS
#> 6 6 6 030404 03 04 04 APURIMAC AYMARAES
#> nombdist capital shape_length shape_area
#> 1 JOSE MARIA ARGUEDAS HUANCABAMBA 0.5703507 0.014648915
#> 2 TINTAY TINTAY 0.7063312 0.011908124
#> 3 LUCRE LUCRE 0.5536897 0.008678206
#> 4 SAN MIGUEL DE CHACCRAMPA CHACCRAMPA 0.4027041 0.007104229
#> 5 HUAYANA HUAYANA 0.5634482 0.007974308
#> 6 CHAPIMARCA CHAPIMARCA 0.6308316 0.017072690
#> geom
#> 1 MULTIPOLYGON (((-73.37071 -...
#> 2 MULTIPOLYGON (((-73.17529 -...
#> 3 MULTIPOLYGON (((-73.24364 -...
#> 4 MULTIPOLYGON (((-73.63057 -...
#> 5 MULTIPOLYGON (((-73.51096 -...
#> 6 MULTIPOLYGON (((-73.04322 -...
# 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 12 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -77.09308 ymin: -12.12351 xmax: -76.80487 ymax: -11.72878
#> Geodetic CRS: WGS 84
#> id objectid ubigeo ccdd ccpp ccdi nombdep nombprov nombdist
#> 1751 1755 1755 150105 15 01 05 LIMA LIMA BREÑA
#> 1752 1756 1756 150106 15 01 06 LIMA LIMA CARABAYLLO
#> 1755 1760 1760 150110 15 01 10 LIMA LIMA COMAS
#> 1756 1761 1761 150111 15 01 11 LIMA LIMA EL AGUSTINO
#> 1758 1763 1763 150113 15 01 13 LIMA LIMA JESUS MARIA
#> 1759 1764 1764 150114 15 01 14 LIMA LIMA LA MOLINA
#> capital shape_length shape_area geom
#> 1751 BREÑA 0.06696340 0.0002661813 MULTIPOLYGON (((-77.05335 -...
#> 1752 CARABAYLLO 0.87284624 0.0258912139 MULTIPOLYGON (((-76.90215 -...
#> 1755 LA LIBERTAD 0.32131581 0.0040586863 MULTIPOLYGON (((-77.05095 -...
#> 1756 EL AGUSTINO 0.27433274 0.0011056739 MULTIPOLYGON (((-76.94638 -...
#> 1758 JESUS MARIA 0.08790282 0.0003599466 MULTIPOLYGON (((-77.03762 -...
#> 1759 LA MOLINA 0.31538511 0.0040373284 MULTIPOLYGON (((-76.94449 -...
# Visualization
maplibre(bounds = lima) |>
add_fill_layer(id = "lima", source = lima, fill_color = "blue", fill_opacity = 0.5)
# }