ruegen <- osmdata::getbb("Rügen")
plot(ruegen)# We see two points, which build the extremes of the bounding box.Introduction to Geospatial Techniques for Social Scientists in R
Stefan Jünger, Anne-Kathrin Stroppe, Dennis Abel
Pick a city of the world to your liking and retrieve its bounding box. Then plot it: What do you see?
The function you may search for is part of the osmdata package. Have a look at the slides.
Please choose a couple of building types you are interested in and set them as key and value pairs. You can find a list of building types in the Overpass API documentation. But don’t forget to set the timeout query parameters using the osmdata::opq() function first.
First, specify the bounding box like before; second, the query parameters; and third, the key and value pairs. Try using a pipe workflow, as it makes it easier.
Download the data using the osmdata::osmdata_sf() function and extract only the polygons.
The downloaded data is a list. The polygons are a named list element that you can extract with its name osm_polygons, just like a variable in a data table.
Take some time to browse through the data. Depending on your chosen building type, you may find some interesting information. You can also plot the data you have just downloaded.
You may consider converting the data into a tibble using tibble::as_tibble() and maybe a sf::st_as_sf() afterward for a nicer browsing experience.
Bonus: If you aiming to use tmap
Warning: Paket 'ggplot2' wurde unter R Version 4.4.3 erstellt
Simple feature collection with 4822 features and 88 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 13.11521 ymin: 54.22811 xmax: 13.75383 ymax: 54.68018
Geodetic CRS: WGS 84
# A tibble: 4,822 × 89
osm_id name abandoned `addr:city` `addr:country` `addr:hamlet`
<chr> <chr> <chr> <chr> <chr> <chr>
1 28430840 <NA> <NA> <NA> <NA> <NA>
2 29418125 <NA> <NA> <NA> <NA> <NA>
3 29418219 Koloss von Prora… <NA> <NA> <NA> <NA>
4 30151636 <NA> <NA> Mönchgut DE <NA>
5 30151653 <NA> <NA> Mönchgut DE <NA>
6 31144258 <NA> <NA> <NA> <NA> <NA>
7 38657041 <NA> <NA> Bergen auf… DE <NA>
8 39839282 <NA> <NA> <NA> <NA> <NA>
9 39839294 <NA> <NA> <NA> <NA> <NA>
10 42451069 <NA> <NA> <NA> <NA> <NA>
# ℹ 4,812 more rows
# ℹ 83 more variables: `addr:housename` <chr>, `addr:housenumber` <chr>,
# `addr:place` <chr>, `addr:postcode` <chr>, `addr:street` <chr>,
# `addr:suburb` <chr>, air_conditioning <chr>, alt_name <chr>, amenity <chr>,
# architect <chr>, `architect:wikidata` <chr>, beds <chr>, building <chr>,
# `building:architecture` <chr>, `building:colour` <chr>,
# `building:flats` <chr>, `building:levels` <chr>, …