crds: Coordinates of a vector"s features or a raster"s cell centers

crds,GRaster-methodR Documentation

Coordinates of a vector"s features or a raster"s cell centers

Description

Returns the coordinates of the center of cells of a GRaster or coordinates of a GVector's vertices. The output will be a matrix, data.frame, or list. If you want the output to be a "points" GVector, use as.points().

Usage

## S4 method for signature 'GRaster'
crds(x, z = is.3d(x), na.rm = TRUE)

## S4 method for signature 'GVector'
crds(x, z = is.3d(x))

st_coordinates(x)

Arguments

x

A GVector or a GRaster.

z

If TRUE (default), return x-, y-, and z-coordinates. If FALSE, just return x- and y-coordinates. For 2-dimensional objects, z-coordinates will all be 0.

na.rm

Logical: If TRUE, remove cells that are NA (GRasters only).

Value

A matrix, data.frame, or list.

See Also

terra::crds()

Examples

if (grassStarted()) {

# Setup
library(terra)

# Plant specimens (points), elevation (raster)
madDypsis <- fastData("madDypsis")
madElev <- fastData("madElev")

# Convert a SpatRaster to a GRaster, and sf to a GVector
dypsis <- fast(madDypsis)
elev <- fast(madElev)

### Get coordinates:
dypsisPoints <- crds(dypsis)
elevPoints <- crds(elev)

head(dypsisPoints)
head(elevPoints)

}

adamlilith/fasterRaster documentation built on Dec. 21, 2024, 2:04 a.m.