Incorporación de la zona municipal de Torreón en el polígono urbano Uso de consultas para la lectura filtrada del Shapefile del contexto estatal filtrado municipal
Contexto geográfico
ruta<-"C:/Users/cguer/Documents/Claudia/Midropbox/Investigacion y escritos/karamanis/data/conjunto_de_datos/"
infile <- "05mun.shp"
nomarchi<-as.filename(paste0(ruta,infile))
nomfil<-"05mun"
a<-"SELECT * FROM \"05mun\" WHERE CVE_ENT = '05' AND CVE_MUN='035'"
datageot<- read_sf(nomarchi,options = "ENCODING=latin1",query=a)
datageot= st_transform(datageot, crs = 4326)
datageo_geom <- st_geometry(datageot)
polygon = st_cast(datageo_geom, "POLYGON")
tor<-polygon[2]
Incorporación de contexto vial como referencia local de ubicación uso de librería OSMDATA Elección territorial del polígono de Torreón urbano (polygon[2])
Delimitación en el área urbana del municipio de Torreón
Código de actividad SCIAN https://www.inegi.org.mx/scian/#
city = "Torreón Coahuila"
viasosm <- opq(city) %>%
add_osm_feature(key = "highway") %>%
osmdata_sf()
viasosm_sf <- viasosm$osm_lines
st_crs(viasosm_sf) <-4326
recorteviasosm_sf <-viasosm_sf[tor, ]
recorteviasosm_sf <-viasosm_sf|> st_intersection(tor)
recorteviasosm_sf <-subset(recorteviasosm_sf,recorteviasosm_sf$highway %in% c("primary","secondary","tertiary"))
# Plotting the rough maps
g <- ggplot() +
geom_sf(data = tor, fill = NA) +
geom_sf(data = recorteviasosm_sf, fill = NA, linewidth = 0.1) +
labs(
title = "Colonias de Torreón"
) +
theme_minimal(
base_family = "body_font",
base_line_size = unit(0.1, "mm")
) +
theme(
plot.title = element_text(size = 30)
)
g
Asentamientos humanos INEGI
Colonias https://www.inegi.org.mx/programas/dcah/
ruta<-"C:/Users/cguer/Documents/Claudia/Midropbox/Investigacion y escritos/karamanis/data/conjunto_de_datos/"
infile <- "00as.shp"
nomarchi<-as.filename(paste0(ruta,infile))
nomfil<-"00as"
a<-"SELECT * FROM \"00as\" WHERE CVE_ENT = '05' AND CVE_MUN='035'"
`%notin%` <- Negate(`%in%`)
datageot<- read_sf(nomarchi,options = "ENCODING=latin1",query=a)
#datageot<- read_sf(nomarchi,options = "ENCODING=latin1")
datageot= st_transform(datageot, crs = 4326)
#unique(datageot$TIPO)
datageot<- datageot|> filter(TIPO %notin% c("NINGUNO","CONDOMINIO"))
g <- ggplot() +
geom_sf(data = tor, fill = NA) +
geom_sf(data = datageot, aes(fill = TIPO),alpha=.7) +
scale_fill_manual(values = c("#f94144",
"#277da1",
"#f9844a",
"#277da1",
"#90be6d",
"#f9c74f",
"#277da1",
"#90be6d",
"#577590",
"#f0028a"
))+
geom_sf(data = recorteviasosm_sf, fill = NA, linewidth = 0.1) +
labs(
title = "Asentamientos humanos en Torreón urbano") +
theme_minimal(
base_family = "body_font",
base_line_size = unit(0.1, "mm")
) +
theme(
legend.position = "bottom",
legend.key.width = unit(3, "line"),
legend.key.height = unit(0.5, "line"),
plot.background = element_rect(fill = NA, color = NA),
plot.title = element_text(size = 30, hjust = 0.5, face = "bold"),
plot.subtitle = element_text(size = 16, hjust = 0.5),
plot.caption = element_text(size = 10, hjust = 0.5, margin = margin(20, 0, 0, 0))
)
g
getwd()
[1] “C:/Users/cguer/Documents/Claudia/Midropbox/Investigacion y escritos/karamanis/portraits/torreon”
map<-"torreon"
pal<-"asenta"
if (!dir.exists(glue("images/{map}"))) {
dir.create(glue("images/{map}"))
}
outfile <- str_to_lower(glue("images/{map}/{map}_{pal}torasenta.png"))
deg_to_rad <- function(x) {
(mean(x) * pi) / 180
}
get_aspect_ratio <- function(geometry) {
if (!inherits(geometry, c("Spatial", "Raster", "sf", "sfc"))) {
stop('"geometry" must be of class "Spatial", "Raster", "sf" or "sfc".')
}
bbox <- sf::st_bbox(geometry)
xlim <- bbox[c(1, 3)]
ylim <- bbox[c(2, 4)]
xdeg <- diff(xlim)
ydeg <- diff(ylim)
if (xdeg == 0 || ydeg == 0) {
asp <- 1
} else {
is_lon_lat <- sf::st_is_longlat(geometry)
asp <- unname((xdeg / ydeg) * ifelse(is_lon_lat, cos(deg_to_rad(ylim)), 1))
}
asp
}
width = 800
height = NA
asp <- get_aspect_ratio(tor)
if (is.na(width) && !is.na(height)) {
width <- height * asp
} else if (is.na(height) && !is.na(width)) {
height <- width / asp
}
#https://stackoverflow.com/questions/57868862/crop-unused-margin-in-a-ggplot-plot
#ggsave(outfile, width = 800, height = 800, units = "mm", dpi = "retina",bg="white",limitsize = FALSE)
#ggsave(outfile, width = width, height = height, units = "mm", dpi = "retina",bg="white",limitsize = FALSE)
ggsave(outfile, width = 11, height = 8, units = "in", dpi = 320,bg="white",limitsize = FALSE)