VELOCIDADES MÁXIMAS Y ESCUELAS EN CIUDAD DE MONTEVIDEO

library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.0.5
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.1.1     v dplyr   1.0.5
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## Warning: package 'ggplot2' was built under R version 4.0.5
## Warning: package 'tibble' was built under R version 4.0.5
## Warning: package 'tidyr' was built under R version 4.0.5
## Warning: package 'readr' was built under R version 4.0.5
## Warning: package 'dplyr' was built under R version 4.0.5
## Warning: package 'forcats' was built under R version 4.0.5
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library (sf)
## Warning: package 'sf' was built under R version 4.0.5
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(osmdata)
## Warning: package 'osmdata' was built under R version 4.0.5
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.0.5
library(ggmap)
## Warning: package 'ggmap' was built under R version 4.0.5
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.

En primer lugar genero la caja de coordenadas de la ciudad de Montevideo. Y luego cargo un mapa base de la ciudad a partir de Open Street Map y me guardo un polígono con el contorno de la ciudad.

bbox_mdeo <- getbb("Montevideo, Montevideo,Uruguay")
mapa_mdeo <- get_stamenmap(bbox = bbox_mdeo,
                          zoom=12)
## Source : http://tile.stamen.com/terrain/12/1405/2469.png
## Source : http://tile.stamen.com/terrain/12/1406/2469.png
## Source : http://tile.stamen.com/terrain/12/1407/2469.png
## Source : http://tile.stamen.com/terrain/12/1408/2469.png
## Source : http://tile.stamen.com/terrain/12/1409/2469.png
## Source : http://tile.stamen.com/terrain/12/1410/2469.png
## Source : http://tile.stamen.com/terrain/12/1405/2470.png
## Source : http://tile.stamen.com/terrain/12/1406/2470.png
## Source : http://tile.stamen.com/terrain/12/1407/2470.png
## Source : http://tile.stamen.com/terrain/12/1408/2470.png
## Source : http://tile.stamen.com/terrain/12/1409/2470.png
## Source : http://tile.stamen.com/terrain/12/1410/2470.png
## Source : http://tile.stamen.com/terrain/12/1405/2471.png
## Source : http://tile.stamen.com/terrain/12/1406/2471.png
## Source : http://tile.stamen.com/terrain/12/1407/2471.png
## Source : http://tile.stamen.com/terrain/12/1408/2471.png
## Source : http://tile.stamen.com/terrain/12/1409/2471.png
## Source : http://tile.stamen.com/terrain/12/1410/2471.png
## Source : http://tile.stamen.com/terrain/12/1405/2472.png
## Source : http://tile.stamen.com/terrain/12/1406/2472.png
## Source : http://tile.stamen.com/terrain/12/1407/2472.png
## Source : http://tile.stamen.com/terrain/12/1408/2472.png
## Source : http://tile.stamen.com/terrain/12/1409/2472.png
## Source : http://tile.stamen.com/terrain/12/1410/2472.png
ggmap(mapa_mdeo)

mdeo_polygon <- getbb("Montevideo, Uruguay", format_out = "sf_polygon")
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
ggmap(mapa_mdeo)+
  geom_sf(data=mdeo_polygon, fill=NA, size=1, color="blue", inherit.aes = FALSE)+
  labs(title="Montevideo",
       caption="Fuente: Open Street Map")+
  theme_void()
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.

Posteriormente cargo información sobre calles de la ciudad.

mdeo_calles <- opq(bbox_mdeo) %>%
              add_osm_feature(key = "highway")
mdeo_calles <- osmdata_sf(mdeo_calles)
mdeo_calles
## Object of class 'osmdata' with:
##                  $bbox : -34.938056,-56.4313997,-34.7018526,-56.0225006
##         $overpass_call : The call submitted to the overpass API
##                  $meta : metadata including timestamp and version numbers
##            $osm_points : 'sf' Simple Features Collection with 86469 points
##             $osm_lines : 'sf' Simple Features Collection with 20322 linestrings
##          $osm_polygons : 'sf' Simple Features Collection with 116 polygons
##        $osm_multilines : NULL
##     $osm_multipolygons : 'sf' Simple Features Collection with 1 multipolygons

