--- title: "Getting started" author: "Paul Carteron" date: "2025-07-23" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Getting started} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- # Before starting We can load the `happign` package, and some additional packages we will need (`sf` to manipulate spatial data and `tmap` to create maps) ``` r knitr::opts_chunk$set(warning = FALSE, message = FALSE) library(happign) library(sf) library(tmap) ``` # WFS, WMS and WMTS service `happign` use three web service from IGN : * WMS raster : data in raster format e.g. images (.jpg, .png, .tif, ...) * WMTS : same as WMS raster but images are precalculated * WFS : data in vector format (.shp, ...). More detailed information are available [here](https://www.ogc.org/standards/wms/) for WMS, [here](https://www.ogc.org/standards/wmts/) for WMTS and [here](https://www.ogc.org/standards/wfs/) for WFS. To download data from IGN web services at least two elements are needed : * A layer name ; * An input shape read by [`sf`]( https://CRAN.R-project.org/package=sf) package. ## Layer name It is possible to find the names of available layers from the IGN website. For example, the first layer name in **WFS format** for ["Administratif" category](https://geoservices.ign.fr/services-web-experts-administratif) is *"ADMINEXPRESS-COG-CARTO.LATEST:arrondissement"* All layer's name can be accessed from R with the `get_layers_metadata()` function. This one connects directly to the IGN site which allows to have the last updated resources. It can be used for WMS and WFS : ``` r administratif_wfs <- get_layers_metadata(data_type = "wfs") administratif_wms <- get_layers_metadata(data_type = "wms-r") administratif_wms <- get_layers_metadata(data_type = "wmts") head(administratif_wfs) ``` ``` ## Name ## 1 OCS-GERS_BDD_LAMB93_2016:oscge_gers_32_2016 ## 2 OCS-GERS_BDD_LAMB93_2019:oscge_gers_32_2019 ## 3 IGNF_GEODESIE:site-rbf ## 4 IGNF_GEODESIE:site-rdf ## 5 LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:arrondissement ## 6 LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:arrondissement_municipal ## Title ## 1 OCSGE Gers 2016 ## 2 OCSGE Gers 2019 ## 3 (obsolete) Site RBF ## 4 (obsolete) Site RDF ## 5 ADMIN EXPRESS mises a jour en continu - arrondissement ## 6 ADMIN EXPRESS mises a jour en continu - arrondissement municipal ## Abstract ## 1 OCSGE Gers 2016 ## 2 OCSGE Gers 2019 ## 3 RBF ## 4 RDF ## 5 ADMIN EXPRESS mises a jour en continu - arrondissement ## 6 ADMIN EXPRESS mises a jour en continu - arrondissement municipal ``` You can specify an apikey to focus on specific category. API keys can be directly retrieved on the [IGN website from the expert web services](https://geoservices.ign.fr/services-web-experts) or with `get_apikeys()` function. ``` r get_apikeys() ``` ``` ## [1] "administratif" "adresse" "agriculture" ## [4] "altimetrie" "cartes" "cartovecto" ## [7] "clc" "economie" "enr" ## [10] "environnement" "geodesie" "lambert93" ## [13] "ocsge" "ortho" "orthohisto" ## [16] "parcellaire" "satellite" "sol" ## [19] "topographie" "transports" ``` ``` r administratif_wmts <- get_layers_metadata("wmts", "administratif") head(administratif_wmts) ``` ``` ## Title ## 1 ADMINEXPRESS COG CARTO ## 2 ADMINEXPRESS COG ; Edition : 2017-01-01 ## 3 ADMINEXPRESS COG ; Edition : 2018-01-01 ## 4 ADMINEXPRESS COG ; Edition : 2019-01-01 ## 5 ADMINEXPRESS COG ; Edition : 2020-01-01 ## 6 ADMINEXPRESS COG ; Edition : 2021-01-01 ## Abstract ## 1 Limites administratives mises à jour en continu ; Edition : 2025-01-01 ## 2 Limites administratives Express COG code officiel géographique ; Edition : 2017-01-01 ## 3 Limites administratives Express COG code officiel géographique ; Edition : 2018-01-01 ## 4 Limites administratives Express COG code officiel géographique ; Edition : 2019-01-01 ## 5 Limites administratives Express COG code officiel géographique ; Edition : 2020-01-01 ## 6 Limites administratives Express COG code officiel géographique ; Edition : 2021-01-01 ## Identifier ## 1 ADMINEXPRESS-COG-CARTO.LATEST ## 2 ADMINEXPRESS-COG.2017 ## 3 ADMINEXPRESS-COG.2018 ## 4 ADMINEXPRESS-COG.2019 ## 5 ADMINEXPRESS-COG.2020 ## 6 ADMINEXPRESS-COG.2021 ``` ## Downloading the data Now that we know how to get a layer name, it only takes a few lines to get plethora of resources. For the example we will look at the beautiful town of Penmarch in France. A part of this town is stored as a shape in happign. ``` r penmarch <- read_sf(system.file("extdata/penmarch.shp", package = "happign")) ``` ### WFS `get_wfs` can be used to download borders : ``` r penmarch_borders <- get_wfs(x = penmarch, layer = "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune") ``` ``` ## Error: Please check that : ## - x is not empty ; ## - layer is valid by running ``` ``` r # Checking result tm_shape(penmarch_borders) + tm_polygons() + tm_add_legend(type = "polygons", position = c("right", "top"), labels = "Penmarch borders from `get_wfs`")+ tm_shape(penmarch) + tm_polygons(fill="red") + tm_add_legend(type = "polygons", fill="red", position = c("right", "top"), labels = "`penmarch` shape from `happign` package")+ tm_title("Penmarch borders from IGN", position = tm_pos_out("center", "top", pos.h = "center"))+ tm_compass(type = "arrow")+ tm_scalebar() ```