Video con la explicación del código https://youtu.be/5gJYygomOIo?si=Ru7GOMKJv3HGn0i2
Datos del Directorio EstadÃstico Nacional de Unidades Económicas (DENUE) en la plataforma del INEGI
https://www.inegi.org.mx/app/descarga/
Para el estado de Coahuila de Zaragoza
https://www.inegi.org.mx/contenidos/masiva/denue/denue_05_shp.zip
Contexto geográfico
ruta<-"C:/Users/cguer/Documents/Claudia/Midropbox/Investigacion y escritos/karamanis/data/conjunto_de_datos/"
infile <- "denue_inegi_05_.shp"
nomarchi<-as.filename(paste0(ruta,infile))
a<-"SELECT * FROM denue_inegi_05 WHERE cve_mun ='035'AND codigo_act in ('622111','622112','622211','622212','622311','622312')"
datadenuet<- read_sf(nomarchi,options = "ENCODING=latin1",query=a)
#datadenuet<- read_sf(nomarchi,options = "ENCODING=latin1")
datadenuet= st_transform(datadenuet, crs = 4326)
datadenuet_geom <- st_geometry(datadenuet)
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"))
recortedenue_sf <-datadenuet|> st_intersection(tor)
recortedenue_sf <-subset(recortedenue_sf,recortedenue_sf$codigo_act %in% c("622111","622112","622211","622212","622311","622312"))
#recortedenue_sf <-subset(recortedenue_sf,recortedenue_sf$codigo_act %in% c("541120"))
# Plotting the rough maps
g <- ggplot() +
geom_sf(data = tor, fill = NA) +
geom_sf(data = recorteviasosm_sf, fill = NA, linewidth = 0.1) +
geom_sf(
data = recortedenue_sf,
# alpha = 0.3,
size = 1,
color="red"
) +
labs(
title = "Puntos DENUE"
) +
theme_minimal(
base_family = "body_font",
base_line_size = unit(0.1, "mm")
) +
theme(
plot.title = element_text(size = 30)
)
g
Creación de zonas buffer o áreas de influencia
PolÃgonos que se generan alrededor de un lugar y que proporcionan una herramienta de análisis espacial para estudiar las relaciones con el entorno
# Convertir las tablas a la proyección CRS EPSG 3857 para los buffers y de unidades de 1 metro
recorteviasosm_sf <- recorteviasosm_sf |> st_transform("EPSG:3857")
recortedenue_sf <- recortedenue_sf |> st_transform("EPSG:3857")
tor <- tor |> st_transform("EPSG:3857")
# Region within 1 km of health facilities
buffer_1 <- recortedenue_sf |>
st_buffer(dist = 1000) |>
st_union() |>
st_intersection(tor)|> st_as_sf() |> mutate(buf_dist = "< 1 km")
plot(buffer_1)
g <- ggplot() +
geom_sf(data = tor, fill = NA) +
geom_sf(data = recorteviasosm_sf, fill = NA, linewidth = 0.1) +
geom_sf(
data = recortedenue_sf,
# alpha = 0.3,
size = .2,
color="red"
) +
geom_sf(
data = buffer_1,
mapping = aes(
fill = buf_dist
),
alpha = 0.5,
colour = "black",
linewidth = 0
) +
scale_fill_manual(
values = paletteer::paletteer_d("rcartocolor::TealGrn")
) +
labs(
title = "Puntos hospitalarios DENUE y área a 1 km"
) +
theme_minimal(
base_family = "body_font",
base_line_size = unit(0.1, "mm")
) +
theme(
plot.title = element_text(size = 20)
)
g
buffer_2 <- recortedenue_sf |>
st_buffer(dist = 2000) |>
st_union() |>
st_intersection(tor)|> st_as_sf() |> mutate(buf_dist = "< 2 km")|>
st_difference(buffer_1)
g <- ggplot() +
geom_sf(data = tor, fill = NA) +
geom_sf(data = recorteviasosm_sf, fill = NA, linewidth = 0.1) +
geom_sf(
data = recortedenue_sf,
# alpha = 0.3,
size = 1,
color="red"
) +
geom_sf(
data = buffer_1,
mapping = aes(
fill = buf_dist
),
alpha = 0.5,
colour = "black",
linewidth = 0
) +
scale_fill_manual(
values = paletteer::paletteer_d("rcartocolor::TealGrn")
) +
geom_sf(
data = buffer_2,
mapping = aes(
fill = buf_dist
),
alpha = 0.5,
colour = "black",
linewidth = 0
) +
scale_fill_manual(
values = paletteer::paletteer_d("rcartocolor::TealGrn")
) +
labs(
title = "Puntos hospitalarios DENUE y área a 1 km y 2 km"
) +
theme_minimal(
base_family = "body_font",
base_line_size = unit(0.1, "mm")
) +
theme(
plot.title = element_text(size = 20)
)
g
buffer_3 <- recortedenue_sf |>
st_buffer(dist = 3000) |>
st_union() |>
st_intersection(tor)|> st_as_sf() |> mutate(buf_dist = "< 3 km")|>
st_difference(buffer_2) |>
st_difference(buffer_1)
g <- ggplot() +
geom_sf(data = tor, fill = NA) +
geom_sf(data = recorteviasosm_sf, fill = NA, linewidth = 0.1) +
geom_sf(
data = recortedenue_sf,
# alpha = 0.3,
size = 1,
color="red"
) +
geom_sf(
data = buffer_1,
mapping = aes(
fill = buf_dist
),
alpha = 0.5,
colour = "black",
linewidth = 0
) +
scale_fill_manual(
values = paletteer::paletteer_d("rcartocolor::TealGrn")
) +
geom_sf(
data = buffer_2,
mapping = aes(
fill = buf_dist
),
alpha = 0.5,
colour = "black",
linewidth = 0
) +
geom_sf(
data = buffer_3,
mapping = aes(
fill = buf_dist
),
alpha = 0.5,
colour = "black",
linewidth = 0
) +
scale_fill_manual(
values = paletteer::paletteer_d("rcartocolor::TealGrn")
) +
labs(
title = "Puntos hospitalarios DENUE y área a 1 km,2, y 3 km"
) +
theme_minimal(
base_family = "body_font",
base_line_size = unit(0.1, "mm")
) +
theme(
plot.title = element_text(size = 20)
)
g
buffer_4 <- recortedenue_sf |>
st_buffer(dist = 4000) |>
st_union() |>
st_intersection(tor)|> st_as_sf() |> mutate(buf_dist = "< 4 km")|>
st_difference(buffer_3) |>
st_difference(buffer_2)|>
st_difference(buffer_1)
plot(buffer_1)
plot(buffer_2)
plot(buffer_3)
plot(buffer_4)
df_buffers <- bind_rows(
buffer_1 |> st_as_sf() |> mutate(buf_dist = "< 1 km"),
buffer_2 |> st_as_sf() |> mutate(buf_dist = "1 - 2 km"),
buffer_3 |> st_as_sf() |> mutate(buf_dist = "2 - 3 km"),
buffer_4 |> st_as_sf() |> mutate(buf_dist = "3 - 4 km")
) |>
mutate(
buf_dist = fct(
buf_dist,
levels = c(
"< 1 km",
"1 - 2 km",
"2 - 3 km",
"3 - 4 km"
)
)
)
plot(df_buffers)
g <- ggplot() +
geom_sf(data = tor, fill = NA) +
geom_sf(data = recorteviasosm_sf, fill = NA, linewidth = 0.1) +
geom_sf(
data = recortedenue_sf,
# alpha = 0.3,
size = 1,
color="red"
) +
geom_sf(
data = df_buffers,
mapping = aes(
fill = buf_dist
),
alpha = 0.5,
colour = "black",
linewidth = 0
) +
scale_fill_met_d("Cross") +
#scale_fill_manual(
# values = paletteer::paletteer_d("rcartocolor::TealGrn")
#) +
labs(
title = "Puntos hospitalarios DENUE y áreas de influencia"
) +
theme_minimal(
base_family = "body_font",
base_line_size = unit(0.1, "mm")
) +
theme(
plot.title = element_text(size = 20)
)
g