rutamc<-"D:/Documents/Claudia/Midropbox/Investigacion y escritos/mapasnacionales"
#tormun <- readOGR(rutamc,"muntor", use_iconv = TRUE, encoding = "latin1")
#Recorte con la librerÃa raster
library(raster)
filename<-paste0(rutamc,"/muntor.shp")
s <- shapefile(filename)
#sub <- crop(s, extent(-103.49, -103.37, 25.49, 25.59))
sub <- crop(s, extent(-103.455, -103.34, 25.565, 25.661))
shapefile(sub,'cropped_muntorsp.shp',overwrite=TRUE)
#coordenadas TSM
#https://www.keene.edu/campus/maps/tool/
#-103.4337616, 25.6611272
#-103.3314514, 25.6581873
#-103.3395767, 25.5713497
#-103.4540749, 25.5656202
#-103.4337044, 25.6608693
######
#-103.4299278, 25.6487997
#-103.3461571, 25.6495734
#-103.3454704, 25.5723304
#-103.4367943, 25.5717110
#-103.4302711, 25.6487997
#El archivo queda guardado y se lee el recorte
tormun2 <- readOGR(rutamc,"cropped_muntorsp", use_iconv = TRUE, encoding = "latin1")
## OGR data source with driver: ESRI Shapefile
## Source: "D:\Documents\Claudia\Midropbox\Investigacion y escritos\mapasnacionales", layer: "cropped_muntorsp"
## with 8608 features
## It has 11 fields
# Para poder graficar con ggplot se convierte en una tabla (dataframe) (paquete broom)
tormun2_df <- tidy(tormun2, region = "id")
# Se agrega un identificador al shapefile que corresponderá al número de renglón
tormun2$id <- rownames(tormun2@data)
# Se reunen los dos archivos a partir del id
tormun2_df <- left_join(tormun2_df,tormun2@data,by = "id")
#Se crea una paleta de colores para las vÃas
via_paletacol <- c("Calle" = "green",
"Boulevard" ="red",
"Avenida" = "blue",
"Privada" = "grey",
"Circuito" = "orange",
"Cerrada" = "purple")
##Calle Boulevard Avenida Privada Circuito
# "green" "grey40" "purple" "grey" "orange"
## Cerrada
# "blue"
# Se grafica con los colores seleccionados
#
ggplot() + geom_path(data = tormun2_df, aes(x = long, y = lat, group = group, color=TIPOVIAL)) +scale_colour_manual(values =via_paletacol) + labs(title = "Ejes viales",
subtitle = "Coloreados por tipo de vÃa", color = "Tipo de vÃa",x = "", y = "") +
theme(axis.text = element_blank(), axis.ticks = element_blank())+ coord_quickmap()+theme_void()

ggplot() + geom_path(data = tormun2_df, aes(x = long, y = lat, group = group, color=TIPOVIAL)) +scale_colour_manual(values =via_paletacol) +
theme(axis.text = element_blank(), axis.ticks = element_blank())+ coord_quickmap()+theme_void()

ggsave("pedazotorsp_map.svg", width = 1300, height = 1300, units = "mm", dpi = "retina",limitsize = FALSE)
#ggsave("pedazotor_map.png", width = 1300, height = 1300, units = "mm", dpi = "retina",limitsize = FALSE)