DESCARGA DE DATOS DE OSM

Trabajo práctico clase 4

Cargamos las librerias que vamos a utilizar

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

Verificamos en https://www.openstreetmap.org/ que al ingresar la busqueda de “Montevideo”, sea dato suficiente para que OSM la ubique en el conjunto de datos

bbox_mvd <- getbb("Montevideo")
mapa_mvd <- get_stamenmap(bbox = bbox_mvd,
                          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_mvd)

Armamos la busqueda en OSM de las calles de Montevideo. En este caso vamos a necesitar todo el key “highway”, para obtener las distintas categorìas de calles de la ciudad

mvd_calles <- opq(bbox_mvd) %>%
              add_osm_feature(key = "highway")

Descargamos la información requerida

mvd_calles <- osmdata_sf(mvd_calles)
mvd_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 85438 points
##             $osm_lines : 'sf' Simple Features Collection with 20053 linestrings
##          $osm_polygons : 'sf' Simple Features Collection with 110 polygons
##        $osm_multilines : NULL
##     $osm_multipolygons : 'sf' Simple Features Collection with 1 multipolygons

Vamos a incorporar unicamente los datos de lineas, que corresponden al dataset da calles

mvd_calles <- mvd_calles$osm_lines
ggmap(mapa_mvd)+
    geom_sf(data = mvd_calles, color="deepskyblue3", alpha=0.5, inherit.aes = FALSE)+
  labs(title="Ciudad de Montevideo",
       caption="Fuente: Open Street Map")+
  theme_void()
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.

Visualizamos las calles por el atributo “highway”, que indica el tipo de calle por categoría (primaria, secundaria, etc.)

ggmap(mapa_mvd)+
    geom_sf(data = mvd_calles, aes(color=highway), size=0.05, inherit.aes = FALSE)+
  labs(title="Ciudad de Montevideo",
       subtitle= "Calles",
       fill= "Categorías de calles",
       caption="Fuente: Open Street Map")+
  theme_void()
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.

Vamos a indicar en R los datos de hospitales que están en OSM como geometría de puntos

mvd_hospitales <- opq(bbox_mvd) %>%
              add_osm_feature(key = "amenity", value = "hospital")

Descargamos la información

mvd_hospitales <- osmdata_sf(mvd_hospitales)

Oservamos la información obtenida

mvd_hospitales
## 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 441 points
##             $osm_lines : NULL
##          $osm_polygons : 'sf' Simple Features Collection with 36 polygons
##        $osm_multilines : NULL
##     $osm_multipolygons : NULL

Nos quedamos solo con los puntos:

mvd_hospitales <- mvd_hospitales$osm_points

Realizamos el mapeo de en conjunto de las bases descargadas de OSM

ggmap(mapa_mvd)+
    geom_sf(data = mvd_calles, aes(color=highway), size=0.05, inherit.aes = FALSE)+
  geom_sf(data = mvd_hospitales, color="black", size=1, inherit.aes = FALSE)+
  labs(title="Ciudad de Montevideo",
       subtitle= "Calles",
       fill= "Categorías de calles",
       caption="Fuente: Open Street Map")+
  theme_void()
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.

Observamos rapidamente que existe una concentración de servicios hospitalarios en el eje de Av. Bulevar Artigas y en la zona de Pque. Batlle y Ciudad Vieja. Asimismo al norte de la ciudad se observan multiples puntos de infraestructuras hospitalarias en los barrios de Colón y Lezica, y en la ciudad de Las Piedras (departamento de Canelones).

Ver en conjunto la información de infraestructura vial y hospitales nos permite identificar de forma preliminar cuales servicios se encuentran con mejor accesibilidad dentro de la trama urbana.

Para contextualizar la cartografía, vamos a descargar la data de espacios libres y playas. Para los datos de playas nos vamos a descargar el conjunto de datos del key “natural” y value “beach”. Para el caso de los espacios libres, de la multiplicidad de conjuntos de informaciñon existentes para representar ese tipo de información, en esta oportunidadoptamos por un dataset denominado “grass”(pasto) del key “landuse”

Armamos la consulta y descarga del dataset de playas:

mvd_playas <- opq(bbox_mvd) %>%
              add_osm_feature(key = "natural", value="beach")
mvd_playas <- osmdata_sf(mvd_playas)
mvd_playas
## 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 1969 points
##             $osm_lines : 'sf' Simple Features Collection with 47 linestrings
##          $osm_polygons : 'sf' Simple Features Collection with 23 polygons
##        $osm_multilines : NULL
##     $osm_multipolygons : 'sf' Simple Features Collection with 16 multipolygons

En este caso nos vamos a quedar solamente con los poligonos

mvd_playas <- mvd_playas$osm_polygons

Realizamos el mismo procedimiento para los espacios libres (grass)….

mvd_pasto <- opq(bbox_mvd) %>%
              add_osm_feature(key = "landuse", value = "grass")
mvd_pasto <- osmdata_sf(mvd_pasto)
mvd_pasto
## 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 38193 points
##             $osm_lines : 'sf' Simple Features Collection with 29 linestrings
##          $osm_polygons : 'sf' Simple Features Collection with 1821 polygons
##        $osm_multilines : NULL
##     $osm_multipolygons : 'sf' Simple Features Collection with 18 multipolygons

En este caso también nos vamos a quedar solamente con los poligonos

mvd_pasto <- mvd_pasto$osm_polygons

Componemos la cartografía con los nuevos datasets descargados

ggmap(mapa_mvd)+
      geom_sf(data = mvd_pasto, fill="darkgreen", size=NA, color=NA, inherit.aes = FALSE)+
     geom_sf(data = mvd_playas, fill="lightyellow", size=NA, color=NA, inherit.aes = FALSE)+
  geom_sf(data = mvd_calles, aes(color=highway), size=0.05, inherit.aes = FALSE)+
  geom_sf(data = mvd_hospitales, color="black", size=1, inherit.aes = FALSE)+
  labs(title="Ciudad de Montevideo",
       subtitle= "Calles",
       fill= "Categorías de calles",
       caption="Fuente: Open Street Map")+
  theme_void()
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.

Observamos que en las áreas centrales de la ciudad, coexisten una importante cantidad de equipamientos vinculados a infraestructuras hospitalarias con grandes espacios libres del tipo parques urbanos; en particular los hospitales ubicados dentro o muy próximos al Parque Batlle.