diff --git a/vignettes/emodnet.wfs.Rmd b/vignettes/emodnet.wfs.Rmd index ac40044..fbacdc7 100644 --- a/vignettes/emodnet.wfs.Rmd +++ b/vignettes/emodnet.wfs.Rmd @@ -1,13 +1,20 @@ --- title: "Accessing and mapping EMODnet data" output: rmarkdown::html_vignette +df_print: "tibble" vignette: > %\VignetteIndexEntry{API details} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- - +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + cache = FALSE +) +``` ## Introduction @@ -25,65 +32,26 @@ pak::pak("EMODnet/emodnet.wfs") ## Explore the EMODnet WFS services with R -For this tutorial we will make use of the `sf`, `dplyr` and `mapview` packages. The simple features `sf` package is a well known standard for dealing with geospatial vector data. The package `dplyr` is a strong library for data manipulation. This package also loads `magrittr`'s pipe operator `%>%` (you could also use the [base pipe](https://r4ds.hadley.nz/workflow-style.html#sec-pipes)), which allows to write pipelines in R. To visualize geometries, `mapview` will create quick interactive maps. +For this tutorial we will make use of the `sf` and `mapview` packages. The simple features `sf` package is a well known standard for dealing with geospatial vector data. To visualize geometries, `mapview` will create quick interactive maps. Run this line to install these packages: ``` r -install.packages(c("sf", "dplyr", "mapview")) +install.packages(c("sf", "mapview")) ``` +EMODnet is organized into [seven thematic lots](https://emodnet.ec.europa.eu/en/emodnet-themes): Bathymetry, Geology, Seabed Habitats, Chemistry, Biology, Physics, and Human Activities, each focusing on a specific aspect of marine data. With the emodnet.wfs package, we can explore and combine the data served by the EMODnet thematic lots through [OGC Web Feature Services](https://en.wikipedia.org/wiki/Web_Feature_Service) or WFS. +Imagine we are interested in seabed substrates. The first step is to choose what EMODnet thematic lot can provide with these data. For that, we can check the services available with the `emodnet_wfs()` function. -With the emodnet.wfs package, we can explore and combine the data served by the [EMODnet lots ](https://emodnet.ec.europa.eu/en/emodnet-themes) through [OGC Web Feature Services](https://en.wikipedia.org/wiki/Web_Feature_Service) or WFS. - -Imagine we are interested in seabed substrates. The first step is to choose what EMODnet lot can provide with these data. For that, we can check the services available with the `emodnet_wfs()` function. - -``` r +```{r, warning=FALSE, message=FALSE} library(emodnet.wfs) library(mapview) -library(dplyr) library(sf) emodnet_wfs() -#> service_name -#> 1 bathymetry -#> 2 biology -#> 3 biology_occurrence_data -#> 4 chemistry_cdi_data_discovery_and_access_service -#> 5 chemistry_cdi_distribution_observations_per_category_and_region -#> 6 chemistry_contaminants -#> 7 chemistry_marine_litter -#> 8 geology_coastal_behavior -#> 9 geology_events_and_probabilities -#> 10 geology_marine_minerals -#> 11 geology_sea_floor_bedrock -#> 12 geology_seabed_substrate_maps -#> 13 geology_submerged_landscapes -#> 14 human_activities -#> 15 physics -#> 16 seabed_habitats_general_datasets_and_products -#> 17 seabed_habitats_individual_habitat_map_and_model_datasets -#> service_url -#> 1 https://ows.emodnet-bathymetry.eu/wfs -#> 2 https://geo.vliz.be/geoserver/Emodnetbio/wfs -#> 3 https://geo.vliz.be/geoserver/Dataportal/wfs -#> 4 https://geo-service.maris.nl/emodnet_chemistry/wfs -#> 5 https://geo-service.maris.nl/emodnet_chemistry_p36/wfs -#> 6 https://geoserver.hcmr.gr/geoserver/EMODNET_SHARED/wfs -#> 7 https://www.ifremer.fr/services/wfs/emodnet_chemistry2 -#> 8 https://drive.emodnet-geology.eu/geoserver/tno/wfs -#> 9 https://drive.emodnet-geology.eu/geoserver/ispra/wfs -#> 10 https://drive.emodnet-geology.eu/geoserver/gsi/wfs -#> 11 https://drive.emodnet-geology.eu/geoserver/bgr/wfs -#> 12 https://drive.emodnet-geology.eu/geoserver/gtk/wfs -#> 13 https://drive.emodnet-geology.eu/geoserver/bgs/wfs -#> 14 https://ows.emodnet-humanactivities.eu/wfs -#> 15 https://prod-geoserver.emodnet-physics.eu/geoserver/ows -#> 16 https://ows.emodnet-seabedhabitats.eu/geoserver/emodnet_open/wfs -#> 17 https://ows.emodnet-seabedhabitats.eu/geoserver/emodnet_open_maplibrary/wfs ``` @@ -91,29 +59,10 @@ emodnet_wfs() The column `service_name` shows services available, while `service_url` has the corresponding base url to perform a WFS request. The Seabed portal should have the data we are looking for. A WFS client can be created by passing the corresponding `service_name` to the function `emodnet_init_wfs_client()`. The layers available to this WFS client are consulted with `emodnet_get_wfs_info()`. -``` r +```{r} seabed_wfs_client <- emodnet_init_wfs_client(service = "seabed_habitats_general_datasets_and_products") -#> ✔ WFS client created successfully -#> ℹ Service: "https://ows.emodnet-seabedhabitats.eu/geoserver/emodnet_open/wfs" -#> ℹ Version: "2.0.0" emodnet_get_wfs_info(wfs = seabed_wfs_client) -#> # A tibble: 72 × 9 -#> # Rowwise: -#> data_source service_name service_url layer_name title abstract class format -#> -#> 1 emodnet_wfs seabed_habitat… https://ow… art17_hab… 2013… "Gridde… WFSF… sf -#> 2 emodnet_wfs seabed_habitat… https://ow… art17_hab… 2013… "Gridde… WFSF… sf -#> 3 emodnet_wfs seabed_habitat… https://ow… art17_hab… 2013… "Gridde… WFSF… sf -#> 4 emodnet_wfs seabed_habitat… https://ow… art17_hab… 2013… "Gridde… WFSF… sf -#> 5 emodnet_wfs seabed_habitat… https://ow… art17_hab… 2013… "Gridde… WFSF… sf -#> 6 emodnet_wfs seabed_habitat… https://ow… art17_hab… 2013… "Gridde… WFSF… sf -#> 7 emodnet_wfs seabed_habitat… https://ow… art17_hab… 2013… "Gridde… WFSF… sf -#> 8 emodnet_wfs seabed_habitat… https://ow… art17_hab… 2013… "Gridde… WFSF… sf -#> 9 emodnet_wfs seabed_habitat… https://ow… carib_eus… 2023… "Output… WFSF… sf -#> 10 emodnet_wfs seabed_habitat… https://ow… biogenic_… Biog… "This l… WFSF… sf -#> # ℹ 62 more rows -#> # ℹ 1 more variable: layer_namespace ``` @@ -121,21 +70,13 @@ emodnet_get_wfs_info(wfs = seabed_wfs_client) Each layer is explained in the `abstract` column. We can see several layers with the information provided by the EU member states for the [Habitats Directive 92/43/EEC reporting](https://www.eea.europa.eu/data-and-maps/data/article-17-database-habitats-directive-92-43-eec-2). We will select the layers about coastal lagoons, mudflats and sandbanks with their respective `layer_name`. -``` r +```{r} habitats_directive_layer_names <- c("art17_hab_1110", "art17_hab_1140", "art17_hab_1150") emodnet_get_layer_info( wfs = seabed_wfs_client, layers = habitats_directive_layer_names ) -#> # A tibble: 3 × 9 -#> # Rowwise: -#> data_source service_name service_url layer_name title abstract class format -#> -#> 1 emodnet_wfs https://ows.emo… seabed_hab… art17_hab… 2013… "Gridde… WFSF… sf -#> 2 emodnet_wfs https://ows.emo… seabed_hab… art17_hab… 2013… "Gridde… WFSF… sf -#> 3 emodnet_wfs https://ows.emo… seabed_hab… art17_hab… 2013… "Gridde… WFSF… sf -#> # ℹ 1 more variable: layer_namespace ``` @@ -143,55 +84,49 @@ emodnet_get_layer_info( We are now ready to read the layers into R with `emodnet_get_layers()`. emodnet.wfs reads the geometries as simple features (See `sf` package) transformed to [4326](https://epsg.io/4326) by default. Specifying another map projection is possible by passing a EPGS code or projection string with `emodnet_get_layers(crs = "your projection")` where crs is a coordinate reference system (CRS). The argument `reduce_layers = TRUE` stack all the layers in one single tibble. Default is FALSE and returns a list of sf objects, one per layer. -``` r +```{r} habitats_directive_layers <- emodnet_get_layers( wfs = seabed_wfs_client, layers = habitats_directive_layer_names, - reduce_layers = TRUE + reduce_layers = TRUE, + outputFormat = "application/json" ) -class(habitats_directive_layers) -#> [1] "sf" "data.frame" - -glimpse(habitats_directive_layers) -#> Rows: 221 -#> Columns: 9 -#> $ gml_id "art17_hab_1110.13", "art17_hab_1110.22", "art17_ha… -#> $ habitat_code "1110", "1110", "1110", "1110", "1110", "1110", "11… -#> $ ms "DK", "ES", "ES", "PT", "PT", "PL", "DK", "FR", "UK… -#> $ region "ATL", "MAC", "MMAC", "MMAC", "MATL", "MBAL", "MBAL… -#> $ cs_ms "U2+", "U1+", "U1+", "XX", "U1-", "U1-", "U1-", "U1… -#> $ country_code "Denmark", "Spain", "Spain", "Portugal", "Portugal"… -#> $ habitat_code_uri "http://dd.eionet.europa.eu/vocabulary/art17_2018/h… -#> $ habitat_description "Sandbanks which are slightly covered by sea water … -#> $ geom MULTISURFACE (POLYGON ((420..., MULTIS… +habitats_directive_layers ``` +Note the use of the `outputFormat` argument in this example. This specifies the file type to request from the service, which can influence how the data is loaded into R. By default, the data is provided in the `GML` format with a geometry type of "MULTISURFACE." However, this geometry type is not widely supported by many software tools, including the `mapview` package. To address this, you can request a different file type, such as GeoJSON, which delivers the geometry as "MULTIPOLYGON"—a format that is more universally compatible. This has been raised before in the [sf community](https://github.com/r-spatial/sf/issues/748). -Run the following code to have a quick look at the layers geometries - -``` r -# Transform to Polygon geometry type from Multisurface -if (unique(st_geometry_type(habitats_directive_layers)) == "MULTISURFACE") { - habitats_directive_layers <- habitats_directive_layers %>% - st_cast(to = "GEOMETRYCOLLECTION") %>% - st_collection_extract(type = "POLYGON") -} - -# Visualize -map <- mapview(habitats_directive_layers, zcol = "habitat_description", burst = TRUE) +Run the following code to have a quick look at the layers geometries. -map +```r +mapview(habitats_directive_layers, zcol = "habitat_description", burst = TRUE) ``` ![plot of chunk unnamed-chunk-6](emodnet.wfs-unnamed-chunk-6-1.png) -EMODnet provides also physics, chemistry, biological or bathymetry data. Explore all the layers available with. +EMODnet provides also physics, chemistry, biological or bathymetry data. Explore all the layers available with: -``` r +```r emodnet_get_all_wfs_info() +#> # A tibble: 1,704 × 9 +#> # Rowwise: +#> data_source service_name service_url layer_name title abstract class format layer_namespace +#> +#> 1 emodnet_wfs bathymetry https://ows.emodnet-bathymetry.eu/wfs download_tiles Bathymetry produ… "Downlo… WFSF… sf emodnet +#> 2 emodnet_wfs bathymetry https://ows.emodnet-bathymetry.eu/wfs contours Depth contours "Genera… WFSF… sf emodnet +#> 3 emodnet_wfs bathymetry https://ows.emodnet-bathymetry.eu/wfs hr_bathymetry_area High resolution … "Layer … WFSF… sf emodnet +#> 4 emodnet_wfs bathymetry https://ows.emodnet-bathymetry.eu/wfs quality_index Quality index "Repres… WFSF… sf emodnet +#> 5 emodnet_wfs bathymetry https://ows.emodnet-bathymetry.eu/wfs sea_names Sea names "Mainta… WFSF… sf world +#> 6 emodnet_wfs bathymetry https://ows.emodnet-bathymetry.eu/wfs source_references Source references "Covera… WFSF… sf emodnet +#> 7 emodnet_wfs bathymetry https://ows.emodnet-bathymetry.eu/wfs undersea_features undersea_features "" WFSF… sf gebco +#> 8 emodnet_wfs biology https://geo.vliz.be/geoserver/Emodnetbio/wfs mediseh_cor_abs_pnt EMODnet Absences… "Coral … WFSF… sf Emodnetbio +#> 9 emodnet_wfs biology https://geo.vliz.be/geoserver/Emodnetbio/wfs mediseh_cor_abs_poly EMODnet Absences… "Coral … WFSF… sf Emodnetbio +#> 10 emodnet_wfs biology https://geo.vliz.be/geoserver/Emodnetbio/wfs mediseh_cymodocea_pnt EMODnet Cymodoce… "Cymodo… WFSF… sf Emodnetbio +#> #> ℹ 1,694 more rows +#> #> ℹ Use `print(n = ...)` to see more rows ``` ## More information