Last active
April 19, 2024 23:35
-
-
Save walkerke/d10745094fda47303fd981e421762f7e to your computer and use it in GitHub Desktop.
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
library(mapboxapi) | |
library(mapview) | |
mb_access_token("YOUR TOKEN GOES HERE") | |
isos <- mb_isochrone("2500 Victory Ave, Dallas TX", | |
time = c(5, 10, 15), | |
profile = "driving-traffic") | |
mapview(isos, zcol = "time", | |
layer.name = "Drive-time to<br/>American Airlines Center") | |
library(sf) | |
# Data: https://egis.dallascityhall.com/resources/Downloads/ShpZip/Library/Libraries.zip | |
dallas_libraries <- st_read("~/Downloads/Libraries.shp") | |
library_isos <- mb_isochrone( | |
dallas_libraries, | |
time = 5, | |
profile = "driving-traffic", | |
id_column = "Library" | |
) | |
mapview(library_isos, | |
layer.name = "5 minute drive-times<br/>around Dallas libraries") | |
library(dplyr) | |
distance_isos <- mb_isochrone("2500 Victory Ave, Dallas TX", | |
distance = c(5000, 10000, 15000), | |
profile = "driving") %>% | |
mutate(km = distance / 1000) | |
mapview(distance_isos, zcol = "km", | |
layer.name = "Driving distances to<br/>American Airlines Center (km)") | |
walking_isos <- mb_isochrone("2500 Victory Ave, Dallas TX", | |
time = c(5, 10, 15), | |
profile = "walking") | |
mapview(walking_isos, zcol = "time", | |
layer.name = "Walk-times to<br/>American Airlines Center") | |
library(fasterize) | |
library(leaflet) | |
surface_isos <- mb_isochrone( | |
location = "2500 Victory Ave, Dallas TX", | |
profile = "driving", | |
time = 1:60 | |
) %>% | |
st_transform(26914) | |
pal <- colorNumeric("viridis", surface_isos$time, na.color = "transparent") | |
template <- raster(surface_isos, resolution = 100) | |
iso_surface <- fasterize(surface_isos, template, field = "time", fun = "min") | |
leaflet() %>% | |
addTiles() %>% | |
addRasterImage(iso_surface, colors = pal, opacity = 0.5) %>% | |
addLegend(values = surface_isos$time, pal = pal, | |
title = "Drive-time to AAC") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment