Skip to contents

This function takes as an input a pair of coordinates of a sf object and returns the corresponding municipality code for that coordinates.

See also mapSpain::esp_get_munic_siane() and catr_ovc_get_cod_munic().

Usage

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

Arguments

x

It could be:

  • A pair of coordinates c(x,y).

  • A sf object. See Details.

srs

SRS/CRS to use on the query. To check the admitted values check catr_srs_values, specifically the wfs_service column. See Details.

verbose

Logical, displays information. Useful for debugging, default is FALSE.

cache_dir

A path to a cache directory. On missing value the function would store the cached files on a temporary dir (See base::tempdir()).

...

Arguments passed on to mapSpain::esp_get_munic_siane

year

Release year. See Details for years available.

Value

A tibble with the format described in catr_ovc_get_cod_munic().

Details

When x is a numeric vector, make sure that the srs matches the coordinate values.

When x is a sf object, only the first value would be used. The function would extract the coordinates using sf::st_centroid(x, of_largest_polygon = TRUE).

Examples

# \donttest{
# Use with coords
catr_get_code_from_coords(c(-16.25462, 28.46824), srs = 4326)
#> # A tibble: 1 × 12
#>   munic      catr_to catr_…¹ catrc…² cpro  cmun  inecode nm    cd    cmc   cp   
#>   <chr>      <chr>   <chr>   <chr>   <chr> <chr> <chr>   <chr> <chr> <chr> <chr>
#> 1 SANTA CRU… 38      900     38900   38    038   38038   SANT… 38    900   38   
#> # … with 1 more variable: cm <chr>, and abbreviated variable names ¹​catr_munic,
#> #   ²​catrcode

# Use with sf
prov <- mapSpain::esp_get_prov("Caceres")
catr_get_code_from_coords(prov)
#> # A tibble: 1 × 12
#>   munic  catr_to catr_munic catrcode cpro  cmun  inecode nm    cd    cmc   cp   
#>   <chr>  <chr>   <chr>      <chr>    <chr> <chr> <chr>   <chr> <chr> <chr> <chr>
#> 1 MONROY 10      128        10128    10    125   10125   MONR… 10    128   10   
#> # … with 1 more variable: cm <chr>
# }