osm_keyValueDL | R Documentation |
Downloads multiple vector datasets from Open Street Maps given a dataframe of key-value pairs and a bounding box.
osm_keyValueDL(keyValDF, bbox)
keyValDF |
Dataframe with two columns, 'key' and 'value'. Can be created
with |
bbox |
the bounding box for the download area |
A list with class osmdata containing the spatial data within its elements.
First created in 2020-11-03 with the script OSMdownloadAndSFtoSQLInterface.R in the MARC-KC/HelpLibrary Repository
Jacob Peterson
## Not run: library(sf) # devtools::install_github('yonghah/esri2sf') library(esri2sf) library(dplyr) library(osmdata) #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Download MARC Boundaries #### #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ MARCprojection <- paste0( "+proj=tmerc +lat_0=36.16666666666666 +lon_0=-94.5 +k=0.9999411764705882 ", "+x_0=850000 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 ", "+no_defs") #For fixing column names form the table joins removeColnamePrefix <- function(df) { names(df) <- sub('.*\\.', '', names(df)) %>% ave(., ., FUN = function(i) paste0(i, '_', seq_along(i))) %>% gsub("_1$", "", .) df } MARCjurisdictions <- esri2sf::esri2sf(url = "https://gis2.marc2.org/arcgis/rest/services/HumanServices/COVIDv2/MapServer/0") %>% sf::st_make_valid() %>% #fixes some issues with data coming from ESRI sf::st_transform(MARCprojection) %>%#puts it in MARC cordinates removeColnamePrefix() #For fixing column names form the table joins #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Create Bounding Box #### #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bb_sf <- MARCjurisdictions %>% sf::st_transform(crs = 4326) %>% sf::st_bbox() #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Download Data for multiple Key Value Sets #### #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ df <- tibble::tribble( ~key, ~value, "highway", "motorway", "highway", "trunk", "highway", "primary", ) #download data test <- osm_keyValueDL(df, bb_sf) #simple plot test$osm_lines %>% sf::st_geometry() %>% plot() #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.