Package {CatastRo}


Title: Interface to the Spanish 'Catastro' Web Services
Version: 1.1.0
Description: Access public spatial data from the Spanish 'Catastro' through its Infrastructure for Spatial Information in Europe ('INSPIRE') and related web services. Retrieve parcel, building, address and map image data and convert between property reference codes and coordinates.
License: GPL-2
URL: https://ropenspain.github.io/CatastRo/, https://github.com/rOpenSpain/CatastRo
BugReports: https://github.com/rOpenSpain/CatastRo/issues
Depends: R (≥ 4.1.0)
Imports: cli, dplyr, httr2 (≥ 1.0.0), lifecycle, mapSpain (≥ 1.0.0), rappdirs (≥ 0.3.0), sf (≥ 1.0.0), terra, tools, utils, xml2
Suggests: ggplot2, knitr, quarto, testthat (≥ 3.3.0), tibble, tidyterra, withr
VignetteBuilder: quarto
Config/Needs/website: ropenspain/rostemplate, devtools, sessioninfo, remotes, sfheaders, rapidjsonr, jsonify, geometries, magick
Config/roxygen2/markdown: TRUE
Config/roxygen2/version: 8.1.0
Config/testthat/edition: 3
Config/testthat/parallel: true
Copyright: Cadastral data © Dirección General del Catastro. See inst/COPYRIGHTS for data access and use conditions.
Encoding: UTF-8
LazyData: true
X-schema.org-isPartOf: https://ropenspain.es/
X-schema.org-keywords: catastro, cran, cran-r, gis, maps, r, r-package, ropenspain, rstats, spain, spatial, static-tiles
NeedsCompilation: no
Packaged: 2026-10-05 09:55:01 UTC; diego
Author: Ángel Delgado Panadero ORCID iD [aut, cph], Iñaki Ucar ORCID iD [ctb], Diego Hernangómez ORCID iD [aut, cre], Dirección General del Catastro [dtc] (Provider of cadastral data and web services)
Maintainer: Diego Hernangómez <diego.hernangomezherrero@gmail.com>
Repository: CRAN
Date/Publication: 2026-10-05 10:10:02 UTC

CatastRo: Interface to the Spanish 'Catastro' Web Services

Description

logo

Access public spatial data from the Spanish 'Catastro' through its Infrastructure for Spatial Information in Europe ('INSPIRE') and related web services. Retrieve parcel, building, address and map image data and convert between property reference codes and coordinates.

Author(s)

Maintainer: Diego Hernangómez diego.hernangomezherrero@gmail.com (ORCID)

Authors:

Other contributors:

See Also

Useful links:


ATOM INSPIRE: Download all addresses for a municipality

Description

Retrieve spatial data for all addresses in a municipality using the ATOM INSPIRE service. The result also contains the corresponding street information in fields prefixed with ⁠tfname_*⁠.

Usage

