Title: | Irish Grid Reference Utilities |
---|---|
Description: | Convert between Irish grid references and Irish Grid coordinates. Irish grid references can also be converted to or from an 'sf' object in any coordinate reference system. Precisions from 1 m to 100 km including 2 km (tetrads) are supported, as are datasets with mixed precision. Conversion to 'sf' polygons is precision-aware. |
Authors: | John Kennedy [aut, cre, cph] |
Maintainer: | John Kennedy <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.0.9000 |
Built: | 2025-03-19 06:18:50 UTC |
Source: | https://github.com/digitalnature-ie/igr |
ig_to_igr()
converts valid Irish Grid (EPSG:29903) coordinates to Irish grid
references at the specified precision.
ig_to_igr(x, digits = 3, precision = NULL, sep = "")
ig_to_igr(x, digits = 3, precision = NULL, sep = "")
x |
A matrix containing Irish Grid X and Y coordinates in the first and second columns respectively. |
digits |
An integer, the number of digits for both easting and northing in the Irish grid references.
|
precision |
An integer, the precision of the Irish grid references in
metres: |
sep |
A character string to place between the 100 km grid letter, easting, northing, and tetrad. |
Either digits
or precision
must be specified. precision
overrides
digits
.
A character vector of Irish grid references.
# A matrix of Irish Grid coordinates m <- matrix(c(0, 412300, 0, 98700, 456000, 0), byrow = TRUE, ncol = 2) m # Convert to Irish grid references ig_to_igr(m) # Insert a space between the 100 km grid letter, easting, and northing ig_to_igr(m, sep = " ") # Convert into Irish grid references with 4 digit easting and northing (10 m precision) ig_to_igr(m, digits = 4) # Convert into Irish grid references with 1 km precision (2 digit easting and northing) ig_to_igr(m, precision = 1000) # Convert into Irish grid references with 2 km precision (tetrad form) ig_to_igr(m, precision = 2000)
# A matrix of Irish Grid coordinates m <- matrix(c(0, 412300, 0, 98700, 456000, 0), byrow = TRUE, ncol = 2) m # Convert to Irish grid references ig_to_igr(m) # Insert a space between the 100 km grid letter, easting, and northing ig_to_igr(m, sep = " ") # Convert into Irish grid references with 4 digit easting and northing (10 m precision) ig_to_igr(m, digits = 4) # Convert into Irish grid references with 1 km precision (2 digit easting and northing) ig_to_igr(m, precision = 1000) # Convert into Irish grid references with 2 km precision (tetrad form) ig_to_igr(m, precision = 2000)
igr_is_valid()
identifies valid Irish grid references.
igr_is_valid(x, tetrad = TRUE)
igr_is_valid(x, tetrad = TRUE)
x |
A character vector of Irish grid references. |
tetrad |
Permit tetrad form of Irish grid reference? |
Valid Irish grid references consist of a letter (other than I) optionally followed by both an easting and northing. The easting and northing must be of the same length of between 1 and 5 digits. There may be whitespace between the letter, easting and northing.
The tetrad form of Irish grid reference consists of a valid 10 km precision Irish grid reference (one letter, one digit easting and one digit northing) followed by a letter (other than O). This refers to a 2 km square within the 10 km square referenced.
A logical vector indicating the validity of each Irish grid reference.
# A vector of alternating valid and invalid Irish grid references v <- c("N8090", "D 12 345 88800", "W34", "I30", "W", "A123", "B1234", "", "A12Z", "A12O") # Check validity of Irish Grid coordinates igr_is_valid(v) # Check validity of Irish Grid coordinates, disallowing tetrad form igr_is_valid(v, tetrad = FALSE)
# A vector of alternating valid and invalid Irish grid references v <- c("N8090", "D 12 345 88800", "W34", "I30", "W", "A123", "B1234", "", "A12Z", "A12O") # Check validity of Irish Grid coordinates igr_is_valid(v) # Check validity of Irish Grid coordinates, disallowing tetrad form igr_is_valid(v, tetrad = FALSE)
igr_to_ig()
converts Irish grid references into a list of Irish Grid
(EPSG:29903) X and Y coordinates. By default the coordinates of the south
west corners of each Irish grid reference are calculated. The precision of each
Irish grid reference in metres can be returned.
igr_to_ig( x, coords = c("x", "y"), centroids = FALSE, precision = NULL, tetrad = TRUE )
igr_to_ig( x, coords = c("x", "y"), centroids = FALSE, precision = NULL, tetrad = TRUE )
x |
A character vector of Irish grid references. See |
coords |
A character vector of the names of the columns to contain the Irish Grid X and Y coordinates respectively. |
centroids |
Should the coordinates of the centroids of the Irish grid references be returned (rather than the south west corners)? |
precision |
The name of the column to contain the precision of each Irish grid reference in metres, if required. |
tetrad |
Permit tetrad form of Irish grid reference? |
A list containing Irish Grid X and Y coordinates and, optionally, the precision in metres of each Irish grid reference. Invalid or missing Irish grid references return NA.
# A vector of Irish grid references of different precisions v <- c("N8090", "D1234588800", "W34", "", "D12T") # Convert south west corners of Irish grid references to Irish Grid coordinates igr_to_ig(v) # Convert centroids of Irish grid references to Irish Grid coordinates igr_to_ig(v, centroids = TRUE) # Specify column names igr_to_ig(v, coords = c("e", "n")) # Also return the precision in metres of each Irish grid reference igr_to_ig(v, precision = "prec")
# A vector of Irish grid references of different precisions v <- c("N8090", "D1234588800", "W34", "", "D12T") # Convert south west corners of Irish grid references to Irish Grid coordinates igr_to_ig(v) # Convert centroids of Irish grid references to Irish Grid coordinates igr_to_ig(v, centroids = TRUE) # Specify column names igr_to_ig(v, coords = c("e", "n")) # Also return the precision in metres of each Irish grid reference igr_to_ig(v, precision = "prec")
st_igr_as_sf()
converts a data frame containing Irish grid references into
an sf object containing point or polygon features. If points, the south west
corners of the grid references are returned. If polygons, squares spanning
the full extent of each grid reference are returned, with each square's size
depending on the precision of each grid reference. The Irish Grid
(EPSG:29903) X and Y coordinates and grid reference precision in metres can
also be returned.
st_igr_as_sf( x, igrefs = "igr", crs = 29903, remove = FALSE, add_coords = FALSE, coords = c("x", "y"), centroids = FALSE, precision = NULL, polygons = FALSE, tetrad = TRUE )
st_igr_as_sf( x, igrefs = "igr", crs = 29903, remove = FALSE, add_coords = FALSE, coords = c("x", "y"), centroids = FALSE, precision = NULL, polygons = FALSE, tetrad = TRUE )
x |
A data.frame containing a column of valid Irish grid references. It
must not have column names specified in |
igrefs |
The name or index of the character column holding Irish grid references. |
crs |
A valid EPSG value (numeric), a string accepted by GDAL, or an
object of class crs containing the coordinate reference system to be
assigned. See |
remove |
Should the column containing the Irish grid references be removed from the result? |
add_coords |
Should the Irish Grid coordinates with column names
specified by |
coords |
A character vector of the names of the columns to contain the Irish Grid X and Y coordinates respectively. |
centroids |
Should the coordinates of the centroids of the Irish grid references be returned (rather than the south west corners)? |
precision |
The name of the column to contain the precision of each Irish grid reference in metres, if required. |
polygons |
If |
tetrad |
Permit tetrad form of Irish grid reference? |
An sf object containing point or polygon features for each Irish grid reference in x.
# A data.frame containing Irish grid references x <- data.frame(igr = c("A00", "N8000", "D12T")) # Convert a data.frame of Irish grid references to an sf object in the # Irish Grid coordinate reference system st_igr_as_sf(x, "igr") # Convert to an sf object in the WGS 84 coordinate reference system st_igr_as_sf(x, "igr", crs = 4326) # Include the Irish Grid coordinates and precision in the sf object st_igr_as_sf(x, "igr", add_coords = TRUE, precision = "prec") # Convert into polygon features rather than point features st_igr_as_sf(x, "igr", polygons = TRUE)
# A data.frame containing Irish grid references x <- data.frame(igr = c("A00", "N8000", "D12T")) # Convert a data.frame of Irish grid references to an sf object in the # Irish Grid coordinate reference system st_igr_as_sf(x, "igr") # Convert to an sf object in the WGS 84 coordinate reference system st_igr_as_sf(x, "igr", crs = 4326) # Include the Irish Grid coordinates and precision in the sf object st_igr_as_sf(x, "igr", add_coords = TRUE, precision = "prec") # Convert into polygon features rather than point features st_igr_as_sf(x, "igr", polygons = TRUE)
st_irishgridrefs()
returns the Irish grid references for all features in an
sf object of point geometries. Features located outside the Irish Grid
(EPSG:29903) extent are returned as NA.
st_irishgridrefs(x, digits = 3, precision = NULL, sep = "")
st_irishgridrefs(x, digits = 3, precision = NULL, sep = "")
x |
An sf object containing geometries of type POINT. |
digits |
An integer, the number of digits for both easting and northing in the Irish grid references.
|
precision |
An integer, the precision of the Irish grid references in
metres: |
sep |
A character string to place between the 100 km grid letter, easting, northing, and tetrad. |
A character vector of Irish grid references.
# An sf object containing point data x_sf <- sf::st_as_sf(data.frame(x = c(0, 490000), y = c(400000, 0)), crs = 29903, coords = c("x", "y") ) # Convert to Irish grid references st_irishgridrefs(x_sf) # Convert into Irish grid references with 4 digit easting and northing (10 m precision) st_irishgridrefs(x_sf, digits = 4) # Convert into Irish grid references with 1 km precision (2 digit easting and northing) st_irishgridrefs(x_sf, precision = 1000) # Convert into Irish grid references with 2 km precision (tetrad form) st_irishgridrefs(x_sf, precision = 2000) # Insert a space between the 100 km grid letter, easting, and northing st_irishgridrefs(x_sf, sep = " ")
# An sf object containing point data x_sf <- sf::st_as_sf(data.frame(x = c(0, 490000), y = c(400000, 0)), crs = 29903, coords = c("x", "y") ) # Convert to Irish grid references st_irishgridrefs(x_sf) # Convert into Irish grid references with 4 digit easting and northing (10 m precision) st_irishgridrefs(x_sf, digits = 4) # Convert into Irish grid references with 1 km precision (2 digit easting and northing) st_irishgridrefs(x_sf, precision = 1000) # Convert into Irish grid references with 2 km precision (tetrad form) st_irishgridrefs(x_sf, precision = 2000) # Insert a space between the 100 km grid letter, easting, and northing st_irishgridrefs(x_sf, sep = " ")