---
title: "OVCCoordenadas service"
description: Geocode cadastral references and reverse geocode coordinates.
author:
  - name: Ángel Delgado Panadero
    orcid: 0000-0002-8189-9251
  - name: Diego Hernangómez
    orcid: 0000-0001-8457-4658
tbl-cap-location: bottom
vignette: >
  %\VignetteIndexEntry{OVCCoordenadas service}
  %\VignetteEngine{quarto::html}
  %\VignetteEncoding{UTF-8}
---

<!-- ovcservice.qmd is generated from ovcservice.qmd.orig. Please edit that file -->



**CatastRo** provides an **R** interface to the **OVCCoordenadas** service from
the [Sede electrónica del Catastro](https://ovc.catastro.meh.es/ovcservweb/ovcswlocalizacionrc/ovccoordenadas.asmx).

This service retrieves the parcel centroid coordinates for a 14-character
cadastral parcel reference. Optional province and municipality values can
narrow the search. Province is required when municipality is provided.

The service can also retrieve cadastral references from longitude and latitude.
You can choose the spatial reference system (SRS, also known as a coordinate
reference system or CRS) used to express the coordinates.

If no exact match is found, the distance query returns cadastral references
within a square with sides of 50 meters, centered on the requested coordinates.

See the [**OVCCoordenadas** service
documentation](https://ovc.catastro.meh.es/ovcservweb/ovcswlocalizacionrc/ovccoordenadas.asmx)
for endpoint details.

These functions use the `catr_ovc_get_*()` prefix and return tibbles from the
**tibble** package.

## CatastRo API

The **OVCCoordenadas** service is available through the following functions:

- `catr_ovc_get_rccoor()`.
- `catr_ovc_get_rccoor_distancia()`.
- `catr_ovc_get_cpmrc()`.

## Reverse geocoding coordinates

`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).


``` r
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) |



This function accepts the following values for the `srs` argument:


``` r
data(catr_srs_values)

# Valid OVC SRS 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 84  |
| 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 |



If no exact match is found, `catr_ovc_get_rccoor_distancia()` retrieves cadastral
references within a square with sides of 50 meters, centered on `lat` and `lon`.
The `dis` column gives the distance to the queried point, and `cmun_ine`
combines the INE province and municipality codes into a five-digit code.


``` r
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

For geocoding, `catr_ovc_get_cpmrc()` accepts a 14-character cadastral parcel
reference (`rc`) and returns its centroid coordinates as `xcoord` and `ycoord`
in the specified `srs`, together with the address. Optional `province` and
`municipality` values can narrow the search. `province` is required when
`municipality` is provided.


``` r
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 following query shows that `municipality` alone is not sufficient to narrow
the search:


``` r
catr_ovc_get_cpmrc(
  rc = "13077A01800039",
  municipality = "SANTA CRUZ DE MUDELA"
) |>
  knitr::kable()
#> ✖ OVC service error 11: LA PROVINCIA ES OBLIGATORIA
```



|refcat         |geo.srs   |
|:--------------|:---------|
|13077A01800039 |EPSG:4326 |



You can also query by providing only `rc`:


``` r
# Query using only the cadastral reference.
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) |


