inspire | R Documentation |
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.
z22_inspire_generate(coords, res = NULL, legacy = FALSE)
z22_inspire_extract(inspire, as_sf = FALSE)
coords |
A list, matrix, or dataframe where the X and Y coordinates are
either in the columns Can also be a |
res |
Resolution of the grid. Can be |
legacy |
If |
inspire |
A vector of INSPIRE IDs. Can be either legacy or non-legacy. |
as_sf |
Whether to return an object of class |
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.
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.
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)
# Extract coordinates from legacy ID strings
z22_inspire_extract("100mN34000E44000")
# 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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.