Me quedo con el mapa de líneas de las calles de la ciudad y recorto las calles con el límite del polígono de la ciudad.

mdeo_calles <- mdeo_calles$osm_lines
mdeo_calles <- st_intersection(mdeo_calles, mdeo_polygon)
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
ggmap(mapa_mdeo)+
  geom_sf(data=mdeo_polygon, fill=NA, size=1, color="blue", inherit.aes = FALSE)+
  geom_sf(data = mdeo_calles, color="deepskyblue4", alpha=0.5, inherit.aes = FALSE)+
  labs(title="Montevideo",
       caption="Fuente: Open Street Map")+
  theme_void()
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.

A partir del mapa es posible vidualizar la diferencial densidad de vías de tránsito en la ciudad. Se concentran en el centro y este de la ciudad y se hacen más dispersas al acercarse a los límites en donde existe una pequeña zona rural y asentamientos irregulares.

Se analizará a continuación la velocidad máxima permitida en las calles de la ciudad.

mdeo_calles <- mdeo_calles %>% 
  mutate(maxspeed =  as.numeric(maxspeed))
ggmap(mapa_mdeo)+
    geom_sf(data = mdeo_calles, aes(color=maxspeed), inherit.aes = FALSE)+
    labs(title="Velocidad máxima permitida, Montevideo",
     caption="Fuente: Open Street Map")+
  scale_colour_viridis_c()+
  theme_void()
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.

Es posible observar que la zona más densa del centro de la ciudad permite velocidades menores a las de la periferia. Para visualizar mejor este aspecto, seleccionaremos las vías con velocidades mayores a la media a 45km. Esa velocidad es la más frecuente en las vías de la ciudad.

ggplot (mdeo_calles)+
  geom_histogram(aes(x=maxspeed))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 11066 rows containing non-finite values (stat_bin).

ggmap(mapa_mdeo)+
  geom_sf(data = filter(mdeo_calles, maxspeed > 45), color="orange", inherit.aes = FALSE)+
  scale_color_viridis_c()+
  labs(title="Montevideo",
       subtitle="Vías con velocidad permitida mayor a 45km por hora",
       caption="Fuente: Open Street Map")+
  theme_void()
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.

Como es claramente visible en el mapa anterior, efectivamente las vías que superan la velocidad permitida de 45km por hora son las que rodean las zonas más densamente pobladas del centro y la costa de la ciudad y algunas arterias importantes como la rambla, Av Italia, Bvar Artigas, etc.

Ahora veremos dónde se ubican los centros educativos en la ciudad. Descargamos la información de escuelas, las guardamos en un mapa de puntos y la intersectamos con los límites de la ciudad.

mdeo_escuelas <- opq(bbox_mdeo) %>% 
                  add_osm_feature(key = "amenity", value = "school")
mdeo_escuelas <- osmdata_sf(mdeo_escuelas) 
mdeo_escuelas <- mdeo_escuelas$osm_points
ggmap(mapa_mdeo)+
  geom_sf(data= filter (mdeo_escuelas, !is.na(amenity)), aes(color=amenity), inherit.aes = FALSE)+
  labs(title="Escuelas de Montevideo",
       caption="Fuente: Open Street Map")+
  theme_void()
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.

Veremos si hay centros educativos sobre vías “rápidas” en las ciudad.

ggmap(mapa_mdeo)+
  geom_sf(data= filter (mdeo_escuelas, !is.na(amenity)), aes(color=amenity), inherit.aes = FALSE)+
  geom_sf(data = filter(mdeo_calles, maxspeed >=75), color="orange", inherit.aes = FALSE)+
  labs(title="Escuelas de Montevideo y calles con velocidad máxima de 75km o más",
       color="Leyenda",
       caption="Fuente: Open Street Map")+
  theme_void()
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.

Con excepción de un centro educativo en la zona este sobre Avenida Italia, ninguno de los establecimientos se encuestran sobre calles cuya velocidad máxima permitida supera los 75km por hora.