CatastRo allows querying the OVCCoordenadas Web Service provided by the Sede electrónica del Catastro API directly through an R IDE.
This API is used to retrieve the spatial coordinates of an urban property. It is not necessary to be the owner to get the information; you only need to know the cadastral reference (RC) of the property. Although the RC is the only compulsory parameter, providing the address can improve results and help avoid errors in the RC.
Additionally, the API can be used to obtain the RC of an urban property. For this, the API requires the longitude and latitude. It also allows you to choose the spatial reference system (SRS, also known as CRS) from a list to express the coordinates.
Finally, the API addresses cases where the exact location of the registered urban property is unknown. In such cases, it returns all properties located within a 50-meter square around the given point.
The documentation of this API can be found here.
These functions are named catr_ovc_* and return a tibble, as provided by the package tibble.
CatastRo API
The OVCCoordenadas Web Service can be accessed using the following functions:
Reverse geocoding cadastral references
The function catr_ovc_get_rccoor() takes the coordinates (lat and lon) and the spatial reference system (srs) used to express them. It returns a tibble with the cadastral reference of the property at that spatial point, including other information such as the address (town, street, and number).
library(CatastRo)
result <- catr_ovc_get_rccoor(
lat = 38.6196566583596,
lon = -3.45624183836806,
srs = "4230"
)
knitr::kable(result)| refcat | address | pc.pc1 | pc.pc2 | geo.xcen | geo.ycen | geo.srs | ldt |
|---|---|---|---|---|---|---|---|
| 13077A01800039 | DS DISEMINADO Polígono 18 Parcela 39 000100200VH67C EL TIRADERO. SANTA CRUZ DE MUDELA (CIUDAD REAL) | 13077A0 | 1800039 | -3.456242 | 38.61966 | EPSG:4230 | DS DISEMINADO Polígono 18 Parcela 39 000100200VH67C EL TIRADERO. SANTA CRUZ DE MUDELA (CIUDAD REAL) |
The function accepts as a srs argument the following values:
data(catr_srs_values)
# OVC valid codes
library(dplyr)
catr_srs_values |>
filter(ovc_service == TRUE) |>
select(SRS, Description) |>
knitr::kable()| SRS | Description |
|---|---|
| 4230 | Geográficas en ED 50 |
| 4258 | Geográficas en ETRS89 |
| 4326 | Geográficas en WGS 80 |
| 23029 | UTM huso 29N en ED50 |
| 23030 | UTM huso 30N en ED50 |
| 23031 | UTM huso 31N en ED50 |
| 25829 | UTM huso 29N en ETRS89 |
| 25830 | UTM huso 30N en ETRS89 |
| 25831 | UTM huso 31N en ETRS89 |
| 32627 | UTM huso 27N en WGS 84 |
| 32628 | UTM huso 28N en WGS 84 |
| 32629 | UTM huso 29N en WGS 84 |
| 32630 | UTM huso 30N en WGS 84 |
| 32631 | UTM huso 31N en WGS 84 |
It is also possible to get all cadastral references within a 50-meter square centered on the coordinates lat and lon using the function catr_ovc_get_rccoor_distancia().
catr_ovc_get_rccoor_distancia(
lat = 40.96002,
lon = -5.663408,
srs = "4230"
) |>
knitr::kable()| geo.xcen | geo.ycen | geo.srs | refcat | address | cmun_ine | pc.pc1 | pc.pc2 | dt.loine.cp | dt.loine.cm | dt.lourb.dir.cv | dt.lourb.dir.pnp | ldt | dis |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| -5.663408 | 40.96002 | EPSG:4230 | 5877501TL7357F | AV REYES DE ESPAÑA 1 SALAMANCA (SALAMANCA) | 37274 | 5877501 | TL7357F | 37 | 274 | 643 | 1 | AV REYES DE ESPAÑA 1 SALAMANCA (SALAMANCA) | 21.81 |
| -5.663408 | 40.96002 | EPSG:4230 | 5778706TL7357H | AV REYES DE ESPAÑA 2 N2-4 SALAMANCA (SALAMANCA) | 37274 | 5778706 | TL7357H | 37 | 274 | 643 | 2 | AV REYES DE ESPAÑA 2 N2-4 SALAMANCA (SALAMANCA) | 23.18 |
Geocoding a cadastral reference
The opposite query is also possible. When provided with a cadastral reference (rc), province (province), and municipality (municipality), the function catr_ovc_get_cpmrc() returns the coordinates (lat and lon) in a specified srs, along with the address (town, street, and number).
catr_ovc_get_cpmrc(
rc = "13077A01800039",
srs = "4230",
province = "CIUDAD REAL",
municipality = "SANTA CRUZ DE MUDELA"
) |>
knitr::kable()| xcoord | ycoord | refcat | address | pc.pc1 | pc.pc2 | geo.xcen | geo.ycen | geo.srs | ldt |
|---|---|---|---|---|---|---|---|---|---|
| -3.456242 | 38.61966 | 13077A01800039 | DS DISEMINADO Polígono 18 Parcela 39 000100200VH67C EL TIRADERO. SANTA CRUZ DE MUDELA (CIUDAD REAL) | 13077A0 | 1800039 | -3.45624183836806 | 38.6196566583596 | EPSG:4230 | DS DISEMINADO Polígono 18 Parcela 39 000100200VH67C EL TIRADERO. SANTA CRUZ DE MUDELA (CIUDAD REAL) |
The province and municipality parameters are optional, but if municipality is provided, province must also be provided. If a value is passed to the province argument while municipality is NULL, the function catr_ovc_get_cpmrc() will display a message and return an empty tibble.
catr_ovc_get_cpmrc(
rc = "13077A01800039",
municipality = "SANTA CRUZ DE MUDELA"
) |>
knitr::kable()
#> Error code: 11. LA PROVINCIA ES OBLIGATORIA| refcat | geo.srs |
|---|---|
| 13077A01800039 | EPSG:4326 |
When using only rc the result is provided as expected:
# No warning, get the result
catr_ovc_get_cpmrc(rc = "13077A01800039") |>
knitr::kable()| xcoord | ycoord | refcat | address | pc.pc1 | pc.pc2 | geo.xcen | geo.ycen | geo.srs | ldt |
|---|---|---|---|---|---|---|---|---|---|
| -3.457532 | 38.61843 | 13077A01800039 | DS DISEMINADO Polígono 18 Parcela 39 000100200VH67C EL TIRADERO. SANTA CRUZ DE MUDELA (CIUDAD REAL) | 13077A0 | 1800039 | -3.45753233627867 | 38.6184314024661 | EPSG:4326 | DS DISEMINADO Polígono 18 Parcela 39 000100200VH67C EL TIRADERO. SANTA CRUZ DE MUDELA (CIUDAD REAL) |
