Este es un mapa interactivo de las manzanas catastrales de Torreón,
Coahuila, generado con leaflet en R.
A continuación se muestra el código utilizado para generar el mapa:
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.4.3
library(sf)
## Warning: package 'sf' was built under R version 4.4.3
## Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.2
##
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Cargar el shapefile
manzanas <- st_read("C:\\Users\\USER\\Downloads\\794551068083_s\\Torreón")
## Multiple layers are present in data source C:\Users\USER\Downloads\794551068083_s\Torreón, reading layer `050350001a'.
## Use `st_layers' to list all layer names and their type in a data source.
## Set the `layer' argument in `st_read' to read a particular layer.
## Warning in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
## automatically selected the first layer in a data source containing more than
## one.
## Reading layer `050350001a' from data source
## `C:\Users\USER\Downloads\794551068083_s\Torreón' using driver `ESRI Shapefile'
## Simple feature collection with 323 features and 2 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: 2350533 ymin: 1491214 xmax: 2369003 ymax: 1510129
## Projected CRS: Mexico ITRF2008 / LCC
# Transformar a WGS84
manzanas_wgs84 <- st_transform(manzanas, 4326)
# Crear el mapa
mapa_torreon <- leaflet() %>%
addTiles(group = "OpenStreetMap") %>%
addProviderTiles("Esri.WorldImagery", group = "Satélite") %>%
setView(lng = -103.4068, lat = 25.5428, zoom = 13) %>%
addPolygons(
data = manzanas_wgs84,
fillColor = "blue",
fillOpacity = 0.4,
color = "white",
weight = 1,
popup = ~paste("<strong>Identificador:</strong>", IDENTIFICA,
"<br><strong>Clave Geográfica:</strong>", CVEGEO),
group = "Manzanas Catastrales"
) %>%
addLayersControl(
baseGroups = c("OpenStreetMap", "Satélite"),
overlayGroups = c("Manzanas Catastrales"),
options = layersControlOptions(collapsed = FALSE)
)
mapa_torreon