Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elipousson/66f05cab50fcba36b66a923f3b7ea025 to your computer and use it in GitHub Desktop.
Save elipousson/66f05cab50fcba36b66a923f3b7ea025 to your computer and use it in GitHub Desktop.
library(sf)
library(mapbaltimore)
library(tidyverse)
map_theme <- ggplot2::theme(
panel.grid.major = ggplot2::element_line(color = "transparent"),
axis.title = ggplot2::element_text(color = "transparent"),
axis.text = ggplot2::element_text(color = "transparent")
)
buffer <- 1
buffer <- units::set_units(buffer, m)
selected_area_neighborhoods <- c("Baltimore Highlands", "Ellwood Park/Monument")
# alternate selected neighborhood for central Baltimore
# selected_area_neighborhoods <- c("Harwood")
selected_area <- get_area(area_type = "neighborhood",
area_name = selected_area_neighborhoods) %>%
st_transform(4326)
# Context neighborhoods are only used to overall size of the map
context_area_neighborhoods <- c("Greektown",
"CARE",
"Milton-Montford",
"Canton",
"Butcher's Hill",
"Brewers Hill")
# alternate context for central Baltimore
# context_area_neighborhoods <- c("Charles Village", "Oakenshawe", "Greenmount West", "Remington", "East Baltimore Midway", "Charles North")
context_area <- get_area(area_type = "neighborhood",
area_name = context_area_neighborhoods,
union = TRUE)
context_area_bbox <- context_area %>%
st_transform(4326) %>%
st_bbox()
arterial_streets <- streets %>%
filter(sha_class %in% c("MART", "PART", "FWY")) %>%
st_union() %>%
st_transform(4326)
area_arterial_streets <- arterial_streets %>%
st_crop(context_area) %>%
st_transform(4326)
area_park_isochrones <- park_isochrones %>%
st_transform(4326)
area_parks <- parks %>%
st_crop(context_area)
context_area_footways <- osmdata::opq(bbox = context_area_bbox) %>%
osmdata::add_osm_feature(key = "highway", value = "footway") %>%
osmdata::osmdata_sf()
area_park_entrances <- context_area_footways$osm_lines %>%
st_transform(2804) %>%
st_crop(st_buffer(context_area, buffer*150)) %>% # Crop footways to within 150m of the context area
st_intersection(st_buffer(parks, buffer*2)) %>% # Crop footways to within 2m of parks in the area
st_difference(st_union(parks)) %>% # Remove footways within parks
st_centroid() %>% # Find center point of lines
select(name, geometry) %>%
st_transform(4326)
area_park_corners <- parks %>%
st_crop(st_buffer(context_area, buffer*150)) %>%
st_convex_hull() %>%
st_simplify(dTolerance = 0.06) %>%
st_cast(to = "MULTIPOINT") %>%
st_cast(to = "POINT") %>%
select(name, geometry = geoms) %>%
st_transform(4326)
area_parks <- area_parks %>%
st_transform(4326)
area_parks_center <- parks %>%
st_crop(st_buffer(context_area, buffer*150)) %>%
st_centroid() %>%
select(name, geometry = geoms) %>%
st_transform(4326)
area_park_isochrones_points <- bind_rows(area_park_corners,
area_park_entrances,
area_parks_center)
area_park_isochrones <- mapboxapi::mb_isochrone(
area_park_isochrones_points,
time = c(3, 6, 9),
profile = "walking")
park_isochrones <- area_park_isochrones %>%
group_by(time) %>%
summarise(
geometry = st_union(geometry)
) %>%
mutate(
time_alpha = case_when(time == 3 ~ 0.3,
time == 6 ~ 0.2,
time == 9 ~ 0.1)
) %>%
st_transform(4326)
ggplot() +
geom_sf(data = arterial_streets,
color = "gray80") +
geom_sf(data = park_isochrones,
fill = "lightgreen",
color = "gray30",
linetype = "dotted",
aes(alpha = time_alpha)) +
geom_sf(data = selected_area,
fill = NA,
color = "gray20",
linetype = "longdash") +
geom_sf(data = area_parks,
fill = "lightgreen",
color = "darkgreen") +
coord_sf(xlim = c(context_area_bbox[[1]], context_area_bbox[[3]]),
ylim = c(context_area_bbox[[2]],context_area_bbox[[4]])) +
guides(alpha = "none") +
labs(
title = "Walking distance (3, 6, and 9 minutes) from southeast Baltimore parks"
) +
hrbrthemes::theme_ipsum_rc() +
map_theme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment