diff --git a/vignettes/emodnet.wfs.Rmd b/vignettes/emodnet.wfs.Rmd index fbacdc7..ece0196 100644 --- a/vignettes/emodnet.wfs.Rmd +++ b/vignettes/emodnet.wfs.Rmd @@ -8,123 +8,219 @@ vignette: > %\VignetteEncoding{UTF-8} --- -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - cache = FALSE -) -``` - +Accessing and mapping EMODnet data +================ ## Introduction -The package was designed to make EMODnet vector data layers easily accessible in R. The package allows users to query information on and download data from all available [EMODnet Web Feature Service (WFS) endpoints](https://emodnet.ec.europa.eu/geonetwork/emodnet/eng/catalog.search#/home) directly into their R working environment. Data are managed as [`sf` objects](https://r-spatial.github.io/sf/) which are currently the state-of-the-art in handling of vector spatial data in R. The package also allows user to specify the coordinate reference system of imported data. +The package was designed to make EMODnet vector data layers easily +accessible in R. The package allows users to query information on and +download data from all available [EMODnet Web Feature Service (WFS) +endpoints](https://emodnet.ec.europa.eu/geonetwork/emodnet/eng/catalog.search#/home) +directly into their R working environment. Data are managed as [`sf` +objects](https://r-spatial.github.io/sf/) which are currently the +state-of-the-art in handling of vector spatial data in R. The package +also allows user to specify the coordinate reference system of imported +data. ## Installation You can install the development version of emodnet.wfs from GitHub with: - ``` r pak::pak("EMODnet/emodnet.wfs") ``` ## Explore the EMODnet WFS services with R -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. +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", "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. +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. -```{r, warning=FALSE, message=FALSE} +``` r library(emodnet.wfs) library(mapview) library(sf) -emodnet_wfs() +services <- emodnet_wfs() +services$service_name +#> [1] "bathymetry" "biology" +#> [3] "biology_occurrence_data" "chemistry_cdi_data_discovery_and_access_service" +#> [5] "chemistry_cdi_distribution_observations_per_category_and_region" "chemistry_contaminants" +#> [7] "chemistry_marine_litter" "geology_coastal_behavior" +#> [9] "geology_events_and_probabilities" "geology_marine_minerals" +#> [11] "geology_sea_floor_bedrock" "geology_seabed_substrate_maps" +#> [13] "geology_submerged_landscapes" "human_activities" +#> [15] "physics" "seabed_habitats_general_datasets_and_products" +#> [17] "seabed_habitats_individual_habitat_map_and_model_datasets" ``` +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()`. - -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 layer_namespace +#> +#> 1 emodnet_wfs seabed_habitats_general_datasets_and_products https://ows.emodnet-seab… art17_hab… 2013… "Gridde… WFSF… sf emodnet_open +#> 2 emodnet_wfs seabed_habitats_general_datasets_and_products https://ows.emodnet-seab… art17_hab… 2013… "Gridde… WFSF… sf emodnet_open +#> 3 emodnet_wfs seabed_habitats_general_datasets_and_products https://ows.emodnet-seab… art17_hab… 2013… "Gridde… WFSF… sf emodnet_open +#> 4 emodnet_wfs seabed_habitats_general_datasets_and_products https://ows.emodnet-seab… art17_hab… 2013… "Gridde… WFSF… sf emodnet_open +#> 5 emodnet_wfs seabed_habitats_general_datasets_and_products https://ows.emodnet-seab… art17_hab… 2013… "Gridde… WFSF… sf emodnet_open +#> 6 emodnet_wfs seabed_habitats_general_datasets_and_products https://ows.emodnet-seab… art17_hab… 2013… "Gridde… WFSF… sf emodnet_open +#> 7 emodnet_wfs seabed_habitats_general_datasets_and_products https://ows.emodnet-seab… art17_hab… 2013… "Gridde… WFSF… sf emodnet_open +#> 8 emodnet_wfs seabed_habitats_general_datasets_and_products https://ows.emodnet-seab… art17_hab… 2013… "Gridde… WFSF… sf emodnet_open +#> 9 emodnet_wfs seabed_habitats_general_datasets_and_products https://ows.emodnet-seab… carib_eus… 2023… "Output… WFSF… sf emodnet_open +#> 10 emodnet_wfs seabed_habitats_general_datasets_and_products https://ows.emodnet-seab… biogenic_… Biog… "This l… WFSF… sf emodnet_open +#> # ℹ 62 more rows ``` +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`. - -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 layer_namespace +#> +#> 1 emodnet_wfs https://ows.emodnet-seabedhabitats.eu/geoserver/emodnet_ope… seabed_hab… art17_hab… 2013… "Gridde… WFSF… sf emodnet_open +#> 2 emodnet_wfs https://ows.emodnet-seabedhabitats.eu/geoserver/emodnet_ope… seabed_hab… art17_hab… 2013… "Gridde… WFSF… sf emodnet_open +#> 3 emodnet_wfs https://ows.emodnet-seabedhabitats.eu/geoserver/emodnet_ope… seabed_hab… art17_hab… 2013… "Gridde… WFSF… sf emodnet_open ``` +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. - -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, outputFormat = "application/json" ) +#> Start tag expected, '<' not found +#> Start tag expected, '<' not found +#> Start tag expected, '<' not found habitats_directive_layers +#> Simple feature collection with 221 features and 8 fields +#> Geometry type: MULTIPOLYGON +#> Dimension: XY +#> Bounding box: xmin: 950000 ymin: 940000 xmax: 6510000 ymax: 4820000 +#> Projected CRS: ETRS89-extended / LAEA Europe +#> First 10 features: +#> id habitat_code ms region cs_ms country_code habitat_code_uri +#> 1 art17_hab_1110.13 1110 DK ATL U2+ Denmark http://dd.eionet.europa.eu/vocabulary/art17_2018/habitats/1110 +#> 2 art17_hab_1110.22 1110 ES MAC U1+ Spain http://dd.eionet.europa.eu/vocabulary/art17_2018/habitats/1110 +#> 3 art17_hab_1110.25 1110 ES MMAC U1+ Spain http://dd.eionet.europa.eu/vocabulary/art17_2018/habitats/1110 +#> 4 art17_hab_1110.59 1110 PT MMAC XX Portugal http://dd.eionet.europa.eu/vocabulary/art17_2018/habitats/1110 +#> 5 art17_hab_1110.56 1110 PT MATL U1- Portugal http://dd.eionet.europa.eu/vocabulary/art17_2018/habitats/1110 +#> 6 art17_hab_1110.53 1110 PL MBAL U1- Poland http://dd.eionet.europa.eu/vocabulary/art17_2018/habitats/1110 +#> 7 art17_hab_1110.17 1110 DK MBAL U1- Denmark http://dd.eionet.europa.eu/vocabulary/art17_2018/habitats/1110 +#> 8 art17_hab_1110.31 1110 FR MATL U1x France http://dd.eionet.europa.eu/vocabulary/art17_2018/habitats/1110 +#> 9 art17_hab_1110.75 1110 UK MATL U1x United Kingdom http://dd.eionet.europa.eu/vocabulary/art17_2018/habitats/1110 +#> 10 art17_hab_1110.1 1110 BE ATL U1x Belgium http://dd.eionet.europa.eu/vocabulary/art17_2018/habitats/1110 +#> habitat_description geometry +#> 1 Sandbanks which are slightly covered by sea water all the time MULTIPOLYGON (((4200000 360... +#> 2 Sandbanks which are slightly covered by sea water all the time MULTIPOLYGON (((1950000 950... +#> 3 Sandbanks which are slightly covered by sea water all the time MULTIPOLYGON (((1960000 950... +#> 4 Sandbanks which are slightly covered by sea water all the time MULTIPOLYGON (((1810000 120... +#> 5 Sandbanks which are slightly covered by sea water all the time MULTIPOLYGON (((2730000 173... +#> 6 Sandbanks which are slightly covered by sea water all the time MULTIPOLYGON (((4610000 346... +#> 7 Sandbanks which are slightly covered by sea water all the time MULTIPOLYGON (((4310000 352... +#> 8 Sandbanks which are slightly covered by sea water all the time MULTIPOLYGON (((3790000 314... +#> 9 Sandbanks which are slightly covered by sea water all the time MULTIPOLYGON (((3780000 319... +#> 10 Sandbanks which are slightly covered by sea water all the time MULTIPOLYGON (((3800000 313... ``` -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). - +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 +``` 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: +#> # 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 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 ``` @@ -133,20 +229,52 @@ emodnet_get_all_wfs_info() ### References -Blondel, Emmanuel. (2020, May 27). ows4R: R Interface to OGC Web-Services (Version 0.1-5). Zenodo. https://doi.org/10.5281/zenodo.3860330 +Blondel, Emmanuel. (2020, May 27). ows4R: R Interface to OGC +Web-Services (Version 0.1-5). Zenodo. + -Flanders Marine Institute (2019). Maritime Boundaries Geodatabase, version 11. Available online at https://www.marineregions.org/. https://doi.org/10.14284/382. +Flanders Marine Institute (2019). Maritime Boundaries Geodatabase, +version 11. Available online at . +. -Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2020). dplyr: A Grammar of Data Manipulation. R package version 1.0.2.https://CRAN.R-project.org/package=dplyr +Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2020). +dplyr: A Grammar of Data Manipulation. R package version +1.0.2.https://CRAN.R-project.org/package=dplyr -Pebesma E (2018). “Simple Features for R: Standardized Support for Spatial Vector Data.” The R Journal, 10(1), 439–446. doi: 10.32614/RJ-2018-009, https://doi.org/10.32614/RJ-2018-009. +Pebesma E (2018). “Simple Features for R: Standardized Support for +Spatial Vector Data.” The R Journal, 10(1), 439–446. doi: +10.32614/RJ-2018-009, . -R Core Team (2020). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL https://www.R-project.org/. +R Core Team (2020). R: A language and environment for statistical +computing. R Foundation for Statistical Computing, Vienna, Austria. URL +. -Tim Appelhans, Florian Detsch, Christoph Reudenbach and Stefan Woellauer (2020). mapview: Interactive Viewing of Spatial Data in R. R package version 2.9.0. https://CRAN.R-project.org/package=mapview +Tim Appelhans, Florian Detsch, Christoph Reudenbach and Stefan Woellauer +(2020). mapview: Interactive Viewing of Spatial Data in R. R package +version 2.9.0. -### Code +### Citation -Please cite this package as: +To cite emodnet.wfs, please use the output from +`citation(package = "emodnet.wfs")`. -Anna Krystalli (2020). emodnet.wfs: Access EMODnet Web Feature Service data through R. R package version 0.0.2. https://github.com/EMODnet/emodnet.wfs. Integrated data products created under the European Marine Observation Data Network (EMODnet) Biology project (EASME/EMFF/2017/1.3.1.2/02/SI2.789013), funded by the by the European Union under Regulation (EU) No 508/2014 of the European Parliament and of the Council of 15 May 2014 on the European Maritime and Fisheries Fund. +``` r +citation(package = "emodnet.wfs") +#> To cite package 'emodnet.wfs' in publications use: +#> +#> Krystalli A, Fernández-Bejarano S, Salmon M (????). _emodnet.wfs: Access EMODnet Web Feature Service data through R_. +#> doi:10.14284/679 , R package version 2.0.2.9000. Integrated data products created under the +#> European Marine Observation Data Network (EMODnet) Biology project (EASME/EMFF/2017/1.3.1.2/02/SI2.789013), funded by the +#> by the European Union under Regulation (EU) No 508/2014 of the European Parliament and of the Council of 15 May 2014 on the +#> European Maritime and Fisheries Fund, . +#> +#> A BibTeX entry for LaTeX users is +#> +#> @Manual{, +#> title = {{emodnet.wfs}: Access EMODnet Web Feature Service data through R}, +#> author = {Anna Krystalli and Salvador Fernández-Bejarano and Maëlle Salmon}, +#> note = {R package version 2.0.2.9000. Integrated data products created under the European Marine Observation Data Network (EMODnet) Biology project (EASME/EMFF/2017/1.3.1.2/02/SI2.789013), funded by the by the European Union under Regulation (EU) No 508/2014 of the European Parliament and of the Council of 15 May 2014 on the European Maritime and Fisheries Fund}, +#> url = {https://github.com/EMODnet/emodnet.wfs}, +#> doi = {10.14284/679}, +#> } +``` diff --git a/vignettes/emodnet.wfs.Rmd.orig b/vignettes/emodnet.wfs.Rmd.orig index 857b1d4..9d7fe63 100644 --- a/vignettes/emodnet.wfs.Rmd.orig +++ b/vignettes/emodnet.wfs.Rmd.orig @@ -1,6 +1,7 @@ --- title: "Accessing and mapping EMODnet data" -output: rmarkdown::html_vignette +output: github_document +df_print: "tibble" vignette: > %\VignetteIndexEntry{API details} %\VignetteEngine{knitr::rmarkdown} @@ -9,10 +10,9 @@ vignette: > ```{r, include = FALSE} knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - echo = TRUE, eval = TRUE, warning = FALSE, - fig.path = "emodnet.wfs-" + collapse = TRUE, + comment = "#>", + cache = FALSE ) ``` @@ -25,39 +25,41 @@ The package was designed to make EMODnet vector data layers easily accessible in You can install the development version of emodnet.wfs from GitHub with: -```{r install, eval = FALSE} + +``` r 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, eval = FALSE} -install.packages(c("sf", "dplyr", "mapview")) -``` +``` r +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. -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 thematic lot can provide with these data. For that, we can check the services available with the `emodnet_wfs()` function. -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 error = FALSE, warning = FALSE, message = FALSE} +```{r, warning=FALSE, message=FALSE} library(emodnet.wfs) library(mapview) -library(dplyr) library(sf) -emodnet_wfs() +services <- emodnet_wfs() +services$service_name ``` 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} seabed_wfs_client <- emodnet_init_wfs_client(service = "seabed_habitats_general_datasets_and_products") @@ -68,6 +70,7 @@ 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} habitats_directive_layer_names <- c("art17_hab_1110", "art17_hab_1140", "art17_hab_1150") @@ -81,39 +84,50 @@ 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} 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) - -glimpse(habitats_directive_layers) +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, eval = TRUE} -# 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) ``` -EMODnet provides also physics, chemistry, biological or bathymetry data. Explore all the layers available with. +![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: -```{r, eval = FALSE} + +```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 @@ -132,8 +146,10 @@ R Core Team (2020). R: A language and environment for statistical computing. R F Tim Appelhans, Florian Detsch, Christoph Reudenbach and Stefan Woellauer (2020). mapview: Interactive Viewing of Spatial Data in R. R package version 2.9.0. https://CRAN.R-project.org/package=mapview -### Code +### Citation -Please cite this package as: +To cite emodnet.wfs, please use the output from `citation(package = "emodnet.wfs")`. -Anna Krystalli (2020). emodnet.wfs: Access EMODnet Web Feature Service data through R. R package version 0.0.2. https://github.com/EMODnet/emodnet.wfs. Integrated data products created under the European Marine Observation Data Network (EMODnet) Biology project (EASME/EMFF/2017/1.3.1.2/02/SI2.789013), funded by the by the European Union under Regulation (EU) No 508/2014 of the European Parliament and of the Council of 15 May 2014 on the European Maritime and Fisheries Fund. +```{r} +citation(package = "emodnet.wfs") +```