I. Descargar de OpenStreetMap la grilla de calles para la Ciudad elegida en el ejercicio 1 y mapearla por uno de sus atributos (velocidad mínima, velocidad máxima, cantidad de carriles, etc).
Antes de hacer el ejercicio, cargamos las librerías necesarias para trabajar con los datos de nuestro interés.
library(tidyverse)
library(sf)
library(osmdata)
library(leaflet)
library(ggsflabel)
Traemos la caja de coordenadas de la ciudad elegida.
bbox <- getbb("Bilbao, España")
bbox
## min max
## x -2.985981 -2.880264
## y 43.213718 43.290132
Traemos el contorno de la ciudad de OSM.
bbox_poly <- getbb("Bilbao, España", format_out = "sf_polygon")
leaflet(bbox_poly) %>%
addTiles() %>%
addPolygons()
Traemos las calles de la ciudad de OSM.
bilbao <- opq(bbox) %>%
add_osm_feature(key = "highway")
bilbao <- bilbao %>%
osmdata_sf()
calles <- bilbao$osm_lines
Visualizamos los resultados.
ggplot() +
geom_sf(data = calles) +
theme_light()

Realizamos la intersección/recorte con el polígono de límites.
calles <- st_intersection(calles, bbox_poly)
ggplot() +
geom_sf(data = calles) +
theme_light()

a. Proyectar los datos descargados en un mapa y comentar los resultados: ¿Cómo se distribuyen en la Ciudad?
Descargamos de OSM la ubicación de hostels en la ciudad de Bilbao.
Bilbao_hostels <- opq(bbox) %>%
add_osm_feature(key = "tourism", value = "hostel") %>%
osmdata_sf()
Bilbao_hostels
Bilbao_hostels2 <- st_intersection(Bilbao_hostels$osm_points, bbox_poly)
Eliminamos con la función UNIQUE los registros duplicados en el total de las variables.
Bilbao_hostels_U <- unique(Bilbao_hostels2)
Bilbao_hostels_U$name
## [1] NA
## [2] NA
## [3] NA
## [4] NA
## [5] NA
## [6] NA
## [7] NA
## [8] NA
## [9] NA
## [10] NA
## [11] "Akelarre"
## [12] NA
## [13] NA
## [14] NA
## [15] NA
## [16] NA
## [17] NA
## [18] NA
## [19] "Pension Mendez"
## [20] NA
## [21] NA
## [22] NA
## [23] NA
## [24] NA
## [25] NA
## [26] "Albergue Claret Enea Aterpea"
## [27] NA
## [28] "Poshtel Bilbao"
## [29] NA
## [30] NA
## [31] NA
## [32] "Hostal Central"
## [33] NA
## [34] NA
## [35] NA
## [36] NA
## [37] "Albergue de Peregrinos Santa Cruz de Begoña"
## [38] "Hostel Optimi Rooms"
## [39] NA
## [40] NA
## [41] NA
## [42] NA
## [43] NA
## [44] NA
## [45] NA
## [46] NA
## [47] NA
## [48] NA
## [49] NA
## [50] NA
## [51] NA
## [52] NA
## [53] "All Iron"
Mapeamos los hostels en la ciudad de Bilbao.
ggplot() +
geom_sf(data = calles, color = "grey") +
geom_sf(data = Bilbao_hostels_U, aes(color = internet_access), size = 4) +
geom_sf_label_repel(data = Bilbao_hostels_U, aes(label = name), size = 4) +
theme_void() +
labs(title = "Bilbao",
subtitle = "Hostels",
caption = "Fuente: OpenStreetMap",
color = "Acceso internet")

