mr_shp | R Documentation |
Get a region shp file
mr_shp( key = NULL, name = NULL, maxFeatures = 500, overwrite = TRUE, read = TRUE, filter = NULL, ... )
key |
(character) Region key, of the form |
name |
(character) Region name, if you supply this, we search
against titles via |
maxFeatures |
(integer) Number of features |
overwrite |
(logical) Overwrite file if already exists.
Default: |
read |
(logical) To read in as spatial object. If |
filter |
(character) String to filter features on |
... |
Curl options passed on to |
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.
A SpatialPolygonsDataFrame
if read = TRUE
, or a path to
a SHP file on disk if read = FALSE
.
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.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.