| Title: | R Interface to Get French Heritage Data |
| Version: | 0.1.1 |
| 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-04-17 16:46:21 UTC; matth |
| Author: | Matthieu Chevereau [aut, cre] |
| Maintainer: | Matthieu Chevereau <matthieu.chevereau@hotmail.fr> |
| Repository: | CRAN |
| Date/Publication: | 2026-04-17 17:00: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 if the Atlas service is reachable
Description
Performs a lightweight HTTP request to test whether a remote service
(typically the French cultural heritage Atlas) is reachable within a
specified timeout. The function uses a HEAD request to avoid downloading
content and returns a logical indicating availability.
Usage
atlas_ok(url = "http://atlas.patrimoines.culture.fr/atlas/trunk/", timeout = 4)
Arguments
url |
A |
timeout |
Numeric. Maximum time in seconds allowed for the request
(including connection and response). Default is |
Details
This function is designed to be robust and silent: any network error
(timeout, DNS failure, connection refusal, etc.) results in FALSE.
The function relies on httr2 and internally performs a HEAD request
using httr2::req_perform(). It does not modify global options and
does not raise errors.
Note that this function checks service reachability, not full functional correctness of the endpoint.
Value
A logical scalar:
-
TRUEif the service responds with an HTTP status code < 400 -
FALSEotherwise (error, timeout, or HTTP status >= 400)
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.
Compute bounding boxes for each feature in an sf object
Description
Computes one bounding box per geometry in an sf object.
Usage
geo_extent(x, crs = 4326)
Arguments
x |
An |
crs |
Numeric or sf CRS. Target CRS used before computation (default 4326). |
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 with one row per feature:
- left
xmin
- bottom
ymin
- right
xmax
- top
ymax
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 shapefile from a ZIP archive
Description
Extracts shapefiles from a ZIP archive, reads the shapefile found
in the "documents" folder into an sf object, and transforms it to
CRS:2154 (Lambert-93 projection for France), unless already in the target CRS.
Usage
geo_shapefile_read(zip_path, crs = 2154)
Arguments
zip_path |
|
crs |
|
Value
An sf object transformed to CRS:2154.
Retrieve INSEE department codes from an sf object
Description
This function retrieves the INSEE administrative department codes
(code_insee) intersecting the features of a given sf object.
It relies on the Admin Express COG WFS service provided by IGN,
accessed via the happign package.
Usage
get_deps(x)
Arguments
x |
An |
Details
The function performs the following steps:
Transforms the input geometries to CRS:4326.
Computes centroids of the geometries.
Queries the IGN WFS service (Admin Express COG) to retrieve departments.
Performs a spatial join using
sf::st_intersects().Extracts and returns unique
code_inseevalues.
Notes:
The function depends on the availability of the IGN WFS service.
Large or complex geometries may cause the request to fail.
In such cases, consider simplifying or reducing the spatial extent of
x.
Value
A character vector of unique INSEE department codes intersecting
the input geometries. Returns NULL if no intersection is found or if the
WFS request fails.
Examples
if (interactive()) {
# Minimal sf object (point in Paris)
x <- sf::st_sf(
geometry = sf::st_sfc(
sf::st_point(c(2.35, 48.85)),
crs = 4326
)
)
# Retrieve department code
get_deps(x)
# Multiple locations (Paris and Rouen)
x2 <- sf::st_sf(
geometry = sf::st_sfc(
sf::st_point(c(2.35, 48.85)), # 75
sf::st_point(c(1.09, 49.44)), # 76
crs = 4326
)
)
get_deps(x2)
}
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.
Usage
get_heritage(x, data_code, buffer = 2500, crs = 2154, verbose = TRUE)
Arguments
x |
An |
data_code |
A single |
buffer |
A |
crs |
An |
verbose |
Logical. If |
Details
It uses the spatial extent and inferred department(s) of the input sf
object to query an internal registry of heritage datasets, then downloads
and merges the corresponding spatial layers.
This function currently supports metropolitan France departments (96 units).
Internally, the function:
Validates the input
data_codeagainst an internal registry.Prepares and optionally buffers the input geometry.
Computes spatial extents (bounding boxes) for each feature.
Assigns each feature to one or more administrative departments.
Filters available heritage records using an internal dataset registry.
Builds query URLs for the Atlas du Patrimoine service.
Downloads ZIP archives containing shapefiles.
Reads, validates, and merges the resulting
sfobjects.
Partial failures are tolerated: invalid or empty responses for individual requests are skipped.
Value
A single sf object containing all retrieved heritage features.
Returns an empty sf object if no data is found or all requests fail.
Examples
if (interactive()) {
# Define a minimal spatial object (WGS84 point)
my_sf_layer <- sf::st_sf(
geometry = sf::st_sfc(
sf::st_point(c(2.21, 48.82)),
crs = 4326
)
)
# Retrieve heritage spatial data
res <- get_heritage(
x = my_sf_layer,
data_code = "IMMH",
buffer = 2000,
crs = 2154,
verbose = TRUE
)
}
Retrieve heritage layer IDs for a given sf object
Description
This function retrieves available heritage dataset identifiers from the French Ministry of Culture’s "Atlas du Patrimoine" service.
Usage
get_heritage_ids(x, buffer = 2500, crs = 2154, verbose = TRUE)
Arguments
x |
An |
buffer |
A |
crs |
An |
verbose |
Logical. If |
Details
It uses the spatial extent and inferred department(s) of the input sf
object to query the service.
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.
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).
- departement
Department code associated with the spatial query.
- 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.