Created
November 13, 2021 04:15
-
-
Save dakvid/23b3111ddb37da97d7ce5b1135d630dd to your computer and use it in GitHub Desktop.
#30DayMapChallenge 2021 - Day 08 - Blue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The monochrome cityscape of Wellington, inspired by several blog | |
# posts and challenge submissions (haven't noted them all). | |
# I used my work's dark blue and highlighted the office building. | |
# It didn't stand out as much as I expected (obvious in hindsight) | |
# but I left it in anyway. :-) | |
# -- David Friggens, November 2021 | |
# Setup ------------------------------------------------------------------- | |
library(magrittr) | |
library(dplyr) | |
library(sf) | |
library(osmdata) | |
library(ggplot2) | |
library(showtext) | |
showtext_auto() | |
font_add_google("Miriam Libre", "miriam_libre") | |
MAP_FONT <- "miriam_libre" | |
DARK_BLUE <- "#003352" | |
ORANGE <- "#ff6600" | |
# OSM data ---------------------------------------------------------------- | |
bbox_wellington <- | |
getbb("Wellington, New Zealand") | |
major_streets <- | |
bbox_wellington %>% | |
opq() %>% | |
add_osm_feature( | |
key = "highway", | |
value = c("motorway", "motorway_junction", "motorway_link", | |
"primary", "primary_link", "raceway", "secondary", "secondary_link", | |
"tertiary", "teriary_link", "trunk", "trunk_link") | |
) %>% | |
osmdata_sf() %>% | |
extract2("osm_lines") | |
minor_streets <- | |
bbox_wellington %>% | |
opq() %>% | |
add_osm_feature( | |
key = "highway", | |
value = c("bridleway", "cycleway", "footway", "living_street", | |
"path", "pedestrian", "residential", "road", "service", "steps", | |
"track", "unclassified") | |
) %>% | |
osmdata_sf() %>% | |
extract2("osm_lines") | |
buildings <- | |
bbox_wellington %>% | |
opq() %>% | |
add_osm_feature( | |
key = "building" | |
) %>% | |
osmdata_sf() %>% | |
extract2("osm_polygons") | |
rail <- | |
bbox_wellington %>% | |
opq() %>% | |
add_osm_feature( | |
key = "railway", | |
value = c("rail", "funicular") | |
) %>% | |
osmdata_sf() %>% | |
extract2("osm_lines") | |
# Restrict to circle ------------------------------------------------------ | |
plimmer_coords <- | |
tibble(lat = -41.286, lon = 174.775) | |
CRS_NZ <- 2193L | |
CRS_LL <- 4326L | |
RADIUS <- 2000 | |
circle <- | |
plimmer_coords %>% | |
st_as_sf(coords = c("lon", "lat"), | |
crs = CRS_LL) %>% | |
st_transform(crs = CRS_NZ) %>% | |
st_buffer(dist = RADIUS) %>% | |
st_transform(crs = CRS_LL) | |
circle_major <- | |
major_streets %>% | |
st_intersection(circle) | |
circle_minor <- | |
minor_streets %>% | |
st_intersection(circle) | |
circle_rail <- | |
rail %>% | |
st_intersection(circle) | |
plimmer_tower <- | |
buildings %>% | |
filter(name == "Plimmer Tower") | |
circle_buildings <- | |
buildings %>% | |
# ?? "Evaluation error: Found 2 features with invalid spherical geometry" ?? | |
filter(! osm_id %in% c("977349100", "977349101"), | |
name != "Plimmer Tower") %>% | |
st_intersection(circle) | |
# Make the map ------------------------------------------------------------ | |
ggplot() + | |
geom_sf( | |
data = circle, | |
color = DARK_BLUE, | |
fill = "white" | |
) + | |
geom_sf( | |
data = circle_minor, | |
color = DARK_BLUE, | |
size = .4, | |
alpha = .65 | |
) + | |
geom_sf( | |
data = circle_major, | |
color = DARK_BLUE, | |
size = .6, | |
alpha = .8 | |
) + | |
geom_sf( | |
data = circle_rail, | |
color = DARK_BLUE, | |
size = .5, | |
alpha = .8 | |
) + | |
geom_sf( | |
data = circle_buildings, | |
fill = DARK_BLUE, | |
lwd = 0, | |
alpha = .3 | |
) + | |
geom_sf( | |
data = plimmer_tower, | |
fill = ORANGE, | |
lwd = 0, | |
alpha = .8 | |
) + | |
geom_text( | |
aes(x = 174.751, y = -41.303, geometry = NULL), | |
label = "Wellington CBD", | |
size = 20, colour = "white", hjust = 0, | |
family = MAP_FONT | |
) + | |
geom_text( | |
aes(x = 174.751, y = -41.3045, geometry = NULL), | |
label = "#30DayMapChallenge 2021 - Day 08 - Blue", | |
size = 12, colour = "white", hjust = 0, | |
family = MAP_FONT | |
) + | |
geom_text( | |
aes(x = 174.799, y = -41.3035, geometry = NULL), | |
label = "David Friggens @dakvid", | |
size = 12, colour = "white", hjust = 1, | |
family = MAP_FONT | |
) + | |
geom_text( | |
aes(x = 174.799, y = -41.3045, geometry = NULL), | |
label = "Data © OpenStreetMap", | |
size = 10, colour = "white", hjust = 1, | |
family = MAP_FONT | |
) + | |
coord_sf(datum = NA) + | |
theme_void() + | |
theme(plot.background = element_rect(fill = DARK_BLUE, colour = DARK_BLUE), | |
panel.background = element_rect(fill = DARK_BLUE, colour = DARK_BLUE)) | |
ggsave("Day_08/Day_08_Wellington_CBD.png", | |
width = 10, height = 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment