knitr::opts_chunk$set( comment = "#>", collapse = TRUE, warning = FALSE, message = FALSE )
mregions
is useful to a wide diversity of R users because you get access to all of the
data MarineRegions has, which can help in a variety of use cases:
Stable version
install.packages("mregions")
Dev version
devtools::install_github("ropensci/mregions") install.packages("leaflet")
library("mregions")
res <- mr_place_types() head(res$type)
res1 <- mr_records_by_type(type = "EEZ") head(res1)
rnames <- mr_names("MarineRegions:iho")
Either pass output of mr_names()
mr_names_search(rnames, "IHO")
or don't (but then mr_names_search()
call takes longer)
mr_names_search("iho", q = "Sea")
res3 <- mr_geojson(key = "Morocco:dam") class(res3) names(res3)
res4 <- mr_shp(key = "Morocco:dam") class(res4)
From geojson or shp. Here, geojson
res7 <- mr_geojson(key = "Morocco:dam") mr_as_wkt(res7, fmt = 5) #> [1] "MULTIPOLYGON (((41.573732 -1.659444, 45.891882 ... cutoff
What if you're WKT string is super long? It's often a problem because some online species occurrence databases that accept WKT to search by geometry bork due to limitations on length of URLs if your WKT string is too long (about 8000 characters, including remainder of URL). One way to deal with it is to reduce detail - simplify.
install.packages("rmapshaper")
Using rmapshaper
we can simplify a spatial object, then search with that.
shp <- mr_shp(key = "MarineRegions:eez_iho_union_v2", maxFeatures = 5)
Visualize
library(leaflet) leaflet() %>% addTiles() %>% addPolygons(data = shp)
Simplify
library("rmapshaper") shp <- ms_simplify(shp)
It's simplified:
library(leaflet) leaflet() %>% addTiles() %>% addPolygons(data = shp)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.