osm_keyValueDL: Easily Download Open Street Map Data

Description Usage Arguments Value Creation notes Author(s) Examples

View source: R/OSMhelpers.R

Description

Downloads multiple vector datasets from Open Street Maps given a dataframe of key-value pairs and a bounding box.

Usage

1
osm_keyValueDL(keyValDF, bbox)

Arguments

keyValDF

Dataframe with two columns, 'key' and 'value'. Can be created with osm_keyValueDF()

Value

A list with class osmdata containing the spatial data within its elements.

Creation notes

First created in 2020-11-03 with the script OSMdownloadAndSFtoSQLInterface.R in the MARC-KC/HelpLibrary Repository

Author(s)

Jacob Peterson

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
## Not run: 
library(sf)
# devtools::install_github('yonghah/esri2sf')
library(esri2sf)
library(dplyr)
library(osmdata)


#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Download MARC Boundaries ####
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MARCprojection <- "+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)

MARC-GIS/marcR documentation built on Nov. 16, 2020, 1:41 p.m.