
Get the cadastral municipality code from coordinates
Source:R/catr-code-coords.R
catr_get_code_from_coords.RdRetrieve the municipality code associated with an sf object
or a coordinate pair.
Arguments
- x
Coordinate input. It can be:
A pair of coordinates
c(x, y). In this case thesrsof the coordinates must be provided.A
sfobject. If the object has several geometries, only the first geometry is used. This function extracts coordinates usingsf::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_servicecolumn.- verbose
Logical. If
TRUE, displays informational messages.- cache_dir
Path to a cache directory. If
NULLorFALSE, the function stores cached files in a temporary directory. Seebase::tempdir().- ...
Arguments passed on to
mapSpain::esp_get_munic_sianeyearCharacter string or number. Release year. It must use format
YYYY(assuming end of year) orYYYY-MM-DD. Historical information starts as of 2005.resolutionCharacter string or number. Resolution of the geospatial data. One of:
"10": 1:10 million."6.5": 1:6.5 million."3": 1:3 million.
regionOptional. A vector of region names, NUTS or ISO codes (see
esp_dict_region_code()).municCharacter string. A name or
regexexpression with the names of the required municipalities. UseNULLto return all municipalities.
Value
A tibble as described in Details. Returns
NULL if the request fails.
Details
On a successful query, this function returns a tibble with one row including the following columns:
munic: Municipality name used by the Spanish Cadastre.catr_to: Cadastral territorial office code.catr_munic: Municipality code as recorded by the Cadastre.catrcode: Full cadastral code for the municipality.cpro: Province code according to the INE.cmun: Municipality code according to the INE.inecode: Full INE code for the municipality.Remaining fields: See the API documentation.
See also
mapSpain::esp_get_munic_siane()retrieves municipality geometries.catr_ovc_get_cod_munic()retrieves municipality codes.sf::st_centroid()computes geometry centroids.
Search for cadastral identifiers:
catr_atom_search_munic(),
catr_ovc_get_cod_munic(),
catr_ovc_get_cod_provinces()
Examples
# \donttest{
# Use with coordinates
catr_get_code_from_coords(c(-16.25462, 28.46824), srs = 4326)
#> ✖ The request could not be completed.
#> ! Failed to perform HTTP request.
#> Caused by error in `curl::curl_fetch_memory()`:
#> ! Failure when receiving data from the peer [ovc.catastro.meh.es]:
#> Recv failure: Connection reset by peer
#> → Returning "NULL" because the request failed.
#> NULL
# Use with an sf object
prov <- mapSpain::esp_get_prov("Caceres")
catr_get_code_from_coords(prov)
#> ✖ The request could not be completed.
#> ! Failed to perform HTTP request.
#> Caused by error in `curl::curl_fetch_memory()`:
#> ! Failure when receiving data from the peer [ovc.catastro.meh.es]:
#> Recv failure: Connection reset by peer
#> → Returning "NULL" because the request failed.
#> NULL
# }