library(tidyverse)
library(dplyr)
library(ggplot2)
library(sf)
list.files()
[1] "Antioquia.nb.html"
[2] "Antioquia.Rmd"
[3] "EVA.ANTIOQUIA.csv"
[4] "mapantioquia.nb.html"
[5] "mapantioquia.Rmd"
[6] "MGN_MPIO_POLITICO.shp"
[7] "MGN_MPIO_POLITICO.shp.xml"
mun_antioquia <- sf::st_read("C:/Users/hinca/Documents/(A) Hinca/UNAL/Semestre 5/Geomática/05_ANTIOQUIA/ADMINISTRATIVO/MGN_MPIO_POLITICO.shp")
Reading layer `MGN_MPIO_POLITICO' from data source
`C:\Users\hinca\Documents\(A) Hinca\UNAL\Semestre 5\Geomática\05_ANTIOQUIA\ADMINISTRATIVO\MGN_MPIO_POLITICO.shp'
using driver `ESRI Shapefile'
Simple feature collection with 125 features and 9 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: -77.12783 ymin: 5.418558 xmax: -73.88128 ymax: 8.873974
Geodetic CRS: WGS 84
mun_antioquia
Simple feature collection with 125 features and 9 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: -77.12783 ymin: 5.418558 xmax: -73.88128 ymax: 8.873974
Geodetic CRS: WGS 84
First 10 features:
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR
1 05 05001 MEDELLÍN
2 05 05101 CIUDAD BOLÍVAR
3 05 05107 BRICEÑO
4 05 05113 BURITICÁ
5 05 05120 CÁCERES
6 05 05093 BETULIA
7 05 05091 BETANIA
8 05 05088 BELLO
9 05 05086 BELMIRA
10 05 05079 BARBOSA
MPIO_CRSLC MPIO_NAREA MPIO_NANO
1 1965 374.8280 2017
2 1869 260.4461 2017
3 Ordenanza 27 de Noviembre 26 de 1980 376.3468 2017
4 1812 355.2103 2017
5 Decreto departamental 160 del 16 de Marzo de 1903 1873.8033 2017
6 Decreto departamental 629 del 28 de Enero de 1884 262.3675 2017
7 Ordenanza 42 del 24 de Abril de 1920 180.5260 2017
8 Ordenanza 48 del 29 deAbril de 1913 147.7589 2017
9 1814 296.1532 2017
10 1812 205.6662 2017
DPTO_CNMBR Shape_Leng Shape_Area geometry
1 ANTIOQUIA 1.0327835 0.03060723 POLYGON ((-75.66974 6.37359...
2 ANTIOQUIA 0.7085039 0.02124224 POLYGON ((-76.04467 5.92774...
3 ANTIOQUIA 1.0044720 0.03078496 POLYGON ((-75.45818 7.22284...
4 ANTIOQUIA 0.9637233 0.02902757 POLYGON ((-75.90857 6.97378...
5 ANTIOQUIA 2.9333643 0.15350440 POLYGON ((-75.20358 7.95716...
6 ANTIOQUIA 0.8476756 0.02141352 POLYGON ((-76.00304 6.28171...
7 ANTIOQUIA 0.6923058 0.01472138 POLYGON ((-75.95474 5.79522...
8 ANTIOQUIA 0.6143227 0.01206804 POLYGON ((-75.58203 6.42510...
9 ANTIOQUIA 1.1730035 0.02420036 POLYGON ((-75.69252 6.75917...
10 ANTIOQUIA 0.7700180 0.01680390 POLYGON ((-75.32148 6.51265...
mun_antioquia$KM2 <- st_area(st_transform(mun_antioquia, 3116))/1E6
mun_antioquia$KM2 <- as.numeric(mun_antioquia$KM2)
mun_antioquia$KM2 <- round(mun_antioquia$KM2,3)
min(mun_antioquia$KM2)
[1] 15.836
max(mun_antioquia$KM2)
[1] 2919.535
library(leaflet)
bins <- c(0, 150, 300, 450, 600, 750, 900, 1200, 1600, 2000, 2400, 2920)
pal <- colorBin("RdYlGn", domain = mun_antioquia$KM2, bins = bins)
mapa <- leaflet(data = mun_antioquia) %>%
addTiles() %>%
addPolygons(label = ~KM2,
popup = ~MPIO_CNMBR,
fillColor = ~pal(KM2),
color = "#444444",
weight = 1,
smoothFactor = 0.5,
opacity = 1.0,
fillOpacity = 0.5,
highlightOptions = highlightOptions(color = "white", weight = 2, bringToFront = TRUE)
) %>%
addProviderTiles(providers$OpenStreetMap) %>%
addLegend("bottomright", pal = pal, values = ~KM2,
title = "Municipalities extent [Km2] (DANE, 2018)",
opacity = 1
)
mapa