Created
May 14, 2020 18:46
-
-
Save michaeldorman/ed0006b58bc47b3699eaec4faeb1b70f to your computer and use it in GitHub Desktop.
Plot city streets
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(sf) | |
library(osmdata) | |
location = "Tel-Aviv, Israel" | |
# Get data | |
q = opq(bbox = location) | |
dat = add_osm_feature(q, key = "highway") | |
dat = osmdata_sf(dat) | |
lines = dat$osm_lines | |
pol = dat$osm_polygons | |
pol = st_cast(pol, "MULTILINESTRING") | |
pol = st_cast(pol, "LINESTRING") | |
lines = rbind(lines, pol) | |
# Crop | |
bb = q$bbox | |
bb = strsplit(bb, ",")[[1]] | |
bb = as.numeric(bb) | |
bb = bb[c(2, 4, 1, 3)] | |
names(bb) = c("xmin", "xmax", "ymin", "ymax") | |
bb = st_bbox(bb, crs = 4326) | |
bb = st_as_sfc(bb) | |
lines = st_intersection(lines, bb) | |
lines = st_transform(lines, 32636) | |
# Plot | |
plot(lines[, "highway"], key.pos = NULL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment