## ----gadm, message=FALSE, warning=FALSE--------------------------------------- library(geodata) adm <- gadm("TZA", level = 1, path=".") ## ----rdtp--------------------------------------------------------------------- library(osmdata) roadtypes <- c("primary", "secondary", "tertiary") getOSMdata <- function(obj, key, value) { b <- sp::bbox(obj) q <- osmdata::opq(b) q <- osmdata::add_osm_feature(q, key, value) d <- osmdata::osmdata_sp(q) d$osm_lines[, key] } ## ----getOSM, eval=FALSE------------------------------------------------------- ## x <- lapply(seq_along(adm), function(i) getOSMdata(adm[i, ], "highway", roadtypes)) ## ----processOSM, eval=FALSE--------------------------------------------------- ## # combine the results for each area ## rd <- do.call(bind, x) ## # remove anything outside of Tanzania ## rd <- crop(rd, adm) ## # aggregate by type, also removing duplicates line parts ## roads <- aggregate(rd, "highway") ## ----simplr, eval=FALSE------------------------------------------------------- ## library(rmapshaper) ## roads <- ms_simplify(roads, keep=0.01)