| Title: | R Interface to Get French Heritage Data |
| Version: | 0.1.0 |
| Description: | Get spatial vector data from the Atlas du Patrimoine (http://atlas.patrimoines.culture.fr/atlas/trunk/), the official national platform of the French Ministry of Culture, and facilitate its use within R geospatial workflows. The package provides functions to list available heritage datasets, query and retrieve heritage data using spatial queries based on user-provided sf objects, perform spatial filtering operations, and return results as sf objects suitable for spatial analysis, mapping, and integration into heritage management and landscape studies. |
| License: | GPL (≥ 3) |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | jsonlite, happign, httr2, sf, xml2 |
| Depends: | R (≥ 4.1.0) |
| LazyData: | true |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.1.7), httptest2 |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-01-20 18:37:25 UTC; matth |
| Author: | Matthieu Chevereau [aut, cre] |
| Maintainer: | Matthieu Chevereau <matthieu.chevereau@hotmail.fr> |
| Repository: | CRAN |
| Date/Publication: | 2026-01-24 10:40:02 UTC |
Available layer datasets
Description
A dataset containing available layer datasets from the French Ministry of Culture's "Atlas du Patrimoine" service.
Usage
all_ids
Format
A data.frame with 5 columns:
- id
(character) Layer id.
- title
(character) Layer title.
- guid
(integer) Layer guid.
- code
(character) Internal code, determined from tile.
- departement
(character) Layer department
Details
Contains only data available on the 96 departments of metropolitan France.
Check that layer data codes are valid
Description
Validates that provided data codes exist in the heritage layers.
Usage
data_check(data_code)
Arguments
data_code |
|
Details
Uses
get_heritage_layernames()to get the list of valid codes.Throws an error if any
data_codeis invalid.
Value
NULL. Invisibly returns NULL if all codes are valid; otherwise throws an error.
See Also
Filter layer IDs by internal code and department
Description
Filters a dataset of layer IDs based on provided data codes and departments.
Usage
data_filter(ids = NULL, department, data_code)
Arguments
ids |
|
department |
|
data_code |
|
Details
Uses
data_check()to ensure that alldata_codevalues are valid.The function currently ignores the
idsargument and always usesfrheritage::all_ids.
Value
data.frame. Subset of ids filtered by data_code and department, with departement column removed.
Example files for testing
Description
These files are used internally for testing functions.
Cast geometries to simple types
Description
This internal helper converts multi-part geometries to their single-part equivalents: MULTIPOLYGON became POLYGON, MULTILINESTRING became LINESTRING, MULTIPOINT became POINT. If the input contains mixed types, each feature is cast individually.
Usage
geo_cast(x)
Arguments
x |
An |
Value
An sf object with geometries cast to simple types.
Retrieve INSEE department codes for each feature in an sf object
Description
This internal helper retrieves the administrative department (code_insee)
intersecting each feature of the input sf object. It uses the
Admin Express COG WFS service from IGN via the happign package.
Usage
geo_dep(x)
Arguments
x |
An |
Details
The input is first transform to CRS:4326.
Centroids of the features are computed before querying the WFS service.
The function uses
quiet()to suppress warnings/messages during processing.If the WFS query fails or returns no features, a vector of
NAvalues is returned.The spatial join is performed using
sf::st_join()withst_intersects.
Value
A character vector with the INSEE department code corresponding
to each feature of x. Returns NULL if no intersection is found.
Compute bounding boxes for each feature in an sf object
Description
This internal helper computes the bounding box (left, bottom, right, top)
for each feature in an sf object.
Usage
geo_extent(x, crs = 4326)
Arguments
x |
An |
crs |
Numeric, Code of the target CRS. Default is |
Details
The function first validates the input with
geo_object_check().Transforms the object to the target CRS before computing bounding boxes.
CRS and units are inherited from the input
sfobject.
Value
A data.frame where each row corresponds to a feature's bounding box,
with columns left, bottom, right, top.
Check that spatial objects are valid sf layers with expected geometry type
Description
This internal helper verifies that all provided objects:
are of class
sf(optional, controlled bycheck_class);contain valid geometries (
sf::st_is_valid());contain no empty geometries (
!sf::st_is_empty());have a geometry type among the allowed ones (if specified).
Usage
geo_object_check(
...,
check_class = TRUE,
check_valid = TRUE,
check_empty = TRUE,
allowed_geom_classes = "POLYGON"
)
Arguments
... |
One or several spatial objects to test. |
check_class |
Logical. Whether to check that each object inherits from
class |
check_valid |
Logical. Whether to check that geometries are valid.
Default is |
check_empty |
Logical. Whether to check that geometries are not empty.
Default is |
allowed_geom_classes |
Character vector of allowed geometry types
(e.g., |
Details
The function raises an informative error message if any condition fails.
It is intended for internal validation of sf inputs before performing
geometric operations or API queries.
Geometry type validation is performed via geo_object_type(), which ensures
type consistency across geometries.
Value
Invisibly returns NULL. Throws an error if any object fails validation.
See Also
Determine the geometry type of an sf object
Description
This internal helper function identifies and normalizes the geometry type
of an sf object. It ensures that all geometries within the object share
a consistent type (e.g., "POINT", "LINESTRING", "POLYGON").
If multiple geometry types are found, an error is raised.
Usage
geo_object_type(x)
Arguments
x |
An |
Details
The function retrieves the geometry type of the input using
sf::st_geometry_type() and standardizes it according to a simplified
classification:
-
"POINT"and"MULTIPOINT"="POINT" -
"LINESTRING"and"MULTILINESTRING"="LINE" -
"POLYGON"and"MULTIPOLYGON"="POLYGON" All other types =
"GEOMETRY"
Mixed or inconsistent geometry collections are not supported.
Value
A single character(1) value representing the normalized geometry type.
Possible values are: "POINT", "LINE", "POLYGON", or "GEOMETRY".
Prepare and aggregate an sf object
Description
This helper function prepares and aggregates an sf object
to produce clean, valid, and unified geometries.
Usage
geo_prepare(x, crs = 2154, buffer = 10)
Arguments
x |
An |
crs |
Integer. Code of the target CRS. Default is |
buffer |
Numeric. Buffer distance (in map units) used to merge nearby features. Default is |
Details
The function performs a complete geometric preparation workflow:
Geometry validation: ensures that all geometries belong to allowed classes (
POINT,LINE, orPOLYGON).Geometry cleaning: invalid features are fixed with
sf::st_make_valid(), Z/M dimensions are dropped viasf::st_zm(), and multipart geometries are cast to simple forms.Coordinate transformation: all geometries are transformed to the specified CRS using
sf::st_transform().Aggregation: small buffer zones (controlled by
buffer) are applied to merge adjacent or overlapping features. The buffered geometries are then dissolved withsf::st_union()and cast toPOLYGONtype.
This process is useful for simplifying feature sets into larger contiguous study zones or analysis areas.
Value
An sf object with cleaned, projected, and aggregated geometries as POLYGONs.
Bind multiple sf objects into a single sf
Description
This internal helper takes a list of sf objects, aligns their columns,
and binds them together into a single sf object. It removes NULL or empty
objects and handles nested lists of sf.
Usage
geo_sf_bind(sf_list)
Arguments
sf_list |
A list of |
Value
A single sf object containing all input features, or NULL
if the input list is empty or contains no valid sf objects.
Read and transform shapefiles from a ZIP archive
Description
Extracts shapefiles from a ZIP archive, reads them into sf objects,
and transform each to CRS:2154 (Lambert-93 projection for France),
unless already in the target CRS.
Usage
geo_shapefiles_read(zip_path, crs = 2154)
Arguments
zip_path |
|
crs |
|
Value
A list of sf objects transform to CRS:2154.
Validate a spatial predicate string
Description
Checks that the provided spatial filter is one of the allowed OGC predicates.
Usage
geo_spatial_check(spatial_filter)
Arguments
spatial_filter |
|
Value
character. The validated predicate in uppercase.
Filter an sf layer by spatial relationship
Description
This internal helper function filters features of an sf layer based on
a specified spatial relationship with another sf object.
Usage
geo_spatial_filter(layer, x, spatial_filter)
Arguments
layer |
An |
x |
An |
spatial_filter |
Character. The spatial predicate to apply. Must be one of:
|
Details
Uses
sf::st_intersects(),sf::st_disjoint(),sf::st_contains(), etc. depending on the value ofspatial_filter.-
"BBOX"is treated as a simple intersection with bounding boxes.
Value
A subset of layer where features satisfy the specified spatial predicate
with respect to x.
Check if an sf object exceeds size or extent thresholds
Description
This internal helper evaluates whether a spatial object is too large based on area (for polygons) and bounding box dimensions.
Usage
geo_too_large(
x,
area_threshold = 1e+09,
extent_threshold = 150000,
verbose = TRUE
)
Arguments
x |
An |
area_threshold |
Numeric. Maximum allowed area in m2 (for polygon geometries). Default is 1e9. |
extent_threshold |
Numeric. Maximum allowed bounding box width or height in meters. Default is 1.5e5. |
verbose |
Logical. If |
Value
Invisibly returns FALSE if within limits. Throws an error if thresholds are exceeded.
Retrieve and download heritage spatial data for a given sf object
Description
This function retrieves and downloads spatial heritage datasets from the
French Ministry of Culture’s "Atlas du Patrimoine" service,
based on the spatial extent and department(s) of a given sf object.
It first identifies relevant dataset IDs and then downloads corresponding
shapefiles for each requested heritage code.
Usage
get_heritage(
x,
data_code,
buffer = 2500,
crs = 2154,
spatial_filter = "intersects",
verbose = TRUE
)
Arguments
x |
An |
data_code |
A single |
buffer |
A |
crs |
An |
spatial_filter |
A |
verbose |
Logical. If |
Details
This functions only works for the 96 departments of metropolitan France.
Internally, the function:
Validates the requested heritage codes.
Checks the spatial filter.
Prepares the geometry and aggregates nearby geometries using
bufferinput.Determines the corresponding INSEE department code for each geometry, using
happign::get_wfs().Computes the bounding box of each geometry.
Filters layers ids for the requested
data_codeby usingfrheritage::all_ids.Builds the URL and downloads the zip archive containing the shapefiles.
Reads and merges shapefiles into
sfobjects.
Value
A single sf object if one heritage code was processed.
Returns an empty sf if no matching data is found.
Examples
if (interactive()) {
# Create a minimal sf object defining the area of interest.
# The geometry is used to identify relevant departments and
# to build spatial queries against the Atlas du Patrimoine.
my_sf_layer <- sf::st_sf(
geometry = sf::st_sfc(
sf::st_point(c(2.21, 48.82)),
crs = 4326
)
)
# Download spatial heritage data for a given heritage code.
# The function returns an sf object containing the retrieved features.
heritage_data <- get_heritage(
x = my_sf_layer,
data_code = "IMMH",
buffer = 2000,
spatial_filter = "intersects"
)
}
Retrieve heritage layer IDs for a given sf object
Description
This function retrieves available layer identifiers from the French Ministry
of Culture's "Atlas du Patrimoine" service feed, based on the
spatial extent and department(s) of a given sf object.
Usage
get_heritage_ids(x, buffer = 2500, crs = 2154, verbose = TRUE)
Arguments
x |
An |
buffer |
A |
crs |
An |
verbose |
Logical. If |
Details
Internally, the function:
Aggregates nearby geometries using
bufferinput.Determines the corresponding INSEE department code for each geometry, using
happign::get_wfs().Computes the bounding box of each geometry.
Queries the "Atlas du Patrimoine" service feed for all available metadata records (IDs, titles, GUIDs) within each bounding box.
Progress is shown for each request.
Value
A data.frame with the following columns:
- id
Numeric identifier extracted from the record GUID.
- title
Record title as published in the service feed.
- guid
Full GUID (unique resource identifier).
- code
Internal code associated with the layer.
Returns an empty data.frame if no records are found or the request fails.
Examples
if (interactive()) {
# Create a minimal sf object defining the area of interest.
# A simple point geometry is sufficient to trigger spatial queries.
my_sf_layer <- sf::st_sf(
geometry = sf::st_sfc(
sf::st_point(c(2.21, 48.82)),
crs = 4326
)
)
# Retrieve available heritage dataset identifiers intersecting
# the spatial extent derived from the sf object.
ids <- get_heritage_ids(my_sf_layer)
}
Get heritage layer codes and labels
Description
This function provides a reference table mapping internal codes to explore heritage layer available datasets from French Ministry of Culture's "Atlas du Patrimoine". Optionally, it can filter the table to return only selected codes.
Usage
get_heritage_layernames(code = NULL)
Arguments
code |
Optional |
Details
The available codes and their meanings are:
-
IMDN— Domaines nationaux -
IMMH— Immeubles classes ou inscrits -
IMUN— Patrimoine Mondial UNESCO – Emprise surfacique des biens -
LACR— Architecture Contemporaine Remarquable -
PADN— Protection au titre des abords de domaines nationaux -
PAMH— Protection au titre des abords de monuments historiques -
PAUN— Patrimoine Mondial UNESCO – Zone tampon des biens -
SICI— Sites classes ou inscrits -
SIPR— Sites patrimoniaux remarquables -
ZPPA— Zones de presomption de prescriptions archeologiques
Value
A data.frame with two columns:
- code
Official heritage layer code (character).
- label
Descriptive label (character).
Examples
# Get the full table of heritage layer codes
get_heritage_layernames()
# Filter for specific codes
get_heritage_layernames(c("IMMH", "SICI"))
Download and parse heritage metadata from a URL
Description
This internal helper performs an HTTP GET request to the given URL
(typically generated by ids_url_build()) and parses the RSS XML
response into a structured data.frame.
Usage
ids_download(url, timeout = 60)
Arguments
url |
|
timeout |
|
Value
A data.frame with columns:
- id
Numeric identifier extracted from the GUID.
- title
Record title as published in the service.
- guid
Full GUID (unique resource identifier).
Returns an empty data.frame if the request fails or no items are found.
Determine internal codes from IDs titles
Description
This internal function converts IDs tiles into their corresponding internal codes (e.g., "IMMH", "PAMH"). It matches based on predefined keyword patterns and chooses the most specific code when multiple patterns match.
Usage
ids_to_codes(x)
Arguments
x |
|
Value
character vector of internal codes corresponding to each input IDs titles.
Returns NA if no pattern matches.
Build a search URL for the RSS service
Description
This internal helper constructs a URL to query for the French Ministry
of Culture's "Atlas du Patrimoine" RSS service.
The URL filters data using a bounding box (extent) and an
INSEE department code (insee_dep).
Usage
ids_url_build(extent, insee_dep)
Arguments
extent |
A named list with elements |
insee_dep |
A character or numeric INSEE department code. |
Value
A character string containing the full URL to query the service.
Execute an expression completely silently
Description
This utility executes any R expression or function call and returns its value, while suppressing all printed output (cat, print), warnings, and messages.
Usage
quiet(expr)
Arguments
expr |
An R expression or function call to execute silently. |
Details
Useful to suppress noisy outputs from functions during package or script execution.
Evaluation occurs in the parent environment to access local variables.
Works cross-platform by redirecting
capture.outputtonulon Windows or/dev/nullon other OS.
Value
The result of evaluating expr.
Download a ZIP file from a given URL
Description
Downloads a ZIP file from a specified URL and saves it to a temporary file.
Usage
zip_download(url, id)
Arguments
url |
|
id |
|
Details
Uses
httr2to perform the HTTP request.If the HTTP response status is not 200, a warning is emitted and
NULLis returned.Errors during download are caught and a warning is printed.
Value
character or NULL.
Path to the temporary ZIP file, or NULL if download fails.
Build a URL query to download a ZIP
Description
Constructs a URL query to request a ZIP file containing spatial data from the French Ministry of Culture's "Atlas du Patrimoine" service.
Usage
zip_query_build(id, title, guid = NULL, extent_vals, crs = 2154)
Arguments
id |
|
title |
|
guid |
|
extent_vals |
|
crs |
|
Details
The function formats the bounding box and metadata into a JSON object, then encodes it into a URL suitable for the Atlas Patrimoines export service.
CRS is converted to a string
"EPSG:<code>".
Value
character. URL string for downloading the dataset in ZIP format.