b. Hacer un conteo de los ítems de la capa descargada por barrio, mapearlo y compararlo con el conteo de los ítems descargados en el ejercicio anterior: ¿La distribución es similar o hay diferencias? ¿A qué se puede deber?
Importamos el geojson con los barrios de Bilbao.
barrios <- st_read('distritos-bilbao_wgs84.geojson') %>% rename(barrios_bilbao=BAR_DS_O) %>% mutate(barrios_bilbao=str_replace_na(barrios_bilbao, "Deusto"))
## Reading layer `distritos-bilbao_wgs84' from data source `C:\Users\jabib\Desktop\TP\distritos-bilbao_wgs84.geojson' using driver `GeoJSON'
## Simple feature collection with 8 features and 10 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -2.985978 ymin: 43.21371 xmax: -2.880261 ymax: 43.29013
## CRS: 4326
barrios
## Simple feature collection with 8 features and 10 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -2.985978 ymin: 43.21371 xmax: -2.880261 ymax: 43.29013
## CRS: 4326
## BAR_CL BAR_BARR barrios_bilbao BAR_MUNI BAR_MUNI_D
## 1 44802000000200 702 Iralabarri 020 Bilbao
## 2 44802000000200 301 Otxarkoaga 020 Bilbao
## 3 44802000000400 204 Uribarri 020 Bilbao
## 4 44802000000100 403 Bolueta 020 Bilbao
## 5 44802000000100 506 Bilbao la Vieja 020 Bilbao
## 6 44802000000000 601 Abando 020 Bilbao
## 7 44802000000500 806 Diseminado Basurtu-Zorrotza 020 Bilbao
## 8 NA <NA> Deusto <NA> <NA>
## BAR_PROV BAR_PROV_D Shape_Leng Shape_Area distrito
## 1 48 Bizkaia 3013.924 382538.0 7
## 2 48 Bizkaia 4073.511 584765.0 3
## 3 48 Bizkaia 2944.946 323226.1 2
## 4 48 Bizkaia 7268.457 768816.2 4
## 5 48 Bizkaia 2206.221 134503.2 5
## 6 48 Bizkaia 4972.360 1174614.1 6
## 7 48 Bizkaia 13613.681 4162459.1 8
## 8 <NA> <NA> 6911.348 847718.6 1
## geometry
## 1 MULTIPOLYGON (((-2.934927 4...
## 2 MULTIPOLYGON (((-2.896959 4...
## 3 MULTIPOLYGON (((-2.922761 4...
## 4 MULTIPOLYGON (((-2.905864 4...
## 5 MULTIPOLYGON (((-2.921609 4...
## 6 MULTIPOLYGON (((-2.940626 4...
## 7 MULTIPOLYGON (((-2.950495 4...
## 8 MULTIPOLYGON (((-2.967939 4...
summary(barrios)
## BAR_CL BAR_BARR barrios_bilbao BAR_MUNI BAR_MUNI_D
## Min. :44802000000000 204 :1 Length:8 020 :7 Bilbao:7
## 1st Qu.:44802000000100 301 :1 Class :character NA's:1 NA's :1
## Median :44802000000200 403 :1 Mode :character
## Mean :44802000000200 506 :1
## 3rd Qu.:44802000000300 601 :1
## Max. :44802000000500 (Other):2
## NA's :1 NA's :1
## BAR_PROV BAR_PROV_D Shape_Leng Shape_Area distrito
## 48 :7 Bizkaia:7 Min. : 2206 Min. : 134503 Min. :1.00
## NA's:1 NA's :1 1st Qu.: 2997 1st Qu.: 367710 1st Qu.:2.75
## Median : 4523 Median : 676791 Median :4.50
## Mean : 5626 Mean :1047330 Mean :4.50
## 3rd Qu.: 7001 3rd Qu.: 929442 3rd Qu.:6.25
## Max. :13614 Max. :4162459 Max. :8.00
##
## geometry
## MULTIPOLYGON :8
## epsg:4326 :0
## +proj=long...:0
##
##
##
##
Mapeamos todos los shapes que tenemos hasta el momento.
ggplot() +
geom_sf(data = barrios) +
geom_sf(data = calles, color = "grey") +
geom_sf(data = ria_mercator , color='blue') +
geom_sf(data = Bilbao_hostels_U, shape = 21, fill = "red", size = 5) +
labs(title = "Mapa de hostels en la ciudad de Bilbao", caption = "Fuente: OpenStreetMap", y="Latitud", x="Longitud") +
theme_light()

hostels_por_barrios <- st_join(Bilbao_hostels_U, barrios)
names(hostels_por_barrios)
## [1] "osm_id" "name" "addr.city"
## [4] "addr.district" "addr.housenumber" "addr.postcode"
## [7] "addr.street" "addr.suburb" "air_conditioning"
## [10] "beds" "designation" "email"
## [13] "guest_house" "internet_access" "internet_access.fee"
## [16] "opening_hours" "operator" "phone"
## [19] "rooms" "source" "source.url"
## [22] "tourism" "website" "wheelchair"
## [25] "BAR_CL" "BAR_BARR" "barrios_bilbao"
## [28] "BAR_MUNI" "BAR_MUNI_D" "BAR_PROV"
## [31] "BAR_PROV_D" "Shape_Leng" "Shape_Area"
## [34] "distrito" "geometry"
Sacamos la cantidad de hostels que tenemos por barrios.
barrios_bilbao_cantidad <- hostels_por_barrios %>%
group_by(barrios_bilbao) %>%
summarise(cantidad = n())
barrios_bilbao_cantidad
## Simple feature collection with 6 features and 2 fields
## geometry type: GEOMETRY
## dimension: XY
## bbox: xmin: -2.963484 ymin: 43.24647 xmax: -2.909634 ymax: 43.26877
## CRS: EPSG:4326
## # A tibble: 6 x 3
## barrios_bilbao cantidad geometry
## * <chr> <int> <GEOMETRY [°]>
## 1 Abando 3 MULTIPOINT ((-2.943954 43.25818), (-2.93537 43.~
## 2 Bilbao la Vieja 22 MULTIPOINT ((-2.928026 43.25579), (-2.925355 43~
## 3 Bolueta 14 MULTIPOINT ((-2.910163 43.24669), (-2.910155 43~
## 4 Deusto 1 POINT (-2.954546 43.26877)
## 5 Diseminado Basurtu-~ 12 MULTIPOINT ((-2.963484 43.26073), (-2.963405 43~
## 6 Uribarri 1 POINT (-2.912549 43.25955)
Ploteamos los hostels por barrios y los hitos turísticos de la ciudad de Bilbao.
ggplot() +
geom_sf(data = barrios) +
geom_sf(data = ria_mercator , color='blue') +
geom_sf(data = barrios_bilbao_cantidad, aes(color = barrios_bilbao),size = 5) +
geom_sf(data = turistico_mercator, color = 'black', shape = 4 ,size = 2) +
labs(title = "Mapa hostels e hitos turísticos por barrios ciudad de Bilbao", caption = "Fuente: OpenStreetMap", y="Latitud", x="Longitud") +
theme_light()

barrios_bilbao_cantidad <- barrios_bilbao_cantidad %>%
st_set_geometry(NULL)
barrios <- barrios %>%
left_join(barrios_bilbao_cantidad, by="barrios_bilbao")
Mapa coroplético de hostels por barrios.
ggplot() +
geom_sf(data = barrios, aes(fill=(cantidad/Shape_Area)*10000)) +
geom_sf(data = ria_mercator , color='blue') +
geom_sf_text(data=barrios, aes(label = barrios_bilbao), size=3 , colour = "black")+
labs(title = "Mapa hostels por barrios",
subtitle = "Ciudad de Bilbao - España",
fill = "Cantidad",
caption= "Fuente: OpenStreetMap",
y="Latitud",
x="Longitud") +
scale_fill_viridis_c() +
theme_light()

Traemos el mapa de oferta turística por barrios y lo comparamos con la oferta de hostels por barrios.
knitr::include_graphics("oferta_turistica_barrio_vir.png")

Como se puede observar, la mayor oferta de hostel tiene correlato con la oferta de hitos turístico. Los hostels se encuentran distribuidos de manera equitativa con los hitos turisticos. En el barrio de Bilbao la Vieja, Bolueta y Diseminado Basurtu - Zorrotza encontramos que el OSM tiene cargados, lo que entendemos, son mismos hostels pero con una leve diferencia en las coordenadas. Esta observación impacta en el mapa coroplético ya que muestra a los barrios con gran cantidad de hostels, cuando en la realidad no es así.
Con este ultimo Chunk damos por finalizado el TP2.-