knitr::opts_chunk$set( warning = FALSE, message = FALSE, collapse = TRUE, comment = "#>" )
mregions
- Get data from https://www.marineregions.org
Some data comes from the Flanders Marine Institute (VLIZ) geoserver
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:
install.packages("mregions") install.packages("sf")
Development version
devtools::install_github("ropensci/mregions")
Load Libraries
library("mregions") library("sf") # helper library library("leaflet")
Get Data
Keys accessible from the Flanders Marine Institute (VLIZ) geoserver.
ecoregions_geoJSON <- mr_geojson(key = "Ecoregions:ecoregions", maxFeatures = 250) length(ecoregions_geoJSON$features)
Plot Data
leaflet() %>% addProviderTiles(provider = 'OpenStreetMap') %>% addGeoJSON(geojson = ecoregions_geoJSON$features) %>% fitBounds(-160,-52,160,60)
Get Data
eezboundaries_geoJSON <- mr_geojson(key = "MarineRegions:eez", maxFeatures = 1)
Plot Data
leaflet() %>% addProviderTiles(provider = 'OpenStreetMap') %>% addGeoJSON(geojson = eezboundaries_geoJSON$features) %>% fitBounds(39,11,83,-10)
Select region
ecoregions_shp <- mr_shp(key = "Ecoregions:ecoregions", maxFeatures = 250) class(ecoregions_shp)
Plot data
leaflet() %>% addProviderTiles(provider = 'OpenStreetMap') %>% addPolygons(data = ecoregions_shp)%>% fitBounds(-182,-79,178,83)
Select region
eezboundaries_shp <- mr_shp(key = "MarineRegions:eez", maxFeatures = 1)
Plot data
leaflet() %>% addProviderTiles(provider = 'OpenStreetMap') %>% addPolygons(data = eezboundaries_shp)
From GeoJSON
ecoregions_geoJSON <- mr_geojson(key = "Ecoregions:ecoregions", maxFeatures = 250) ecoregions_wkt_fromGeoJSON <- mr_as_wkt(ecoregions_geoJSON, fmt = 2) class(ecoregions_wkt_fromGeoJSON) ecoregions_wkt_fromGeoJSON[1]
From shp object (using the sf package)
ecoregions_shp <- mr_shp(key = "Ecoregions:ecoregions", maxFeatures = 250) ecoregions_shp_geom <- st_geometry(ecoregions_shp) ecoregions_wkt_fromshp <- st_as_text(ecoregions_shp_geom) ecoregions_wkt_fromshp[1]
More detailed example using the Black Sea Ecoregion only
ecoregions_blacksea <- subset(ecoregions_shp, ecoregions_shp$ecoregion == "Black Sea") class(ecoregions_blacksea) ecoregions_blacksea_geom <- st_geometry(ecoregions_blacksea) class(ecoregions_blacksea_geom) ecoregions_blacksea_wkt <- st_as_text(ecoregions_blacksea_geom) class(ecoregions_blacksea_wkt) ecoregions_blacksea_wkt
highseas_info <- mr_geo_code(place = "High Seas") class(highseas_info) str(highseas_info)
mregions
in R doing citation(package = 'mregions')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.