| Title: | R Interface to 'IGN' Web Services |
|---|---|
| Description: | Automatic open data acquisition from resources of IGN ('Institut National de Information Geographique et forestiere') (<https://www.ign.fr/>). Available datasets include various types of raster and vector data, such as digital elevation models, state borders, spatial databases, cadastral parcels, and more. 'happign' also provide access to API Carto (<https://apicarto.ign.fr/api/doc/>). |
| Authors: | Paul Carteron [aut, cre] (ORCID: <https://orcid.org/0000-0002-6942-6662>) |
| Maintainer: | Paul Carteron <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.3.8.9000 |
| Built: | 2026-05-26 07:05:18 UTC |
| Source: | https://github.com/paul-carteron/happign |
Check if a wms layer is queryable with GetFeatureInfo.
are_queryable(apikey)are_queryable(apikey)
apikey |
API key from |
character containing the name of the queryable layers
build query for isochrone-dist API
build_iso_query( point, source, value, type, profile, direction, constraints, distance_unit, time_unit )build_iso_query( point, source, value, type, profile, direction, constraints, distance_unit, time_unit )
point |
|
source |
|
value |
|
type |
|
profile |
|
direction |
|
constraints |
Used to express constraints on the characteristics
to calculate isochrones/isodistances. See section |
distance_unit |
|
time_unit |
|
httr2_request object
Data for French communes from the INSEE file "v_commune_2025.csv".
com_2025com_2025
A data frame with one row per commune and the following columns:
(chr) Type of commune (4 characters)
(chr) Commune code (5 characters)
(int) Region code (2 characters)
(chr) Department code (3 characters)
(chr) Code of the territorial collectivity with departmental powers (4 characters)
(chr) District (arrondissement) code (4 characters)
(int) Name type indicator (1 character)
(chr) Official name in uppercase (200 characters)
(chr) Official name with proper typography (200 characters)
(chr) Official name with article and proper typography (200 characters)
(chr) Canton code (5 characters). For “multi-canton” communes, code ranges from 99 to 90 (pseudo-canton) or 89 to 80 (new communes)
(int) Parent commune code for municipal districts and associated or delegated communes (5 characters)
https://www.insee.fr/fr/statistiques/fichier/8377162/cog_ensemble_2025_csv.zip
Data for French departments from the INSEE file "Départements".
dep_2025dep_2025
A data frame with one row per department and the following columns:
(chr) Department code (3 characters)
(int) Region code (2 characters)
(chr) Commune code of the departmental capital (5 characters)
(int) Name type indicator (1 character)
(chr) Official name in uppercase (200 characters)
(chr) Official name with proper typography (200 characters)
(chr) Official name with article and proper typography (200 characters)
https://www.insee.fr/fr/statistiques/fichier/8377162/cog_ensemble_2025_csv.zip
Implementation of the cadastre module from the IGN's apicarto
get_apicarto_cadastre(x, type = "commune", section = NULL, numero = NULL, code_abs = NULL, source = "pci", progress = TRUE)get_apicarto_cadastre(x, type = "commune", section = NULL, numero = NULL, code_abs = NULL, source = "pci", progress = TRUE)
x |
|
type |
|
section |
|
numero |
|
code_abs |
|
source |
|
progress |
Display a progress bar? Use TRUE to turn on a basic progress
bar, use a string to give it a name. See |
Vectorisation:
Arguments x, section, numero, and code_abs are vectorized
if only one argument has length > 1 (Cartesian product)
x = 29158; section = c("A", "B")
→ (29158, "A"), (29158, "B")
x = 29158, section = "A", numero = 1:3
→ (29158, "A", 1); (29158, "A", 2); (29158, "A", 3)
In case all vectorised arguments have the same length Pairwise matching is used
x = c(29158, 29158); section = c("A", "B"); numero = 1:2
→ (29158, "A", 1), (29158, "B", 2)
Ambiguous vectorisation:
If more than one argument has length > 1 but lengths differ, it is unclear
whether to combine them pairwise or via cartesian product. This is rejected
with an error to avoid unintended queries.
x = 29158, section = c("A", "B"), numero = 1:2
Possible interpretations:
1. Pairwise: (29158, "A", 1), (29158, "B", 2)
2. Cartesian: (29158, "A", 1), (29158, "A", 2), (29158, "B", 1), (29158, "B", 2)
Source:
BD Parcellaire ("bdp") is no longer updated and its use is discouraged.
PCI Express ("pci") is strongly recommended and will become mandatory.
See IGN's product comparison table.
Object of class sf
## Not run: library(sf) library(tmap) # shape from the town of penmarch penmarch <- read_sf(system.file("extdata/penmarch.shp", package = "happign")) # get commune borders ## from shape penmarch_borders <- get_apicarto_cadastre(penmarch, type = "commune") qtm(penmarch_borders)+qtm(penmarch, fill = "red") ## from insee_code border <- get_apicarto_cadastre("29158", type = "commune") borders <- get_apicarto_cadastre(c("29158", "29135"), type = "commune") qtm(borders, fill="nom_com") # get cadastral parcels ## from shape parcels <- get_apicarto_cadastre(penmarch, type = "parcelle") qtm(parcels, fill="section") ## from insee code parcels <- get_apicarto_cadastre("29158", type = "parcelle") qtm(parcels, fill="section") # Use parameter recycling ## get sections "AW" parcels from multiple insee_code parcels <- get_apicarto_cadastre( c("29158", "29135"), section = "AW", type = "parcelle" ) qtm(borders, fill = NA)+qtm(parcels) ## if multiple args with length > 1 result is ambigous parcels <- get_apicarto_cadastre( x = c("29158", "29135"), section = c("AW", "AB"), numero = 1, type = "parcelle" ) ## get parcels numbered "0001", "0010" of section "AW" and "BR" insee <- rep("29158", 2) section <- c("AW", "BR") numero <- c("0001", "0010") parcels <- get_apicarto_cadastre(insee, section = section, numero = numero, type = "parcelle") qtm(penmarch_borders, fill = NA)+qtm(parcels) # Arrondissement insee code should be used for paris, lyon, marseille error <- get_apicarto_cadastre(c(75056, 69123, 13055)) paris_arr123 <- get_apicarto_cadastre(c(75101, 75102, 75103)) qtm(paris_arr123, fill = "code_insee") ## End(Not run)## Not run: library(sf) library(tmap) # shape from the town of penmarch penmarch <- read_sf(system.file("extdata/penmarch.shp", package = "happign")) # get commune borders ## from shape penmarch_borders <- get_apicarto_cadastre(penmarch, type = "commune") qtm(penmarch_borders)+qtm(penmarch, fill = "red") ## from insee_code border <- get_apicarto_cadastre("29158", type = "commune") borders <- get_apicarto_cadastre(c("29158", "29135"), type = "commune") qtm(borders, fill="nom_com") # get cadastral parcels ## from shape parcels <- get_apicarto_cadastre(penmarch, type = "parcelle") qtm(parcels, fill="section") ## from insee code parcels <- get_apicarto_cadastre("29158", type = "parcelle") qtm(parcels, fill="section") # Use parameter recycling ## get sections "AW" parcels from multiple insee_code parcels <- get_apicarto_cadastre( c("29158", "29135"), section = "AW", type = "parcelle" ) qtm(borders, fill = NA)+qtm(parcels) ## if multiple args with length > 1 result is ambigous parcels <- get_apicarto_cadastre( x = c("29158", "29135"), section = c("AW", "AB"), numero = 1, type = "parcelle" ) ## get parcels numbered "0001", "0010" of section "AW" and "BR" insee <- rep("29158", 2) section <- c("AW", "BR") numero <- c("0001", "0010") parcels <- get_apicarto_cadastre(insee, section = section, numero = numero, type = "parcelle") qtm(penmarch_borders, fill = NA)+qtm(parcels) # Arrondissement insee code should be used for paris, lyon, marseille error <- get_apicarto_cadastre(c(75056, 69123, 13055)) paris_arr123 <- get_apicarto_cadastre(c(75101, 75102, 75103)) qtm(paris_arr123, fill = "code_insee") ## End(Not run)
Implementation of the "Codes Postaux" module from the IGN's apicarto. This API give information about commune from postal code.
get_apicarto_codes_postaux(code_post)get_apicarto_codes_postaux(code_post)
code_post |
|
Object of class data.frame
## Not run: info_commune <- get_apicarto_codes_postaux("29760") code_post <- c("29760", "08170") info_communes <- get_apicarto_codes_postaux(code_post) code_post <- c("12345") info_communes <- get_apicarto_codes_postaux(code_post) code_post <- c("12345", "08170") info_communes <- get_apicarto_codes_postaux(code_post) ## End(Not run)## Not run: info_commune <- get_apicarto_codes_postaux("29760") code_post <- c("29760", "08170") info_communes <- get_apicarto_codes_postaux(code_post) code_post <- c("12345") info_communes <- get_apicarto_codes_postaux(code_post) code_post <- c("12345", "08170") info_communes <- get_apicarto_codes_postaux(code_post) ## End(Not run)
Apicarto module Geoportail de l'urbanisme
get_apicarto_gpu(x, layer, category = NULL)get_apicarto_gpu(x, layer, category = NULL)
x |
|
layer |
|
category |
public utility easement according to the national nomenclature |
/!\ API cannot returned more than 5000 features.
All existing parameters for layer :
"municipality" : information on the communes (commune with RNU, merged commune)
"document" : information on urban planning documents (POS, PLU, PLUi, CC, PSMV, SCoT)
"zone-urba" : zoning of urban planning documents,
"secteur-cc" : communal map sectors
"prescription-surf", "prescription-lin", "prescription-pct" : its's
a constraint or a possibility indicated in an urban planning document (PLU, PLUi, ...)
"info-surf", "info-lin", "info-pct" : its's an information indicated
in an urban planning document (PLU, PLUi, ...)
"acte-sup" : act establishing the SUP
"generateur-sup-s", "generateur-sup-l", "generateur-sup-p" : an
entity (site or monument, watercourse, water catchment, electricity or gas
distribution of electricity or gas, etc.) which generates on the surrounding
SUP (of passage, alignment, protection, land reservation, etc.)
"assiette-sup-s", "assiette-sup-l", "assiette-sup-p" : spatial area
to which SUP it applies.
sf
## Not run: library(sf) library(tmap) # Find if commune is under the RNU (national urbanism regulation) # If no RNU it means communes probably have a PLU rnu <- get_apicarto_gpu("29158", "municipality") rnu$is_rnu # Get urbanism document # Rq : when using geometry, multiple documents can be returned due to intersection x <- get_apicarto_cadastre("29158", "commune") document <- get_apicarto_gpu(x, "document") document$partition penmarch <- document$partition[2] # get gpu features ## from shape gpu <- get_apicarto_gpu(x, "zone-urba") qtm(gpu, fill="typezone") ## from partition gpu <- get_apicarto_gpu(penmarch, "zone-urba") qtm(gpu, fill="typezone") # example : all prescription layers <- names(get_gpu_layers("prescription")) prescriptions <- lapply(layers, \(x) get_apicarto_gpu(penmarch, x)) |> setNames(layers) qtm(prescriptions$`prescription-pct`, fill = "libelle")+ qtm(prescriptions$`prescription-lin`, col = "libelle")+ qtm(prescriptions$`prescription-surf`, fill = "libelle") # When using SUP, category can be used for filtering # AC1 : Monuments historiques penmarch <- get_apicarto_cadastre(29158) mh <- get_apicarto_gpu(penmarch, "assiette-sup-s", category = "AC1") # example : public utility servitude (SUP) generateur ## /!\ a generator can justify several assiette gen_mh <- get_apicarto_gpu(penmarch, "generateur-sup-s", "AC1") qtm(mh, fill = "lightblue")+qtm(gen_mh, fill = "red") ## End(Not run)## Not run: library(sf) library(tmap) # Find if commune is under the RNU (national urbanism regulation) # If no RNU it means communes probably have a PLU rnu <- get_apicarto_gpu("29158", "municipality") rnu$is_rnu # Get urbanism document # Rq : when using geometry, multiple documents can be returned due to intersection x <- get_apicarto_cadastre("29158", "commune") document <- get_apicarto_gpu(x, "document") document$partition penmarch <- document$partition[2] # get gpu features ## from shape gpu <- get_apicarto_gpu(x, "zone-urba") qtm(gpu, fill="typezone") ## from partition gpu <- get_apicarto_gpu(penmarch, "zone-urba") qtm(gpu, fill="typezone") # example : all prescription layers <- names(get_gpu_layers("prescription")) prescriptions <- lapply(layers, \(x) get_apicarto_gpu(penmarch, x)) |> setNames(layers) qtm(prescriptions$`prescription-pct`, fill = "libelle")+ qtm(prescriptions$`prescription-lin`, col = "libelle")+ qtm(prescriptions$`prescription-surf`, fill = "libelle") # When using SUP, category can be used for filtering # AC1 : Monuments historiques penmarch <- get_apicarto_cadastre(29158) mh <- get_apicarto_gpu(penmarch, "assiette-sup-s", category = "AC1") # example : public utility servitude (SUP) generateur ## /!\ a generator can justify several assiette gen_mh <- get_apicarto_gpu(penmarch, "generateur-sup-s", "AC1") qtm(mh, fill = "lightblue")+qtm(gen_mh, fill = "red") ## End(Not run)
All API keys are manually extract from this table provided by IGN.
get_apikeys()get_apikeys()
character
## Not run: # One API key get_apikeys()[1] # All API keys get_apikeys() ## End(Not run)## Not run: # One API key get_apikeys()[1] # All API keys get_apikeys() ## End(Not run)
Helpers that return available GPU layers and their type.
get_gpu_layers(type = NULL)get_gpu_layers(type = NULL)
type |
|
"du": "Document d'urbanisme"
"sup": "Servitude d'utilité publique"
list
# All layers names(get_gpu_layers()) # All sup layers names(get_gpu_layers("generateur")) # All sup and du layers names(get_gpu_layers(c("generateur", "prescription")))# All layers names(get_gpu_layers()) # All sup layers names(get_gpu_layers("generateur")) # All sup and du layers names(get_gpu_layers(c("generateur", "prescription")))
Calculates isochrones or isodistances in France from an sf object using the IGN API on the Géoportail platform. The reference data comes from the IGN BD TOPO® database. For further information see IGN documentation.
get_iso(x, value, type = "time", profile = "pedestrian", time_unit = "minute", distance_unit = "meter", direction = "departure", source = "pgr", constraints = NULL) get_isodistance(x, dist, unit = "meter", source = "pgr", profile = "car", direction = "departure", constraints = NULL) get_isochrone(x, time, unit = "minute", source = "pgr", profile = "car", direction = "departure", constraints = NULL)get_iso(x, value, type = "time", profile = "pedestrian", time_unit = "minute", distance_unit = "meter", direction = "departure", source = "pgr", constraints = NULL) get_isodistance(x, dist, unit = "meter", source = "pgr", profile = "car", direction = "departure", constraints = NULL) get_isochrone(x, time, unit = "minute", source = "pgr", profile = "car", direction = "departure", constraints = NULL)
x |
Object of class |
value |
|
type |
|
profile |
|
time_unit |
|
distance_unit |
|
direction |
|
source |
|
constraints |
Used to express constraints on the characteristics
to calculate isochrones/isodistances. See section |
dist |
|
unit |
see |
time |
|
object of class sf with POLYGON geometry
get_isodistance(): Wrapper function to calculate isodistance from get_iso.
get_isochrone(): Wrapper function to calculate isochrone from get_iso.
Isochrones are calculated using the same resources as for route calculation. PGR" and "VALHALLA" resources are used, namely "bdtopo-valhalla" and "bdtopo-pgr".
bdtopo-valhalla" : To-Do
bdtopo-iso" is based on the old services over a certain distance, to solve performance problems. We recommend its use for large isochrones.
PGR resources are resources that use the PGRouting engine to calculate isochrones. ISO resources are more generic. The engine used for calculations varies according to several parameters. At present, the parameter concerned is cost_value, i.e. the requested time or distance.
get_isodistance, get_isochrone
## Not run: library(sf) library(tmap) # All area i can acces in less than 5 minute from penmarch centroid penmarch <- get_apicarto_cadastre("29158") penmarch_centroid <- st_centroid(penmarch) isochrone <- get_isochrone(penmarch_centroid, 5) qtm(penmarch, col = "red")+qtm(isochrone, col = "blue")+qtm(penmarch_centroid, fill = "red") # All area i can acces as pedestrian in less than 1km isodistance <- get_isodistance(penmarch_centroid, 1, unit = "kilometer", profile = "pedestrian") qtm(penmarch, col = "red")+qtm(isodistance, col = "blue")+qtm(penmarch_centroid, fill = "red") # In case of multiple point provided, the output will contain as many polygons as points. code_insee <- c("29158", "29072", "29171") communes_centroid <- get_apicarto_cadastre(code_insee) |> st_centroid() isochrones <- get_isochrone(communes_centroid, 8) isochrones$code_insee <- code_insee qtm(isochrones, fill = "code_insee") # Find area where i can acces all communes centroid in less than 8 minutes area <- st_intersection(isochrones) qtm(communes_centroid, fill = "red")+ qtm(area[area$origins == "1:3",]) ## End(Not run)## Not run: library(sf) library(tmap) # All area i can acces in less than 5 minute from penmarch centroid penmarch <- get_apicarto_cadastre("29158") penmarch_centroid <- st_centroid(penmarch) isochrone <- get_isochrone(penmarch_centroid, 5) qtm(penmarch, col = "red")+qtm(isochrone, col = "blue")+qtm(penmarch_centroid, fill = "red") # All area i can acces as pedestrian in less than 1km isodistance <- get_isodistance(penmarch_centroid, 1, unit = "kilometer", profile = "pedestrian") qtm(penmarch, col = "red")+qtm(isodistance, col = "blue")+qtm(penmarch_centroid, fill = "red") # In case of multiple point provided, the output will contain as many polygons as points. code_insee <- c("29158", "29072", "29171") communes_centroid <- get_apicarto_cadastre(code_insee) |> st_centroid() isochrones <- get_isochrone(communes_centroid, 8) isochrones$code_insee <- code_insee qtm(isochrones, fill = "code_insee") # Find area where i can acces all communes centroid in less than 8 minutes area <- st_intersection(isochrones) qtm(communes_centroid, fill = "red")+ qtm(area[area$origins == "1:3",]) ## End(Not run)
This function is a wrapper around the RSS feed of the geoservice site to get the latest information.
get_last_news()get_last_news()
message or error
## Not run: get_last_news() ## End(Not run)## Not run: get_last_news() ## End(Not run)
Metadata are retrieved using the IGN APIs. The execution time can be long depending on the size of the metadata associated with the API key and the overload of the IGN servers.
get_layers_metadata(data_type, apikey = NULL)get_layers_metadata(data_type, apikey = NULL)
data_type |
Should be |
apikey |
API key from |
"wfs" : Web Feature Service designed to return data in vector format (line,
point, polygon, ...) ;
"wms-r" : Web Map Service focuses on raster data ;
"wmts" : Web Map Tile Service is similar to WMS, but instead of serving maps
as single images, WMTS serves maps by dividing the map into a pyramid of tiles at
multiple scales.
data.frame
## Not run: # Get all metadata for a datatype metadata_table <- get_layers_metadata("wms-r") # Get all "administratif" wms layers apikey <- get_apikeys()[1] #administratif admin_layers <- get_layers_metadata("wms-r", apikey) ## End(Not run)## Not run: # Get all metadata for a datatype metadata_table <- get_layers_metadata("wms-r") # Get all "administratif" wms layers apikey <- get_apikeys()[1] #administratif admin_layers <- get_layers_metadata("wms-r", apikey) ## End(Not run)
For some wms layer more information can be found with GetFeatureInfo request. This function first check if info are available. If not, available layers are returned.
get_location_info(x, apikey = "ortho", layer = "ORTHOIMAGERY.ORTHOPHOTOS", read_sf = TRUE, version = "1.3.0")get_location_info(x, apikey = "ortho", layer = "ORTHOIMAGERY.ORTHOPHOTOS", read_sf = TRUE, version = "1.3.0")
x |
Object of class |
apikey |
|
layer |
|
read_sf |
|
version |
|
character or sf containing additional information about the layer
## Not run: library(sf) library(tmap) # From single point x <- st_centroid(read_sf(system.file("extdata/penmarch.shp", package = "happign"))) location_info <- get_location_info(x, "ortho", "ORTHOIMAGERY.ORTHOPHOTOS", read_sf = F) location_info$date_vol # From multiple point x1 <- st_sfc(st_point(c(-3.549957, 47.83396)), crs = 4326) # Carnoet forest x2 <- st_sfc(st_point(c(-3.745995, 47.99296)), crs = 4326) # Coatloch forest forests <- lapply(list(x1, x2), get_location_info, apikey = "environnement", layer = "FORETS.PUBLIQUES", read_sf = T) qtm(forests[[1]]) + qtm(forests[[2]]) # Find all queryable layers queryable_layers <- lapply(get_apikeys(), are_queryable) |> unlist() ## End(Not run)## Not run: library(sf) library(tmap) # From single point x <- st_centroid(read_sf(system.file("extdata/penmarch.shp", package = "happign"))) location_info <- get_location_info(x, "ortho", "ORTHOIMAGERY.ORTHOPHOTOS", read_sf = F) location_info$date_vol # From multiple point x1 <- st_sfc(st_point(c(-3.549957, 47.83396)), crs = 4326) # Carnoet forest x2 <- st_sfc(st_point(c(-3.745995, 47.99296)), crs = 4326) # Coatloch forest forests <- lapply(list(x1, x2), get_location_info, apikey = "environnement", layer = "FORETS.PUBLIQUES", read_sf = T) qtm(forests[[1]]) + qtm(forests[[2]]) # Find all queryable layers queryable_layers <- lapply(get_apikeys(), are_queryable) |> unlist() ## End(Not run)
Download features from the IGN Web Feature Service (WFS) using a spatial predicate, an ECQL attribute query, or both.
get_wfs( x = NULL, layer = NULL, predicate = bbox(), query = NULL, verbose = TRUE )get_wfs( x = NULL, layer = NULL, predicate = bbox(), query = NULL, verbose = TRUE )
x |
|
layer |
|
predicate |
|
query |
|
verbose |
|
get_wfs use ECQL language : a query language created by the
OpenGeospatial Consortium. More info about ECQL language can be
found here.
An object of class sf.
## Not run: library(sf) # Load a geometry x <- read_sf(system.file("extdata/penmarch.shp", package = "happign")) # Retrieve commune boundaries intersecting x commune <- get_wfs( x = x, layer = "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune" ) plot(st_geometry(commune), border = "firebrick") # Attribute-only query (no spatial filter) # If unknown, available attributes can be retrieved using `get_wfs_attributes()` attrs <- get_wfs_attributes("LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune") print(attrs) plou_communes <- get_wfs( x = NULL, layer = "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune", query = "nom_officiel ILIKE 'PLOU%'" ) plot(st_geometry(plou_communes)) # Multiple Attribute-only query (no spatial filter) plou_inf_2000 <- get_wfs( x = NULL, layer = "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune", query = "nom_officiel ILIKE 'PLOU%' AND population < 2000" ) plot(st_geometry(plou_communes)) plot(st_geometry(plou_inf_2000), col = "firebrick", add = TRUE) # Spatial predicate usage layer <- "BDCARTO_V5:rond_point" bbox_feat <- get_wfs(commune, layer, predicate = bbox()) plot(st_geometry(bbox_feat), col = "red") plot(st_geometry(commune), add = TRUE) intersects_feat <- get_wfs(commune, layer, predicate = intersects()) plot(st_geometry(intersects_feat), col = "red") plot(st_geometry(commune), add = TRUE) dwithin_feat <- get_wfs(commune, layer, predicate = dwithin(5, "kilometers")) plot(st_geometry(dwithin_feat), col = "red") plot(st_geometry(commune), add = TRUE) ## End(Not run)## Not run: library(sf) # Load a geometry x <- read_sf(system.file("extdata/penmarch.shp", package = "happign")) # Retrieve commune boundaries intersecting x commune <- get_wfs( x = x, layer = "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune" ) plot(st_geometry(commune), border = "firebrick") # Attribute-only query (no spatial filter) # If unknown, available attributes can be retrieved using `get_wfs_attributes()` attrs <- get_wfs_attributes("LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune") print(attrs) plou_communes <- get_wfs( x = NULL, layer = "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune", query = "nom_officiel ILIKE 'PLOU%'" ) plot(st_geometry(plou_communes)) # Multiple Attribute-only query (no spatial filter) plou_inf_2000 <- get_wfs( x = NULL, layer = "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune", query = "nom_officiel ILIKE 'PLOU%' AND population < 2000" ) plot(st_geometry(plou_communes)) plot(st_geometry(plou_inf_2000), col = "firebrick", add = TRUE) # Spatial predicate usage layer <- "BDCARTO_V5:rond_point" bbox_feat <- get_wfs(commune, layer, predicate = bbox()) plot(st_geometry(bbox_feat), col = "red") plot(st_geometry(commune), add = TRUE) intersects_feat <- get_wfs(commune, layer, predicate = intersects()) plot(st_geometry(intersects_feat), col = "red") plot(st_geometry(commune), add = TRUE) dwithin_feat <- get_wfs(commune, layer, predicate = dwithin(5, "kilometers")) plot(st_geometry(dwithin_feat), col = "red") plot(st_geometry(commune), add = TRUE) ## End(Not run)
Helper to write ecql filter. Retrieve all attributes from a layer.
get_wfs_attributes(layer = NULL)get_wfs_attributes(layer = NULL)
layer |
|
charactervector with layer attributes
## Not run: get_wfs_attributes("LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune") ## End(Not run)## Not run: get_wfs_attributes("LIMITES_ADMINISTRATIVES_EXPRESS.LATEST:commune") ## End(Not run)
Download a raster layer from the IGN Web Mapping Services (WMS). Specify a location using a shape and provide the layer name.
get_wms_raster(x, layer = "ORTHOIMAGERY.ORTHOPHOTOS", res = 10, crs = 2154, rgb = TRUE, filename = NULL, overwrite = FALSE, verbose = TRUE)get_wms_raster(x, layer = "ORTHOIMAGERY.ORTHOPHOTOS", res = 10, crs = 2154, rgb = TRUE, filename = NULL, overwrite = FALSE, verbose = TRUE)
x |
Object of class |
layer |
|
res |
|
crs |
|
rgb |
|
filename |
|
overwrite |
|
verbose |
|
res: Note that setting res higher than the default resolution
of the layer will increase the number of pixels but not the precision
of the image. For instance, downloading the BD Alti layer from IGN
is optimal at a resolution of 25m.
rgb: Rasters are commonly used to download images such as orthophotos.
In specific cases like DEMs, however, a value per pixel is essential. See
examples below.
SpatRaster object from terra package.
## Not run: library(sf) library(tmap) # Shape from the best town in France penmarch <- read_sf(system.file("extdata/penmarch.shp", package = "happign")) # For specific data, choose apikey with get_apikey() and layer with get_layers_metadata() apikey <- get_apikeys()[4] # altimetrie metadata_table <- get_layers_metadata("wms-r", apikey) # all layers for altimetrie wms layer <- metadata_table[2,1] # ELEVATION.ELEVATIONGRIDCOVERAGE # Downloading digital elevation model values not image mnt_2154 <- get_wms_raster(penmarch, layer, res = 1, crs = 2154, rgb = FALSE) # If crs is set to 4326, res is in degrees mnt_4326 <- get_wms_raster(penmarch, layer, res = 0.0001, crs = 4326, rgb = FALSE) # Plotting result tm_shape(mnt_4326)+ tm_raster()+ tm_shape(penmarch)+ tm_borders(col = "blue", lwd = 3) ## End(Not run)## Not run: library(sf) library(tmap) # Shape from the best town in France penmarch <- read_sf(system.file("extdata/penmarch.shp", package = "happign")) # For specific data, choose apikey with get_apikey() and layer with get_layers_metadata() apikey <- get_apikeys()[4] # altimetrie metadata_table <- get_layers_metadata("wms-r", apikey) # all layers for altimetrie wms layer <- metadata_table[2,1] # ELEVATION.ELEVATIONGRIDCOVERAGE # Downloading digital elevation model values not image mnt_2154 <- get_wms_raster(penmarch, layer, res = 1, crs = 2154, rgb = FALSE) # If crs is set to 4326, res is in degrees mnt_4326 <- get_wms_raster(penmarch, layer, res = 0.0001, crs = 4326, rgb = FALSE) # Plotting result tm_shape(mnt_4326)+ tm_raster()+ tm_shape(penmarch)+ tm_borders(col = "blue", lwd = 3) ## End(Not run)
Download an RGB raster layer from IGN Web Map Tile Services (WMTS). WMTS focuses on performance and can only query pre-calculated tiles.
get_wmts(x, layer = "ORTHOIMAGERY.ORTHOPHOTOS", zoom = 10L, crs = 2154, filename = tempfile(fileext = ".tif"), verbose = FALSE, overwrite = FALSE, interactive = FALSE)get_wmts(x, layer = "ORTHOIMAGERY.ORTHOPHOTOS", zoom = 10L, crs = 2154, filename = tempfile(fileext = ".tif"), verbose = FALSE, overwrite = FALSE, interactive = FALSE)
x |
Object of class |
layer |
|
zoom |
|
crs |
|
filename |
|
verbose |
|
overwrite |
If TRUE, output raster is overwrite. |
interactive |
|
SpatRaster object from terra package.
get_apikeys(), get_layers_metadata()
## Not run: library(sf) library(tmap) penmarch <- read_sf(system.file("extdata/penmarch.shp", package = "happign")) # Get orthophoto layers <- get_layers_metadata("wmts", "ortho")$Identifier ortho <- get_wmts(penmarch, layer = layers[1], zoom = 21) plotRGB(ortho) # Get all available irc images layers <- get_layers_metadata("wmts", "orthohisto")$Identifier irc_names <- grep("irc", layers, value = TRUE, ignore.case = TRUE) irc <- lapply(irc_names, function(x) get_wmts(penmarch, layer = x, zoom = 18)) |> setNames(irc_names) # remove empty layer (e.g. only NA) irc <- Filter(function(x) !all(is.na(values(x))), irc) # plot all_plots <- lapply(irc, plotRGB) ## End(Not run)## Not run: library(sf) library(tmap) penmarch <- read_sf(system.file("extdata/penmarch.shp", package = "happign")) # Get orthophoto layers <- get_layers_metadata("wmts", "ortho")$Identifier ortho <- get_wmts(penmarch, layer = layers[1], zoom = 21) plotRGB(ortho) # Get all available irc images layers <- get_layers_metadata("wmts", "orthohisto")$Identifier irc_names <- grep("irc", layers, value = TRUE, ignore.case = TRUE) irc <- lapply(irc_names, function(x) get_wmts(penmarch, layer = x, zoom = 18)) |> setNames(irc_names) # remove empty layer (e.g. only NA) irc <- Filter(function(x) !all(is.na(values(x))), irc) # plot all_plots <- lapply(irc, plotRGB) ## End(Not run)
Data for French regions from the INSEE file "Régions".
reg_2025reg_2025
A data frame with one row per region and the following columns:
(int) Region code (2 characters)
(chr) Commune code of the regional capital (5 characters)
(int) Name type indicator (1 character)
(chr) Official name in uppercase (200 characters)
(chr) Official name with proper typography (200 characters)
(chr) Official name with article and proper typography (200 characters)
https://www.insee.fr/fr/statistiques/fichier/8377162/cog_ensemble_2025_csv.zip
These functions create spatial predicates used by get_wfs() to filter
features based on their spatial relationship with a reference geometry.
intersects() within() disjoint() contains() touches() crosses() overlaps() equals() bbox() dwithin(distance, units = "meters") beyond(distance, units = "meters") relate(pattern)intersects() within() disjoint() contains() touches() crosses() overlaps() equals() bbox() dwithin(distance, units = "meters") beyond(distance, units = "meters") relate(pattern)
distance |
Numeric distance value (single value). |
units |
Distance units supported by the WFS server (e.g. |
pattern |
A 9-character DE-9IM pattern string. |
Predicates describe how geometries should be compared (e.g. intersection, containment, distance-based relations). Users should not construct predicates manually; instead, use the helper functions listed below.
bbox(): Select features intersecting the bounding box of the reference geometry.
intersects(): Select features whose geometry intersects the reference geometry.
disjoint(): Select features whose geometry intersects the reference geometry.
contains(): Select features that completely contain the reference geometry.
within(): Select features completely within the reference geometry.
touches(): Select features that touch the reference geometry at the boundary.
crosses(): Select features that cross the reference geometry.
overlaps(): Select features that partially overlap the reference geometry.
equals(): Select features geometrically equal to the reference geometry.
dwithin(distance, units): Select features within a given distance of the reference geometry.
beyond(distance, units): Select features farther than a given distance from the reference geometry.
relate(pattern): Select features matching a DE-9IM spatial relationship pattern.
A spatial predicate object (used internally by get_wfs()).
intersects() bbox() dwithin(50, "meters") beyond(100, "meters") relate("T*F**F***")intersects() bbox() dwithin(50, "meters") beyond(100, "meters") relate("T*F**F***")