library(sf)
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(ggplot2)
# Replace with the path to your shapefile
shapefile_path <- "archivosSHP/colonias_GCSWGS84_V1.shp"
# Load the shapefile
shapefile_data <- st_read(shapefile_path)
## Reading layer `colonias_GCSWGS84_V1' from data source
## `/Users/COLSON/Library/Mobile Documents/com~apple~CloudDocs/AlanFiles/Colson/COLSON 2024/Temas selectos R 2024/archivosSHP/colonias_GCSWGS84_V1.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 449 features and 6 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -111.0717 ymin: 28.98888 xmax: -110.8769 ymax: 29.16923
## Geodetic CRS: WGS 84
# View the first few rows of the attribute table
head(shapefile_data)
## Simple feature collection with 6 features and 6 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -110.9316 ymin: 29.00034 xmax: -110.9151 ymax: 29.0137
## Geodetic CRS: WGS 84
## OBJECTID NAME CODIGOCOLO
## 1 1 ARBOLEDAS 260300001017-L
## 2 2 SIERRA CLARA 260300001209-B
## 3 3 AREA SIN ASIGNACION DE COLONIA (LIENZO CHARRO) 260300001315-F
## 4 4 AREA SIN ASIGNACION DE COLONIA (CIUDAD DE LOS NINOS) 260300001329-H
## 5 5 TERRANOVA 260300001216-B
## 6 6 CARRETAS, LAS 260300001036-C
## SHAPE_LENG CODIGONUEV OID_1 geometry
## 1 1886.1323 HerCo081 1 MULTIPOLYGON (((-110.9266 2...
## 2 874.5188 HerCo139 2 MULTIPOLYGON (((-110.919 29...
## 3 1012.0158 HerCo140 3 MULTIPOLYGON (((-110.9159 2...
## 4 1601.5094 HerCo141 4 MULTIPOLYGON (((-110.9206 2...
## 5 2015.7367 HerCo142 5 MULTIPOLYGON (((-110.9243 2...
## 6 988.9333 HerCo143 6 MULTIPOLYGON (((-110.9243 2...
# View the structure of the data frame
str(shapefile_data)
## Classes 'sf' and 'data.frame': 449 obs. of 7 variables:
## $ OBJECTID : int 1 2 3 4 5 6 7 8 9 10 ...
## $ NAME : chr "ARBOLEDAS" "SIERRA CLARA" "AREA SIN ASIGNACION DE COLONIA (LIENZO CHARRO)" "AREA SIN ASIGNACION DE COLONIA (CIUDAD DE LOS NINOS)" ...
## $ CODIGOCOLO: chr "260300001017-L" "260300001209-B" "260300001315-F" "260300001329-H" ...
## $ SHAPE_LENG: num 1886 875 1012 1602 2016 ...
## $ CODIGONUEV: chr "HerCo081" "HerCo139" "HerCo140" "HerCo141" ...
## $ OID_1 : int 1 2 3 4 5 6 7 8 9 10 ...
## $ geometry :sfc_MULTIPOLYGON of length 449; first list element: List of 1
## ..$ :List of 1
## .. ..$ : num [1:9, 1:2] -111 -111 -111 -111 -111 ...
## ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
## - attr(*, "sf_column")= chr "geometry"
## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA
## ..- attr(*, "names")= chr [1:6] "OBJECTID" "NAME" "CODIGOCOLO" "SHAPE_LENG" ...
¿Qué significa eso de “CODIGOCOLO”? Este archivo está evidentemente incompleto y presenta muchos errores en la topología de los polígonos.
# Simple plot with a title using ggplot2
ggplot(data = shapefile_data) +
geom_sf() +
ggtitle("División de colonias de Hermosillo") +
theme_minimal()