Skip to contents

Get a region shp file

Usage

mr_shp(
  key = NULL,
  name = NULL,
  maxFeatures = 500,
  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 httr::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.

Value

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

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.

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

if (FALSE) {
## 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)
}