Skip to contents

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.

Usage

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
)

Arguments

x

A data.frame containing a column of valid Irish grid references. It must not have column names specified in coords.

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 sf::st_crs().

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 be included in the result?

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 FALSE (the default) the result will contain point features located at the south-west corner of each Irish grid reference. If TRUE the result will contain polygon features spanning the extent of each Irish grid reference.

tetrad

Permit tetrad form of Irish grid reference?

Value

An sf object containing point or polygon features for each Irish grid reference in x.

Examples

# 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")
#> Simple feature collection with 3 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 0 ymin: 2e+05 xmax: 316000 ymax: 426000
#> Projected CRS: TM75 / Irish Grid
#>     igr              geometry
#> 1   A00       POINT (0 4e+05)
#> 2 N8000  POINT (280000 2e+05)
#> 3  D12T POINT (316000 426000)

# Convert to an sf object in the WGS 84 coordinate reference system
st_igr_as_sf(x, "igr", crs = 4326)
#> Simple feature collection with 3 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -11.1116 ymin: 53.04498 xmax: -6.184984 ymax: 55.06779
#> Geodetic CRS:  WGS 84
#>     igr                   geometry
#> 1   A00  POINT (-11.1116 54.80789)
#> 2 N8000 POINT (-6.807924 53.04498)
#> 3  D12T POINT (-6.184984 55.06779)

# Include the Irish Grid coordinates and precision in the sf object
st_igr_as_sf(x, "igr", add_coords = TRUE, precision = "prec")
#> Simple feature collection with 3 features and 4 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 0 ymin: 2e+05 xmax: 316000 ymax: 426000
#> Projected CRS: TM75 / Irish Grid
#>     igr      x      y  prec              geometry
#> 1   A00      0 400000 10000       POINT (0 4e+05)
#> 2 N8000 280000 200000  1000  POINT (280000 2e+05)
#> 3  D12T 316000 426000  2000 POINT (316000 426000)

# Convert into polygon features rather than point features
st_igr_as_sf(x, "igr", polygons = TRUE)
#> Simple feature collection with 3 features and 1 field
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 0 ymin: 2e+05 xmax: 318000 ymax: 428000
#> Projected CRS: TM75 / Irish Grid
#>     igr                       geometry
#> 1   A00 POLYGON ((10000 410000, 100...
#> 2 N8000 POLYGON ((281000 201000, 28...
#> 3  D12T POLYGON ((318000 428000, 31...