Skip to content

Commit

Permalink
Update episodes/18-import-and-visualise-osm-data.Rmd
Browse files Browse the repository at this point in the history
Co-authored-by: Claudiu Forgaci <[email protected]>
  • Loading branch information
Clementine Cottineau and cforgaci authored May 13, 2024
1 parent 9b2fb07 commit b5f51fa
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions episodes/18-import-and-visualise-osm-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b5f51fa

Please sign in to comment.