catr_atom_get_address(
  munic,
  to = NULL,
  cache = deprecated(),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

munic

Municipality name, partial name or cadastral code. Use catr_atom_search_munic() to find cadastral codes.

to

Optional territorial office containing munic. Use this argument to narrow the search.

cache

[Deprecated] This argument is no longer supported because results are always cached.

update_cache

Logical. Whether to refresh the cached file. Defaults to FALSE.

cache_dir

Path to a cache directory. If NULL or FALSE, the function stores cached files in a temporary directory. See base::tempdir().

verbose

Logical. Whether to display informational messages.

Value

An sf object. Returns NULL if the data cannot be retrieved.

References

API documentation.

INSPIRE services for cadastral cartography.

See Also

Work with cadastral addresses: catr_atom_get_address_db_all(), catr_wfs_get_address_bbox()

Query ATOM INSPIRE services: catr_atom_get_address_db_all(), catr_atom_get_buildings(), catr_atom_get_buildings_db_all(), catr_atom_get_parcels(), catr_atom_get_parcels_db_all(), catr_atom_search_munic()

Examples



s <- catr_atom_get_address("Melque", to = "Segovia")

library(ggplot2)

ggplot(s) +
  geom_sf(aes(color = specification)) +
  coord_sf(
    xlim = c(376200, 376850),
    ylim = c(4545000, 4546000)
  ) +
  labs(
    title = "Addresses",
    subtitle = "Melque de Cercos, Segovia"
  )



ATOM INSPIRE: List address download URLs

Description

Create a table of URLs provided by the Spanish Cadastre ATOM INSPIRE service for downloading addresses.

catr_atom_get_address_db_all() provides a summary table with all territorial offices and their municipalities, excluding the Basque Country and Navarre. catr_atom_get_address_db_to() provides a table for one territorial office and its municipalities.

Usage

catr_atom_get_address_db_all(
  cache = deprecated(),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

catr_atom_get_address_db_to(
  to,
  cache = deprecated(),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

cache

[Deprecated] This argument is no longer supported because results are always cached.

update_cache

Logical. Whether to refresh the cached file. Defaults to FALSE.

cache_dir

Path to a cache directory. If NULL or FALSE, the function stores cached files in a temporary directory. See base::tempdir().

verbose

Logical. Whether to display informational messages.

to

Character string. Territorial office to match using base::grep().

Value

A tibble with the requested information. Returns NULL if the data cannot be retrieved or no territorial office matches to.

catr_atom_get_address_db_all() returns the following columns:

catr_atom_get_address_db_to() returns munic, url and date for the selected territorial office.

Source

https://www.catastro.hacienda.gob.es/INSPIRE/Addresses/ES.SDGC.AD.atom.xml

See Also

Work with cadastral addresses: catr_atom_get_address(), catr_wfs_get_address_bbox()

Query ATOM INSPIRE services: catr_atom_get_address(), catr_atom_get_buildings(), catr_atom_get_buildings_db_all(), catr_atom_get_parcels(), catr_atom_get_parcels_db_all(), catr_atom_search_munic()

Examples



catr_atom_get_address_db_all()



ATOM INSPIRE: Download all buildings for a municipality

Description

Retrieve spatial data for all buildings in a municipality using the ATOM INSPIRE service.

Usage

catr_atom_get_buildings(
  munic,
  to = NULL,
  what = c("building", "buildingpart", "other"),
  cache = deprecated(),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

munic

Municipality name, partial name or cadastral code. Use catr_atom_search_munic() to find cadastral codes.

to

Optional territorial office containing munic. Use this argument to narrow the search.

what

Information to load, either "building" for buildings, "buildingpart" for parts of a building or "other" for other elements such as swimming pools.

cache

[Deprecated] This argument is no longer supported because results are always cached.

update_cache

Logical. Whether to refresh the cached file. Defaults to FALSE.

cache_dir

Path to a cache directory. If NULL or FALSE, the function stores cached files in a temporary directory. See base::tempdir().

verbose

Logical. Whether to display informational messages.

Value

An sf object. Returns NULL if the data cannot be retrieved.

References

API documentation.

INSPIRE services for cadastral cartography.

See Also

Work with cadastral buildings: catr_atom_get_buildings_db_all(), catr_wfs_get_buildings_bbox()

Query ATOM INSPIRE services: catr_atom_get_address(), catr_atom_get_address_db_all(), catr_atom_get_buildings_db_all(), catr_atom_get_parcels(), catr_atom_get_parcels_db_all(), catr_atom_search_munic()

Examples



s <- catr_atom_get_buildings("Nava de la Asuncion", to = "Segovia")

library(ggplot2)
ggplot(s) +
  geom_sf() +
  coord_sf(
    xlim = c(374500, 375500),
    ylim = c(4556500, 4557500)
  ) +
  labs(
    title = "Buildings",
    subtitle = "Nava de la Asuncion, Segovia"
  )



ATOM INSPIRE: List building download URLs

Description

Create a table of URLs provided by the Spanish Cadastre ATOM INSPIRE service for downloading buildings.

catr_atom_get_buildings_db_all() provides a summary table with all territorial offices and their municipalities, excluding the Basque Country and Navarre. catr_atom_get_buildings_db_to() provides a table for one territorial office and its municipalities.

Usage

catr_atom_get_buildings_db_all(
  cache = deprecated(),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

catr_atom_get_buildings_db_to(
  to,
  cache = deprecated(),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

cache

[Deprecated] This argument is no longer supported because results are always cached.

update_cache

Logical. Whether to refresh the cached file. Defaults to FALSE.

cache_dir

Path to a cache directory. If NULL or FALSE, the function stores cached files in a temporary directory. See base::tempdir().

verbose

Logical. Whether to display informational messages.

to

Character string. Territorial office to match using base::grep().

Value

A tibble with the requested information. Returns NULL if the data cannot be retrieved or no territorial office matches to.

catr_atom_get_address_db_all() returns the following columns:

catr_atom_get_address_db_to() returns munic, url and date for the selected territorial office.

Source

https://www.catastro.hacienda.gob.es/INSPIRE/buildings/ES.SDGC.BU.atom.xml

See Also

Work with cadastral buildings: catr_atom_get_buildings(), catr_wfs_get_buildings_bbox()

Query ATOM INSPIRE services: catr_atom_get_address(), catr_atom_get_address_db_all(), catr_atom_get_buildings(), catr_atom_get_parcels(), catr_atom_get_parcels_db_all(), catr_atom_search_munic()

Examples



catr_atom_get_buildings_db_all()



ATOM INSPIRE: Download all cadastral parcels for a municipality

Description

Retrieve spatial data for all cadastral parcels in a municipality using the ATOM INSPIRE service.

Usage

catr_atom_get_parcels(
  munic,
  to = NULL,
  what = c("parcel", "zoning"),
  cache = deprecated(),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

munic

Municipality name, partial name or cadastral code. Use catr_atom_search_munic() to find cadastral codes.

to

Optional territorial office containing munic. Use this argument to narrow the search.

what

Information to load, either "parcel" for cadastral parcels or "zoning" for cadastral zoning.

cache

[Deprecated] This argument is no longer supported because results are always cached.

update_cache

Logical. Whether to refresh the cached file. Defaults to FALSE.

cache_dir

Path to a cache directory. If NULL or FALSE, the function stores cached files in a temporary directory. See base::tempdir().

verbose

Logical. Whether to display informational messages.

Value

An sf object. Returns NULL if the data cannot be retrieved.

References

API documentation.

INSPIRE services for cadastral cartography.

See Also

Work with cadastral parcels: catr_atom_get_parcels_db_all(), catr_wfs_get_parcels_bbox()

Query ATOM INSPIRE services: catr_atom_get_address(), catr_atom_get_address_db_all(), catr_atom_get_buildings(), catr_atom_get_buildings_db_all(), catr_atom_get_parcels_db_all(), catr_atom_search_munic()

Examples



s <- catr_atom_get_parcels("Melque", to = "Segovia", what = "parcel")

library(ggplot2)

ggplot(s) +
  geom_sf() +
  labs(
    title = "Cadastral parcels",
    subtitle = "Melque de Cercos, Segovia"
  )



ATOM INSPIRE: List cadastral parcel download URLs

Description

Create a table of URLs provided by the Spanish Cadastre ATOM INSPIRE service for downloading cadastral parcels.

catr_atom_get_parcels_db_all() provides a summary table with all territorial offices and their municipalities, excluding the Basque Country and Navarre. catr_atom_get_parcels_db_to() provides a table for one territorial office and its municipalities.

Usage

catr_atom_get_parcels_db_all(
  cache = deprecated(),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

catr_atom_get_parcels_db_to(
  to,
  cache = deprecated(),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

cache

[Deprecated] This argument is no longer supported because results are always cached.

update_cache

Logical. Whether to refresh the cached file. Defaults to FALSE.

cache_dir

Path to a cache directory. If NULL or FALSE, the function stores cached files in a temporary directory. See base::tempdir().

verbose

Logical. Whether to display informational messages.

to

Character string. Territorial office to match using base::grep().

Value

A tibble with the requested information. Returns NULL if the data cannot be retrieved or no territorial office matches to.

catr_atom_get_address_db_all() returns the following columns:

catr_atom_get_address_db_to() returns munic, url and date for the selected territorial office.

Source

https://www.catastro.hacienda.gob.es/INSPIRE/CadastralParcels/ES.SDGC.CP.atom.xml

See Also

Work with cadastral parcels: catr_atom_get_parcels(), catr_wfs_get_parcels_bbox()

Query ATOM INSPIRE services: catr_atom_get_address(), catr_atom_get_address_db_all(), catr_atom_get_buildings(), catr_atom_get_buildings_db_all(), catr_atom_get_parcels(), catr_atom_search_munic()

Examples



catr_atom_get_parcels_db_all()



ATOM INSPIRE: Search for municipality codes

Description

Search for a municipality by name or code and return matching Spanish Cadastre municipality codes.

Usage

catr_atom_search_munic(
  munic,
  to = NULL,
  cache = deprecated(),
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

munic

Municipality name, partial name or cadastral code. Use catr_atom_search_munic() to find cadastral codes.

to

Optional territorial office containing munic. Use this argument to narrow the search.

cache

[Deprecated] This argument is no longer supported because results are always cached.

update_cache

Logical. Whether to refresh the cached file. Defaults to FALSE.

cache_dir

Path to a cache directory. If NULL or FALSE, the function stores cached files in a temporary directory. See base::tempdir().

verbose

Logical. Whether to display informational messages.

Value

A tibble with the territorial office, municipality name and cadastral code. Returns NULL if the data cannot be retrieved or no match is found.

See Also

catr_atom_get_address(), catr_atom_get_buildings() and catr_atom_get_parcels() accept the returned cadastral municipality code as munic. catr_get_code_from_coords() finds that code from coordinates.

Search for cadastral identifiers: catr_get_code_from_coords(), catr_ovc_get_cod_munic(), catr_ovc_get_cod_provinces()

Query ATOM INSPIRE services: catr_atom_get_address(), catr_atom_get_address_db_all(), catr_atom_get_buildings(), catr_atom_get_buildings_db_all(), catr_atom_get_parcels(), catr_atom_get_parcels_db_all()

Examples



catr_atom_search_munic("Mad")



Clear your CatastRo cache directory

Description

Use this function with caution. Depending on its arguments, this function:

Usage

catr_clear_cache(config = FALSE, cached_data = TRUE, verbose = FALSE)

Arguments

config

If TRUE, deletes the configuration directory of CatastRo.

cached_data

If TRUE, deletes your cache_dir and all its contents.

verbose

Logical. Whether to display informational messages.

Details

With config = TRUE and cached_data = TRUE, this function resets the cache state as if you had never used CatastRo.

Value

NULL, invisibly. This function is called for its side effects.

See Also

tools::R_user_dir() defines platform-specific user directories.

Manage the local cache: catr_set_cache_dir()

Examples


# Don't run this! It modifies your current state
## Not run: 
my_cache <- catr_detect_cache_dir()

# Set an example cache
ex <- file.path(tempdir(), "example", "cache")
catr_set_cache_dir(ex, verbose = FALSE)

# Restore initial cache
catr_clear_cache(verbose = TRUE)

catr_set_cache_dir(my_cache)
identical(my_cache, catr_detect_cache_dir())

## End(Not run)

Get a cadastral municipality code from coordinates

Description

Retrieve the municipality code associated with an sf object or a coordinate pair.

Usage

catr_get_code_from_coords(
  x,
  srs = NULL,
  verbose = FALSE,
  cache_dir = NULL,
  ...
)

Arguments

x

Coordinate input. It can be:

  • A pair of coordinates c(x, y). In this case the srs of the coordinates must be provided.

  • An sf object. If the object has several geometries, only the first geometry is used. This function extracts coordinates using sf::st_centroid(x, of_largest_polygon = TRUE).

srs

SRS/CRS to use in the query. To see allowed values, use catr_srs_values, specifically the ovc_service column.

verbose

Logical. Whether to display informational messages.

cache_dir

Path to a cache directory. If NULL or FALSE, the function stores cached files in a temporary directory. See base::tempdir().

...

Arguments passed on to mapSpain::esp_get_munic_siane

year

Character string or number. Release year. It must use format YYYY (assuming end of year) or YYYY-MM-DD. Historical information starts as of 2005.

resolution

Character string or number. Resolution of the geospatial data. One of:

  • "10": 1:10 million.

  • "6.5": 1:6.5 million.

  • "3": 1:3 million.

region

Optional. A vector of region names, NUTS or ISO codes (see esp_dict_region_code()).

munic

Character string. A name or regex expression with the names of the required municipalities. Use NULL to return all municipalities.

Details

On a successful query, this function returns a one-row tibble with the following columns:

Value

A tibble as described in Details. Returns NULL if the request fails.

See Also

Search for cadastral identifiers: catr_atom_search_munic(), catr_ovc_get_cod_munic(), catr_ovc_get_cod_provinces()

Examples



# Use with coordinates
catr_get_code_from_coords(c(-16.25462, 28.46824), srs = 4326)

# Use with an `sf` object.
prov <- mapSpain::esp_get_prov("Caceres")
catr_get_code_from_coords(prov)



OVCCallejero: Get municipality codes

Description

Query the OVCCallejero ConsultaMunicipioCodigos service to retrieve municipality names and codes from the Spanish Cadastre and the National Statistics Institute (INE).

Usage

catr_ovc_get_cod_munic(cpro, cmun = NULL, cmun_ine = NULL, verbose = FALSE)

Arguments

cpro

Province code returned by catr_ovc_get_cod_provinces().

cmun, cmun_ine

Municipality code as recorded by the Spanish Cadastre (cmun) or the National Statistics Institute (cmun_ine). Either cmun or cmun_ine must be provided.

verbose

Logical. Whether to display informational messages.

Details

On a successful query, this function returns a one-row tibble with the following columns:

Value

A tibble as described in Details. Returns NULL if the request fails.

References

ConsultaMunicipioCodigos.

See Also

catr_atom_search_munic() searches municipality codes by name. catr_atom_get_parcels() accepts the returned catrcode as munic. mapSpain::esp_get_munic_siane() retrieves municipality geometries, including the INE code.

Search for cadastral identifiers: catr_atom_search_munic(), catr_get_code_from_coords(), catr_ovc_get_cod_provinces()

Query OVC web services: catr_ovc_get_cod_provinces(), catr_ovc_get_cpmrc(), catr_ovc_get_rccoor(), catr_ovc_get_rccoor_distancia()

Examples



# Get municipality by cadastral code
ab <- catr_ovc_get_cod_munic(cpro = 2, cmun = 900)

ab

# Same query using the INE code

ab2 <- catr_ovc_get_cod_munic(cpro = 2, cmun_ine = 3)

ab2



OVCCallejero: Get province codes

Description

Query the OVCCallejero ConsultaProvincia service to retrieve provinces and their INE codes. Only provinces within the jurisdiction of the Directorate General for Cadastre are included.

Usage

catr_ovc_get_cod_provinces(verbose = FALSE)

Arguments

verbose

Logical. Whether to display informational messages.

Value

A tibble with province names and codes. Returns NULL if the request fails.

References

ConsultaProvincia.

See Also

catr_ovc_get_cod_munic() uses a province code as cpro to look up municipality codes.

Search for cadastral identifiers: catr_atom_search_munic(), catr_get_code_from_coords(), catr_ovc_get_cod_munic()

Query OVC web services: catr_ovc_get_cod_munic(), catr_ovc_get_cpmrc(), catr_ovc_get_rccoor(), catr_ovc_get_rccoor_distancia()

Examples



catr_ovc_get_cod_provinces()



OVCCoordenadas: Geocode a cadastral reference

Description

Query the OVCCoordenadas Consulta CPMRC service to retrieve coordinates for a parcel reference. The returned coordinates locate the parcel centroid.

Usage

catr_ovc_get_cpmrc(
  rc,
  srs = 4326,
  province = NULL,
  municipality = NULL,
  verbose = FALSE
)

Arguments

rc

A 14-character cadastral parcel reference to geocode.

srs

SRS/CRS to use in the query. To see allowed values, use catr_srs_values, specifically the ovc_service column.

province, municipality

Optional character strings used to narrow the search. province is required when municipality is provided.

verbose

Logical. Whether to display informational messages.

Details

If the API returns no results or reports an error, the result is a tibble containing only query information.

On a successful query, this function returns a tibble with one row per cadastral reference, including the following columns:

Value

A tibble as described in Details. Returns NULL if the request fails.

References

Consulta CPMRC.

See Also

Work with cadastral references: catr_ovc_get_rccoor(), catr_ovc_get_rccoor_distancia()

Query OVC web services: catr_ovc_get_cod_munic(), catr_ovc_get_cod_provinces(), catr_ovc_get_rccoor(), catr_ovc_get_rccoor_distancia()

Examples




# Using all arguments
catr_ovc_get_cpmrc("13077A01800039",
  4230,
  province = "CIUDAD REAL",
  municipality = "SANTA CRUZ DE MUDELA"
)

# Only the cadastral reference
catr_ovc_get_cpmrc("9872023VH5797S")



OVCCoordenadas: Reverse geocode coordinates

Description

Query the OVCCoordenadas Consulta RCCOOR service to retrieve the cadastral reference associated with a pair of coordinates.

Usage

catr_ovc_get_rccoor(lat, lon, srs = 4326, verbose = FALSE)

Arguments

lat

Y coordinate for the query, expressed in the SRS/CRS defined by srs. For geographic coordinates, this is the latitude.

lon

X coordinate for the query, expressed in the SRS/CRS defined by srs. For geographic coordinates, this is the longitude.

srs

SRS/CRS to use in the query. To see allowed values, use catr_srs_values, specifically the ovc_service column.

verbose

Logical. Whether to display informational messages.

Details

If the API returns no results or reports an error, the result is a tibble containing only query information.

On a successful query, this function returns a tibble with one row per cadastral reference, including the following columns:

Value

A tibble as described in Details. Returns NULL if the request fails.

References

Consulta RCCOOR.

See Also

catr_ovc_get_rccoor_distancia() also searches a nearby area when no exact match is found. catr_wfs_get_parcels_parcel() retrieves parcel geometries using the returned cadastral references.

Work with cadastral references: catr_ovc_get_cpmrc(), catr_ovc_get_rccoor_distancia()

Query OVC web services: catr_ovc_get_cod_munic(), catr_ovc_get_cod_provinces(), catr_ovc_get_cpmrc(), catr_ovc_get_rccoor_distancia()

Examples



catr_ovc_get_rccoor(
  lat = 38.6196566583596,
  lon = -3.45624183836806,
  srs = 4326
)



OVCCoordenadas: Find cadastral references near coordinates

Description

Query the OVCCoordenadas Consulta RCCOOR Distancia service to retrieve cadastral references near a pair of coordinates. If no exact match is found, the API searches a square with sides of 50 meters, centered on the requested coordinates.

Usage

catr_ovc_get_rccoor_distancia(lat, lon, srs = 4326, verbose = FALSE)

Arguments

lat

Y coordinate for the query, expressed in the SRS/CRS defined by srs. For geographic coordinates, this is the latitude.

lon

X coordinate for the query, expressed in the SRS/CRS defined by srs. For geographic coordinates, this is the longitude.

srs

SRS/CRS to use in the query. To see allowed values, use catr_srs_values, specifically the ovc_service column.

verbose

Logical. Whether to display informational messages.

Details

If the API returns no results or reports an error, the result is a tibble containing only query information.

On a successful query, this function returns a tibble with one row per cadastral reference, including the following columns:

Value

A tibble as described in Details. Returns NULL if the request fails.

References

Consulta RCCOOR Distancia.

See Also

catr_ovc_get_rccoor() looks up the cadastral reference at the exact coordinates. catr_wfs_get_parcels_parcel() retrieves parcel geometries using the returned cadastral references.

Work with cadastral references: catr_ovc_get_cpmrc(), catr_ovc_get_rccoor()

Query OVC web services: catr_ovc_get_cod_munic(), catr_ovc_get_cod_provinces(), catr_ovc_get_cpmrc(), catr_ovc_get_rccoor()

Examples



catr_ovc_get_rccoor_distancia(
  lat = 40.963200,
  lon = -5.671420,
  srs = 4326
)



Set your CatastRo cache directory

Description

Configure the cache directory used by CatastRo. Use Sys.getenv("CATASTROESP_CACHE_DIR") or catr_detect_cache_dir() to inspect the current path.

Usage

catr_set_cache_dir(
  cache_dir = NULL,
  overwrite = FALSE,
  install = FALSE,
  verbose = TRUE
)

catr_detect_cache_dir()

Arguments

cache_dir

Path to a cache directory. If NULL or FALSE, the function stores cached files in a temporary directory. See base::tempdir().

overwrite

Logical. Whether to overwrite an existing CATASTROESP_CACHE_DIR value already present on your machine.

install

Logical. Whether to store the path locally for use in future sessions. Defaults to FALSE.

verbose

Logical. Whether to display informational messages.

Details

By default, when no cache_dir is set, CatastRo uses a directory inside base::tempdir(), so files are temporary and are removed when the R session ends. To persist a cache across R sessions, use catr_set_cache_dir(cache_dir, install = TRUE), which writes the chosen path to a small configuration file under tools::R_user_dir("CatastRo", "config").

Value

catr_set_cache_dir() returns a character string containing the cache directory path, invisibly. This function is called for its side effects.

catr_detect_cache_dir() returns a character string containing the cache directory path used in this session.

Caching strategies

Source files are cached after download. CatastRo implements the following caching options:

Cached files can occasionally become corrupt. In that case, try downloading the data by setting update_cache = TRUE in the corresponding function.

If a download fails, try another download method and save the file in cache_dir. Use verbose = TRUE to inspect the API query and catr_detect_cache_dir() to identify your cache path.

Note

In CatastRo >= 1.0.0, the location of the configuration file has moved from rappdirs::user_config_dir("CatastRo", "R") to tools::R_user_dir("CatastRo", "config"). A migration function moves previous configuration files to the new location and displays a message. This message appears only once.

See Also

tools::R_user_dir() defines platform-specific user directories.

Manage the local cache: catr_clear_cache()

Examples


# Caution! This modifies your current state
## Not run: 
my_cache <- catr_detect_cache_dir()

# Set an example cache
ex <- file.path(tempdir(), "example", "cachenew")
catr_set_cache_dir(ex)

catr_detect_cache_dir()

# Restore initial cache
catr_set_cache_dir(my_cache)
identical(my_cache, catr_detect_cache_dir())

## End(Not run)

catr_detect_cache_dir()

Reference SRS codes for CatastRo services

Description

A tibble containing valid SRS values, also known as CRS values, for each API service. Values are represented as EPSG codes.

Format

A tibble with 16 rows and columns:

SRS

Spatial reference system (SRS) value, also known as a coordinate reference system (CRS), identified by the corresponding EPSG code.

Description

Description of the SRS/EPSG code.

ovc_service

Logical. Whether this code is valid for OVC services.

wfs_service

Logical. Whether this code is valid for WFS INSPIRE services.

Details

Table: Content of catr_srs_values

SRS Description ovc_service wfs_service
3785 ⁠Web Mercator⁠ FALSE TRUE
3857 ⁠Web Mercator⁠ FALSE TRUE
4230 ⁠Geográficas en ED 50⁠ TRUE FALSE
4258 ⁠Geográficas en ETRS89⁠ TRUE TRUE
4326 ⁠Geográficas en WGS 84⁠ TRUE TRUE
23029 ⁠UTM huso 29N en ED50⁠ TRUE FALSE
23030 ⁠UTM huso 30N en ED50⁠ TRUE FALSE
23031 ⁠UTM huso 31N en ED50⁠ TRUE FALSE
25829 ⁠UTM huso 29N en ETRS89⁠ TRUE TRUE
25830 ⁠UTM huso 30N en ETRS89⁠ TRUE TRUE
25831 ⁠UTM huso 31N en ETRS89⁠ TRUE TRUE
32627 ⁠UTM huso 27N en WGS 84⁠ TRUE FALSE
32628 ⁠UTM huso 28N en WGS 84⁠ TRUE FALSE
32629 ⁠UTM huso 29N en WGS 84⁠ TRUE FALSE
32630 ⁠UTM huso 30N en WGS 84⁠ TRUE FALSE
32631 ⁠UTM huso 31N en WGS 84⁠ TRUE FALSE

References

See Also

catr_ovc_get_cpmrc() and catr_ovc_get_rccoor() accept SRS codes listed in the ovc_service column. catr_wfs_get_parcels_bbox() accepts codes listed in the wfs_service column. sf::st_crs() inspects the corresponding coordinate reference system.

Examples

data("catr_srs_values")

# OVC valid codes
library(dplyr)

catr_srs_values |> filter(ovc_service)

# WFS valid codes

catr_srs_values |> filter(wfs_service)

# Use with sf::st_crs()

catr_srs_values |>
  filter(wfs_service & ovc_service) |>
  print() |>
  # Select the first value.
  slice_head(n = 1) |>
  pull(SRS) |>
  # Convert to a CRS.
  sf::st_crs(.)

WFS INSPIRE: Download addresses

Description

Retrieve spatial address data through several types of WFS queries:

Usage

catr_wfs_get_address_bbox(x, srs = NULL, verbose = FALSE)

catr_wfs_get_address_codvia(codvia, del, mun, srs = NULL, verbose = FALSE)

catr_wfs_get_address_rc(rc, srs = NULL, verbose = FALSE)

catr_wfs_get_address_postalcode(postalcode, srs = NULL, verbose = FALSE)

Arguments

x

Input defining the query area. See Bounding box. It can be:

  • A numeric vector of length 4 with the coordinates that define the bounding box: c(xmin, ymin, xmax, ymax).

  • An sf or sfc object from sf.

srs

SRS/CRS to use in the query. To see allowed values, use catr_srs_values, specifically the wfs_service column. See Bounding box.

verbose

Logical. Whether to display informational messages.

codvia

Cadastral street code.

del

Cadastral office code.

mun

Cadastral municipality code.

rc

Cadastral reference to retrieve.

postalcode

Postal code.

Value

An sf object. Returns NULL if the data cannot be retrieved.

API limits

The API service is limited to a bounding box of 4 km2 and a maximum of 5,000 elements.

Bounding box

When x is a numeric vector, make sure that srs matches the coordinate values. This function queries the bounding box in EPSG:25830, ETRS89 / UTM zone 30N, to work around a potential API issue.

When x is an sf object, the srs value is ignored. In this case, the bounding box of the sf object is used for the query (see sf::st_bbox()).

The result uses the SRS of the input spatial object or the srs value provided with a numeric vector.

References

API documentation.

INSPIRE services for cadastral cartography.

See Also

catr_wms_get_layer() downloads a map image using the returned spatial object as its extent (x).

Work with cadastral addresses: catr_atom_get_address(), catr_atom_get_address_db_all()

Query WFS INSPIRE services: catr_wfs_get_buildings_bbox(), catr_wfs_get_parcels_bbox(), inspire_wfs_get()

Examples



ad <- catr_wfs_get_address_bbox(
  c(
    233673, 4015968, 233761, 4016008
  ),
  srs = 25830
)

library(ggplot2)

ggplot(ad) +
  geom_sf()



WFS INSPIRE: Download buildings

Description

Retrieve spatial building data through two types of WFS queries:

Usage

catr_wfs_get_buildings_bbox(
  x,
  what = c("building", "buildingpart", "other"),
  srs = NULL,
  verbose = FALSE
)

catr_wfs_get_buildings_rc(
  rc,
  what = c("building", "buildingpart", "other"),
  srs = NULL,
  verbose = FALSE
)

Arguments

x

Input defining the query area. See Bounding box. It can be:

  • A numeric vector of length 4 with the coordinates that define the bounding box: c(xmin, ymin, xmax, ymax).

  • An sf or sfc object from sf.

what

Information to load, either "building" for buildings, "buildingpart" for parts of a building or "other" for other elements such as swimming pools.

srs

SRS/CRS to use in the query. To see allowed values, use catr_srs_values, specifically the wfs_service column. See Bounding box.

verbose

Logical. Whether to display informational messages.

rc

Cadastral reference to retrieve.

Value

An sf object. Returns NULL if the data cannot be retrieved.

API limits

The API service is limited to a bounding box of 4 km2 and a maximum of 5,000 elements.

Bounding box

When x is a numeric vector, make sure that srs matches the coordinate values. This function queries the bounding box in EPSG:25830, ETRS89 / UTM zone 30N, to work around a potential API issue.

When x is an sf object, the srs value is ignored. In this case, the bounding box of the sf object is used for the query (see sf::st_bbox()).

The result uses the SRS of the input spatial object or the srs value provided with a numeric vector.

References

API documentation.

INSPIRE services for cadastral cartography.

See Also

catr_wms_get_layer() downloads a map image using the returned spatial object as its extent (x).

Work with cadastral buildings: catr_atom_get_buildings(), catr_atom_get_buildings_db_all()

Query WFS INSPIRE services: catr_wfs_get_address_bbox(), catr_wfs_get_parcels_bbox(), inspire_wfs_get()

Examples



# Using a bounding box
building <- catr_wfs_get_buildings_bbox(
  c(
    376550,
    4545424,
    376600,
    4545474
  ),
  srs = 25830
)
library(ggplot2)
ggplot(building) +
  geom_sf() +
  labs(title = "Search using a bounding box")

# Using a cadastral reference
rc <- catr_wfs_get_buildings_rc("6656601UL7465N")
library(ggplot2)
ggplot(rc) +
  geom_sf() +
  labs(title = "Search using rc")



WFS INSPIRE: Download cadastral parcels

Description

Retrieve spatial cadastral parcel and zoning data through several types of WFS queries:

Usage

catr_wfs_get_parcels_bbox(
  x,
  what = c("parcel", "zoning"),
  srs = NULL,
  verbose = FALSE
)

catr_wfs_get_parcels_zoning(cod_zona, srs = NULL, verbose = FALSE)

catr_wfs_get_parcels_parcel(rc, srs = NULL, verbose = FALSE)

catr_wfs_get_parcels_neigh_parcel(rc, srs = NULL, verbose = FALSE)

catr_wfs_get_parcels_parcel_zoning(cod_zona, srs = NULL, verbose = FALSE)

Arguments

x

Input defining the query area. See Bounding box. It can be:

  • A numeric vector of length 4 with the coordinates that define the bounding box: c(xmin, ymin, xmax, ymax).

  • An sf or sfc object from sf.

what

Information to load, either "parcel" for cadastral parcels or "zoning" for cadastral zoning.

srs

SRS/CRS to use in the query. To see allowed values, use catr_srs_values, specifically the wfs_service column. See Bounding box.

verbose

Logical. Whether to display informational messages.

cod_zona

Cadastral zone code.

rc

Cadastral reference to retrieve.

Value

An sf object. Returns NULL if the data cannot be retrieved.

API limits

The API service has the following limits:

Bounding box

When x is a numeric vector, make sure that srs matches the coordinate values. This function queries the bounding box in EPSG:25830, ETRS89 / UTM zone 30N, to work around a potential API issue.

When x is an sf object, the srs value is ignored. In this case, the bounding box of the sf object is used for the query (see sf::st_bbox()).

The result uses the SRS of the input spatial object or the srs value provided with a numeric vector.

References

API documentation.

INSPIRE services for cadastral cartography.

See Also

catr_wms_get_layer() downloads a map image using the returned spatial object as its extent (x).

Work with cadastral parcels: catr_atom_get_parcels(), catr_atom_get_parcels_db_all()

Query WFS INSPIRE services: catr_wfs_get_address_bbox(), catr_wfs_get_buildings_bbox(), inspire_wfs_get()

Examples



cp <- catr_wfs_get_parcels_bbox(
  c(
    233673, 4015968, 233761, 4016008
  ),
  srs = 25830
)

library(ggplot2)

ggplot(cp) +
  geom_sf()



WMS INSPIRE: Download georeferenced map images

Description

Retrieve georeferenced map images from the Spanish Cadastre WMS service. This function wraps mapSpain::esp_get_tiles().

Usage

catr_wms_get_layer(
  x,
  srs = NULL,
  what = c("building", "buildingpart", "parcel", "zoning", "address", "admboundary",
    "admunit"),
  styles = "default",
  update_cache = FALSE,
  cache_dir = NULL,
  verbose = FALSE,
  crop = FALSE,
  options = NULL,
  ...
)

Arguments

x

Input defining the query area. See Bounding box. It can be:

  • A numeric vector of length 4 with the coordinates that define the bounding box: c(xmin, ymin, xmax, ymax).

  • An sf or sfc object from sf.

srs

SRS/CRS to use in the query. To see allowed values, use catr_srs_values, specifically the wfs_service column. See Bounding box.

what

WMS layer to download. See Layers and styles.

styles

Style to apply to the selected WMS layer. See Layers and styles.

update_cache

Logical. Whether to refresh the cached file. Defaults to FALSE.

cache_dir

Path to a cache directory. If NULL or FALSE, the function stores cached files in a temporary directory. See base::tempdir().

verbose

Logical. Whether to display informational messages.

crop

Logical. If TRUE, crop results to the specified x extent. If x is an sf object with one POINT, crop is set to FALSE. See terra::crop().

options

A named list containing additional options to pass to the query.

...

Arguments passed on to mapSpain::esp_get_tiles

res

Character string or number. Only valid for WMS providers. Resolution (in pixels) of the final tile.

bbox_expand

Number. Expansion percentage of the bounding box of x.

transparent

Logical. Whether to use a transparent background, if supported.

mask

Logical. TRUE to mask the result to x. See terra::mask().

Value

A SpatRaster with three RGB or four RGBA layers. See terra::RGB().

Bounding box

When x is a numeric vector, make sure that srs matches the coordinate values. When x is an sf object, the srs value is ignored.

The query uses EPSG:3857 (Web Mercator), then transforms the tile back to the SRS of x. If the tile appears distorted, provide a spatial object as x or set srs to the SRS of the requested tile. See Examples.

Layers and styles

Layers

The what argument selects one of the following API layers:

Styles

The WMS service provides different styles for each layer (what argument). Available styles include:

See the API documentation for complete layer and style information.

See Also

Examples



if (requireNamespace("tidyterra", quietly = TRUE)) {
  # With a bounding box

  pict <- catr_wms_get_layer(
    c(222500, 4019500, 223700, 4020700),
    srs = 25830,
    what = "parcel"
  )

  library(mapSpain)
  library(ggplot2)
  library(tidyterra)

  ggplot() +
    geom_spatraster_rgb(data = pict)

  # With a spatial object

  parcels <- catr_wfs_get_parcels_neigh_parcel("3662303TF3136B", srs = 25830)

  # Use styles

  parcels_img <- catr_wms_get_layer(parcels,
    what = "buildingpart",
    srs = 25830, # Same as the parcels object
    bbox_expand = 0.3,
    styles = "ELFCadastre"
  )

  ggplot() +
    geom_sf(data = parcels, fill = "blue", alpha = 0.5) +
    geom_spatraster_rgb(data = parcels_img)
}



Query WFS INSPIRE services

Description

Build and run a WFS INSPIRE request. This function supports the package's WFS functions and is also available for querying other cadastral or INSPIRE resources.

Usage

inspire_wfs_get(
  scheme = "https",
  hostname = "ovc.catastro.meh.es",
  path = "INSPIRE/wfsCP.aspx",
  query = list(),
  cache_dir = NULL,
  verbose = FALSE
)

Arguments

scheme

Character string specifying the protocol used to access the resource.

hostname

Character string specifying the resource host.

path

Character string specifying the resource path on the host.

query

Named list of query parameters and their values.

cache_dir

Path to a cache directory. If NULL or FALSE, the function stores cached files in a temporary directory. See base::tempdir().

verbose

Logical. Whether to display informational messages.

Details

This function constructs a request URL from its components, downloads the result to the cache directory and reports WFS exceptions. See Examples.

Value

A character string containing the downloaded file path. Returns NULL if the request fails.

See Also

Query WFS INSPIRE services: catr_wfs_get_address_bbox(), catr_wfs_get_buildings_bbox(), catr_wfs_get_parcels_bbox()

Examples


# Access the Cadastre of Navarre.
# See also https://ropenspain.github.io/CatastRoNav/

file_local <- inspire_wfs_get(
  hostname = "inspire.navarra.es",
  path = "services/BU/wfs",
  query = list(
    service = "WFS",
    request = "getfeature",
    typenames = "BU:Building",
    bbox = "609800,4740100,611000,4741300",
    SRSNAME = "EPSG:25830"
  )
)

if (!is.null(file_local)) {
  pamp <- sf::read_sf(file_local)

  if (requireNamespace("ggplot2", quietly = TRUE)) {
    library(ggplot2)
    ggplot(pamp) +
      geom_sf()
  }
}


Decide whether an example should run

Description

Determine whether an example should run based on the current platform and network availability.

Usage

run_example()

Details

Returns FALSE on CRAN, macOS or when offline.

Value

A logical value, TRUE if examples should run, FALSE otherwise.

Examples

run_example()