Created
September 1, 2020 06:34
-
-
Save rexarski/281200b2bcca2655eb47430a7ce30e30 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(osrm) | |
library(sp) | |
library(cartography) | |
library(leaflet) | |
# Get isochones with a SpatialPointsDataFrame, custom breaks | |
iso <- osrmIsochrone(loc = c(149.1212457, -35.2766747), breaks = seq(from = 0,to = 30, by = 5)) | |
# Map | |
ptm <- proc.time() | |
osm <- getTiles(x = iso, crop = FALSE, type = "osm", zoom = 13) | |
tilesLayer(x = osm) | |
bks <- sort(c(unique(iso$min), max(iso$max))) | |
cols <- paste0(carto.pal("turquoise.pal", n1 = length(bks)-1), 80) | |
choroLayer(spdf = iso, | |
var = "center", breaks = bks, | |
border = NA, col = cols, | |
legend.pos = "topleft",legend.frame = TRUE, | |
legend.title.txt = "Isochrones\n(min)", | |
add = TRUE) | |
plot(apotheke.sp[10,], add=TRUE, col ="red", pch = 20) | |
proc.time() - ptm | |
# Map as leaflet | |
ptm <- proc.time() | |
iso@data$drive_times <- factor(paste(iso@data$min, "to", iso@data$max, "min")) | |
factpal <- colorFactor("RdYlBu", iso@data$drive_times) | |
leaflet() %>% | |
setView(149.1212457, -35.2766747, zoom = 11) %>% | |
addProviderTiles("CartoDB.Positron", group="Greyscale") %>% | |
addMarkers(lng = 149.1212457, lat = -35.2766747, popup = "Starting Point") %>% | |
addPolygons(fill=TRUE, stroke=TRUE, color = "black", | |
fillColor = ~factpal(iso@data$drive_times), | |
weight=0.5, fillOpacity=0.2, | |
data = iso, popup = iso@data$drive_times, | |
group = "Drive Time") %>% | |
addLegend("bottomright", pal = factpal, values = iso@data$drive_time, title = "Drive Time") | |
proc.time() - ptm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment