From b5f51faff038ac259f5988ae983b621c007fb48e Mon Sep 17 00:00:00 2001 From: Clementine Cottineau Date: Mon, 13 May 2024 09:55:11 +0200 Subject: [PATCH] Update episodes/18-import-and-visualise-osm-data.Rmd Co-authored-by: Claudiu Forgaci <33600128+cforgaci@users.noreply.github.com> --- episodes/18-import-and-visualise-osm-data.Rmd | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/episodes/18-import-and-visualise-osm-data.Rmd b/episodes/18-import-and-visualise-osm-data.Rmd index 05aae9a2..a6843488 100644 --- a/episodes/18-import-and-visualise-osm-data.Rmd +++ b/episodes/18-import-and-visualise-osm-data.Rmd @@ -210,21 +210,25 @@ We have produced a proof a concept on Brielle, but can we factorise our work to We might replace the name in the first line and run everything again. Or we can create a function. ```{r reproducibility} extract_buildings <- function(cityname, year=1900){ -nominatim_polygon <- geo_lite_sf(address = cityname, points_only = FALSE) -bb <- st_bbox(nominatim_polygon) -x <- opq(bbox = bb) %>% - add_osm_feature(key = 'building') %>% - osmdata_sf() -buildings <- x$osm_polygons %>% - st_transform(.,crs=28992) -start_date <- as.numeric(buildings$start_date) -buildings$build_date <- if_else(start_date < year, year, start_date) - ggplot(data = buildings) + - geom_sf(aes(fill = build_date, colour=build_date)) + - scale_fill_viridis_c(option = "viridis")+ - scale_colour_viridis_c(option = "viridis") + - ggtitle(paste0("Old buildings in ",cityname)) + - coord_sf(datum = st_crs(28992)) + nominatim_polygon <- geo_lite_sf(address = cityname, points_only = FALSE) + bb <- st_bbox(nominatim_polygon) + + x <- opq(bbox = bb) %>% + add_osm_feature(key = 'building') %>% + osmdata_sf() + + buildings <- x$osm_polygons %>% + st_transform(.,crs=28992) + + start_date <- as.numeric(buildings$start_date) + + buildings$build_date <- if_else(start_date < year, year, start_date) + ggplot(data = buildings) + + geom_sf(aes(fill = build_date, colour=build_date)) + + scale_fill_viridis_c(option = "viridis")+ + scale_colour_viridis_c(option = "viridis") + + ggtitle(paste0("Old buildings in ",cityname)) + + coord_sf(datum = st_crs(28992)) } #test on Brielle