Skip to contents

Given pairs of coordinates, generates their INSPIRE grid representation. Given INSPIRE identifiers, can also extract the X and Y coordinates.

An INSPIRE ID contains information about the CRS, cell size and the ETRS89-LAEA coordinates of the south-west corner of the grid cell in its format. Only the relevant first digits are used in place of the full coordinates. In case of res = "100km", these are the first two digits, for res = "100m" the first five digits.

CRS3035{cellsize}mN{y}E{x} # new format
{cellsize}N{y}E{x}         # legacy format

The legacy format always uses meters while the legacy formats aggregates cell sizes greater or equal to 1000m to km.

Usage

z22_inspire_generate(coords, res = NULL, legacy = FALSE)

z22_inspire_extract(inspire, as_sf = FALSE)

Arguments

coords

A list, matrix, or dataframe where the X and Y coordinates are either in the columns "x" and "y" or in the first and second column position, respectively. Column names are converted to lowercase.

Can also be a sf/sfc object in which case the coordinates are extracted using st_coordinates.

res

Resolution of the grid. Can be "100m", "250m", "1km", "5km", "10km", or "100km". If NULL, tries to guess the resolution from the provided coordinates.

legacy

If TRUE, generates legacy INSPIRE ID. Defaults to FALSE.

inspire

A vector of INSPIRE IDs. Can be either legacy or non-legacy.

as_sf

Whether to return an object of class sfc or a tibble.

Value

z22_inspire_generate returns a character vector containing the INSPIRE identifiers. z22_inspire_extract returns a dataframe or sfc object containing the points extracted from the INSPIRE identifiers. Note that the returned coordinates are always the centers of the grid cells as opposed to the south-west corners.

Details

To remain fast even for huge grid datasets, the function is just a very simple sprintf wrapper that performs no input checks. To produce valid INSPIRE identifiers, make sure to transform your data to ETRS89-LAEA (e.g. using st_transform(..., 3035)). You should also make sure that the coordinates are the south-west corner of existing INSPIRE grid cells.

Examples

library(dplyr, warn.conflicts = FALSE)

# Generate IDs from a dataframe
coords <- tibble(x = c(4334150, 4334250), y = c(2684050, 2684050))
identical(z22_inspire_extract(z22_inspire_generate(coords)), coords)
#> [1] TRUE

# Extract coordinates from legacy ID strings
z22_inspire_extract("100mN34000E44000")
#> # A tibble: 1 × 2
#>         x       y
#>     <dbl>   <dbl>
#> 1 4400050 3400050

# Generate IDs from an sf dataframe
if (requireNamespace("sf", quietly = TRUE)) {
  coords <- sf::st_as_sf(coords, coords = c("x", "y"))
  z22_inspire_generate(coords)
}
#> [1] "CRS3035RES100mN26840E43341" "CRS3035RES100mN26840E43342"