pull_crs {tidyterra}R Documentation

Extract CRS on WKT format

Description

Extract the WKT version of the CRS associated to a string, number of sf/Spat* object.

The Well-known text (WKT) representation of coordinate reference systems (CRS) is a character string that identifies precisely the parameters of each CRS. This is the current standard used on sf and terra packages.

Usage

pull_crs(.data, ...)

Arguments

.data

Input potentially including or representing a CRS. It could be a sf/sfc object, a SpatRaster/SpatVector object, a crs object from sf::st_crs(), a character (for example a proj4 string) or a integer (representing an EPSG code).

...

ignored

Details

Although the WKT representation is the same, sf and terra API slightly differs. For example, sf can do:

sf::st_transform(x, 25830)

While sf equivalent is:

terra::project(bb, "epsg:25830")

Knowing the WKT would help to smooth workflows when working with different packages and object types.

Value

A WKT representation of the corresponding CRS.

Internals

This is a thin wrapper of sf::st_crs() and terra::crs().

See Also

terra::crs(), sf::st_crs() for knowing how these packages handle CRS definitions.

Other helpers: compare_spatrasters(), is_grouped_spatvector(), is_regular_grid()

Examples


# sf objects

sfobj <- sf::st_as_sfc("MULTIPOINT ((0 0), (1 1))", crs = 4326)

fromsf1 <- pull_crs(sfobj)
fromsf2 <- pull_crs(sf::st_crs(sfobj))

# terra

v <- terra::vect(sfobj)
r <- terra::rast(v)

fromterra1 <- pull_crs(v)
fromterra2 <- pull_crs(r)

# integers
fromint <- pull_crs(4326)

# Characters
fromchar <- pull_crs("epsg:4326")


all(
  fromsf1 == fromsf2,
  fromsf2 == fromterra1,
  fromterra1 == fromterra2,
  fromterra2 == fromint,
  fromint == fromchar
)

cat(fromsf1)

[Package tidyterra version 0.6.0 Index]