mr_shp: Get a region shp file

Description Usage Arguments Details Value Note Examples

View source: R/region_shp.R

Description

Get a region shp file

Usage

1
2
mr_shp(key = NULL, name = NULL, maxFeatures = 50, overwrite = TRUE,
  read = TRUE, filter = NULL, ...)

Arguments

key

(character) Region key, of the form x:y, where x is a namespace (e.g., MarineRegions), and y is a region (e.g., eez_33176)

name

(character) Region name, if you supply this, we search against titles via mr_names function

maxFeatures

(integer) Number of features

overwrite

(logical) Overwrite file if already exists. Default: FALSE

read

(logical) To read in as spatial object. If FALSE a path given back. if TRUE, you need the rgdal package installed. Default: FALSE

filter

(character) String to filter features on

...

Curl options passed on to GET. since we use caching, note that if you've made the exact same request before and the file is still in cache, we grab the cached file and don't make an HTTP request, so any curl options passed would be ignored.

Details

We use rappdirs to determine where to cache data depening on your operating system. See rappdirs::user_cache_dir("mregions") for location on your machine

We cache based on the name of the region plus the maxFeatures parameter. That is to say, you can query the same region name, but with different maxFeatures parameter values, and they will get cached separately. You can clear the cache by going to the directory at rappdirs::user_cache_dir("mregions") and deleting the files.

We use stringsAsFactors = FALSE inside of rgdal::readOGR() so that character variables aren't converted to factors.

Value

A SpatialPolygonsDataFrame if read = TRUE, or a path to a SHP file on disk if read = FALSE.

Note

the parameter name is temporarily not useable. MarineRegions updated their web services, and we haven't sorted out yet how to make this feature work. We may bring it back in future version of this pacakge.

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
## Not run: 
## just get path
mr_shp(key = "MarineRegions:eez_iho_union_v2", read = FALSE)
## read shp file into spatial object
res <- mr_shp(key = "MarineRegions:eez_iho_union_v2", read = TRUE)

mr_shp(key = "SAIL:w_marinehabitatd")

# maxFeatures
library(sp)
plot(mr_shp(key = "MarineRegions:eez_iho_union_v2"))
plot(mr_shp(key = "MarineRegions:eez_iho_union_v2", maxFeatures = 5))

# vizualize with package leaflet
if (requireNamespace("leaflet")) {
  library('leaflet')
  leaflet() %>%
    addTiles() %>%
    addPolygons(data = res)
}

# use `filter` param to get a subset of a region
library(sp)
pp <- mr_shp(key = "MarineRegions:eez_iho_union_v2")
plot(pp)
rr <- mr_shp(key = "MarineRegions:eez_iho_union_v2",
  filter = "North Atlantic Ocean")
plot(rr)

# get Samoan Exclusive Economic Zone
res <- mr_shp(
  key = "MarineRegions:eez",
  filter = "Samoan Exclusive Economic Zone"
)
sp::plot(res)

## End(Not run)

mregions documentation built on May 2, 2019, 6:53 a.m.