Skip to content

Instantly share code, notes, and snippets.

@Robinlovelace
Created August 21, 2017 12:16
Show Gist options
  • Save Robinlovelace/d403d85a08166fb90543ed2aa62224fa to your computer and use it in GitHub Desktop.
Save Robinlovelace/d403d85a08166fb90543ed2aa62224fa to your computer and use it in GitHub Desktop.
pkgs = c("osmdata", "sf", "tmap", "devtools")
# install.packages(pkgs) # uncomment this line to install the packages if needs be
lapply(pkgs, library, character.only = TRUE)
city = "harrogate"
distance = 5000 # radius outside city in bounding box in metres
install_github("ropensci/stplanr", ref = "sfr")
city_latlon = tmaptools::geocode_OSM(q = city)
city_sf = st_sf(st_sfc(st_point(city_latlon$coords)))
city_buff = stplanr::geo_buffer(city_sf, dist = distance)
bounding_box = sp::bbox(as_Spatial(st_geometry(city_buff)))
q1 = opq(bbox = bounding_box) %>%
add_osm_feature(key = "highway")
res1 = osmdata_sf(q1)
plot(res1$osm_lines$geometry)
tmap_mode("view")
# qtm(res$osm_lines[sample(nrow(res1$osm_lines), size = 1000),])
q2 = opq(bbox = bounding_box) %>%
add_osm_feature(key = "leisure", value = "park")
res2 = osmdata_sf(q2)
plot(res2$osm_polygons, add = TRUE, col = "green")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment