Skip to content

Instantly share code, notes, and snippets.

@walkerke
Created November 13, 2022 16:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkerke/a0f4c4874495d65ce9a8b814880d9226 to your computer and use it in GitHub Desktop.
Save walkerke/a0f4c4874495d65ce9a8b814880d9226 to your computer and use it in GitHub Desktop.
library(mapboxapi)
library(tidyverse)
library(sf)
library(patchwork)
city_halls <- c(
"New York" = "City Hall Park, New York, NY 10007",
"Los Angeles" = "200 N Spring St, Los Angeles, CA 90012",
"Chicago" = "121 N La Salle St, Chicago, IL 60602",
"Houston" = "901 Bagby St, Houston, TX 77002",
"Phoenix" = "200 W Washington St, Phoenix, AZ 85003",
"Philadelphia" = "1400 John F Kennedy Blvd, Philadelphia, PA 19107",
"San Antonio" = "100 Military Plaza #4, San Antonio, TX 78205",
"San Diego" = "Civic Ctr Plz, San Diego, CA 92101",
"Dallas" = "1500 Marilla St, Dallas, TX 75201",
"San Jose" = "200 E Santa Clara St, San Jose, CA 95113"
)
# Build out the mapping workflow
plots <- imap(city_halls, ~{
print(glue::glue("Working on {.y}..."))
# Get an isochrone - 5 minute drive
iso <- mb_isochrone(.x, time = 5, profile = "walking")
# Query the tiles
vector_extract <- get_vector_tiles(
tileset_id = "mapbox.mapbox-streets-v8",
location = iso,
zoom = 15
)
# Intersect the buildings with the buffer
buildings_extract <- vector_extract$building %>%
st_intersection(iso)
# Plot the result
ggplot() +
geom_sf(data = iso, color = "black", fill = "white") +
geom_sf(data = buildings_extract, fill = "navy", color = "navy") +
theme_void() +
labs(title = .y) +
theme(plot.title = element_text(hjust = 0.5))
})
wrap_plots(plots, ncol = 5) +
plot_annotation(caption = "Building footprints within a 5 minute walk of respective city halls.\nGraphic by @kyle_e_walker; data © Mapbox, OpenStreetMap contributors")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment