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.
CRS3035RES{cellsize}mN{y}E{x} # long format
{cellsize}N{y}E{x}         # short formatThe short format always uses meters while the short formats aggregates cell sizes greater or equal to 1000m to km.
Usage
z22_inspire_generate(coords, res = NULL, short = FALSE, llc = FALSE)
z22_inspire_extract(inspire, as = c("df", "sf"), meta = 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/sfcobject in which case the coordinates are extracted usingst_coordinates.- res
 Resolution of the grid. Can be
"100m","250m","1km","5km","10km", or"100km". IfNULL, tries to guess the resolution from the provided coordinates.- short
 If
TRUE, generates short INSPIRE IDs. Defaults toFALSE.- llc
 Do the coordinates in
coordsrepresent the lower-left corners of their cells? IfFALSE, subtracts each coordinate by half ofres. IfTRUE, leaves them as-is. Defaults toFALSE, i.e., treat coordinates as cell centroids.- inspire
 A vector of INSPIRE IDs. Can be either short or long format.
- as
 Specifies the output class. Must be one of
"df"or"sf". If"df"(default), returns flat coordinates in a dataframe. If"sf"(and thesfpackage is installed), converts the coordinates to ansftibble.- meta
 Whether to include parsed CRS and resolution in the output. If
FALSE, output contains only coordinates. IfTRUE, also contains columns"crs"and"res".
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))[c("x", "y")], coords)
#> [1] TRUE
# Extract coordinates from short 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"), crs = 3035)
  z22_inspire_generate(coords)
}
#> [1] "CRS3035RES100mN2684000E4334100" "CRS3035RES100mN2684000E4334200"