temp <- tempfile()
temp2 <- tempfile()
#url<-"https://www.inegi.org.mx/contenidos/masiva/denue/denue_09_shp.zip"
url<-paste0("https://www.inegi.org.mx/contenidos/masiva/denue/denue_",numentidad$codent,"_shp.zip")
download.file(url, temp)
unzip(zipfile = temp, exdir = temp2)
rut<-file.path(temp2)
ruta<-paste0(rut,"\\conjunto_de_datos")
nomfile<-paste0("denue_inegi_",numentidad$codent,"_")
mimapas <- readOGR(ruta,nomfile)
mimapas<-subset(mimapas, cve_ent==numentidad$codent)
mimapas<-subset(mimapas, cve_mun==numuni$codmuni)
#proj4string(mimapas)
unlink(c(temp, temp2))
glue(" \n## ",params$varname," \n \n ") %>% cat()
glue::glue (params$entidad, "\n\n") %>% cat()
Coahuila de Zaragoza
glue("\n\n") ## one newline
glue::glue (params$municipalidad, " \n\n") %>% cat()
Torreón
mimapas_df <- as(mimapas, "data.frame")
#sciansec<-mimapas_df[, c('codigo_act', 'nombre_act')]
#a<-sciansec %>% group_by_all() %>% tally()
#mimapas_df <-subset(mimapas_df, mimapas_df$nombre_act %in% c(params$varname))
mimapas_df <-subset(mimapas_df, mimapas_df$codigo_act %in% c("522451","522452"))
#mimapas_df <-subset(mimapas_df,!(mimapas_df$per_ocu %in% c("0 a 5 personas","6 a 10 personas")))
#mimapas_df <- mimapas_df %>% filter(grepl("DIAMANTEX", raz_social))
#mimapas_dfS <- mimapas_df %>% filter(grepl("7-ELEVEN",raz_social))
#mimapas_df <-subset(mimapas_df, mimapas_df$nom_estab %in% c("NEVERIA CHEPO"))
coords.df <- data.frame(mimapas_df$longitud, mimapas_df$latitud)
coords.mx <- as.matrix(coords.df)
# Compute distance matrix
dist.mx <- dist(coords.mx)
tsp.ins <- tsp_instance(coords.mx, dist.mx)
tour <- run_solver(tsp.ins, method="2-opt")
#autoplot(tsp.ins, tour)
tour_order <- as.integer(tour)
mleft<-min(coords.df$mimapas_df.longitud)-.05
mright<-max(coords.df$mimapas_df.longitud)+.05
mbottom<-min(coords.df$mimapas_df.latitud)-.05
mtop<-max(coords.df$mimapas_df.latitud)+.05
test1=get_stamenmap(bbox = c(left =mleft, bottom = mbottom, right = mright, top =mtop),source="stamen",maptype="toner-hybrid", zoom=13)
#terrain
#toner-lite
#watercolor
#terrain-background
#terrain-labels
#terrain-lines
#toner
#toner-2010***
#toner-2011
#toner-background
#toner-hybrid***
#toner-labels
#toner-lines
tour_order <- as.integer(tour)
#
# Sort addresses.
#
addresses <- coords.df[tour_order,]
ggmap(test1, extent = "device") +
geom_point(data = addresses, aes(x = mimapas_df.longitud, y = mimapas_df.latitud), colour = "red",size = 2, alpha = 0.75) +
geom_path(data = addresses, aes(x = mimapas_df.longitud, y = mimapas_df.latitud), colour = "red",size = 1, alpha = 0.75) +
labs(x = "", y = "")