From: Frederik Vanrenterghem Date: Tue, 27 Feb 2024 14:30:01 +0000 (+0800) Subject: Voeg analyse samenvatting Red Rooster OSM toe. X-Git-Url: http://git.vanrenterghem.biz/www2.vanrenterghem.biz.git/commitdiff_plain/0102e884f848ce0ff586cf1035d90e0cf01a7d7a?hp=e0633cd234ccf6cfd02063ffae5950d9cf5ef1c1 Voeg analyse samenvatting Red Rooster OSM toe. --- diff --git a/source/posts/Red_Rooster_line.org b/source/posts/Red_Rooster_line.org new file mode 100644 index 0000000..7e733b6 --- /dev/null +++ b/source/posts/Red_Rooster_line.org @@ -0,0 +1,41 @@ +#+date: <2024-02-27 Tue 22:27> +#+filetags: :R:spatial:analysis:visualisation:open_web: +#+title: Sydney's Red Rooster line. + +#+BEGIN_PREVIEW + +Listening to ABC Radio National a couple of weeks ago, I learned about Sydney's Red Rooster line. It's a straight line that can be drawn across Sydney marking the socio-economic divide that exists between the northern and eastern suburbs of Sydney and the western and soutwestern ones. Out of curiosity, I set out to explore this using data available on the open web, in particular [[https://welcome.openstreetmap.org/what-is-openstreetmap/][OpenStreetMap]]. + +#+ATTR_HTML: :class img-fluid :alt Map of Sydney with Red Rooster line +[[file:../assets/Sydney_Red_Rooster_line.png]] + +The above map was drawn in R using [[https://www.openstreetmap.org/][OpenStreetMap]] data for all its components. + +#+END_PREVIEW + +In R, obtaining data from OpenStreetMap is most easily done using the ~osmdata~ library, which provides functions to create and send an Overpass query. For instance, the snippet below obtains all locations that have been tagged as a fast food amenity within a geographical bounding box. In the same way, all roads, waterways and suburb boundaries can be obtained. + +#+BEGIN_SRC R +fastfood <- lapply(bb, function(x) { + opq(x, timeout = 50) |> + add_osm_feature("amenity", "fast_food") |> + osmdata_sf()}) +#+END_SRC + +One of the quirks of the returned data is that any geometrical shape that has an element of it within the bounding box of the query is returned in whole. When rendered on a map surface, this results in the map exceeding the boundaries of the bounding box. Using the ~st_intersection()~ function this can be corrected relatively easily. + +More difficult is rendering the ocean in a particular color, as there is no polygon returned for the partial ocean within the query geometry. This contrary to waterways and lakes. I solved this creating an outline for the overall land area within the bounding box, and subtracting that area from its bounding box area. + +#+BEGIN_SRC R +outlines <- st_union(osm_multipolygons) + +ocean <- function() { + a <- st_difference(boundingBoxSfc, outlines) + a <- st_transform(a, crs = st_crs(outlines)) + return(a)} +#+END_SRC + +In the full code, available on [[http://git.vanrenterghem.biz/R/openstreetmap-red-rooster-locations-analysis.git][my git server]], I also plot Perth to see whether the same socio-economic dividing line can be found over here in Western Australia's capital. It's certainly possible to see the affluent western suburbs are not as well served by Red Rooster as the eastern and southern ones: + +#+ATTR_HTML: :class img-fluid :alt Map of Perth with Red Rooster locations +[[file:../assets/Perth_Red_Rooster_locations.png]]