Learn R Programming

frheritage (version 0.1.0)

get_heritage: 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
)

Value

A single sf object if one heritage code was processed. Returns an empty sf if no matching data is found.

Arguments

x

An sf object defining the area of interest.

data_code

A single character heritage dataset codes to retrieve. Valid codes can be obtained with get_heritage_layernames().

buffer

A numeric value (default = 2500). Buffer distance in meters used to slightly expand geometries before querying.

crs

An integer or sf::st_crs object (default = 2154). Coordinate reference system used for spatial processing.

spatial_filter

A character string (default = "intersects"). Spatial predicate to filter downloaded features.

verbose

Logical. If TRUE (default), prints progress and diagnostic messages.

Details

This functions only works for the 96 departments of metropolitan France.

Internally, the function:

  1. Validates the requested heritage codes.

  2. Checks the spatial filter.

  3. Prepares the geometry and aggregates nearby geometries using buffer input.

  4. Determines the corresponding INSEE department code for each geometry, using happign::get_wfs().

  5. Computes the bounding box of each geometry.

  6. Filters layers ids for the requested data_code by using frheritage::all_ids.

  7. Builds the URL and downloads the zip archive containing the shapefiles.

  8. Reads and merges shapefiles into sf objects.

Examples

Run this code
# \donttest{
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"
  )
}
# }

Run the code above in your browser using DataLab