Learn R Programming

tidyterra (version 1.3.0)

as_coordinates: Get cell number, row and column from a SpatRaster

Description

as_coordinates() returns the position of each cell in the SpatRaster matrix.

Usage

as_coordinates(x, as.raster = FALSE)

Value

A tibble or a SpatRaster (if as.raster = TRUE) with one row (or cell) for each cell in x.

When as.raster = TRUE, the resulting SpatRaster has the same CRS, extent and resolution as x.

Arguments

x

A SpatRaster object.

as.raster

If TRUE, the result is a SpatRaster object with three layers indicating the position of each cell (cell number, row and column).

See Also

slice.SpatRaster().

Coercing objects: as_sf(), as_spatraster(), as_spatvector(), as_tibble.Spat, fortify.Spat, tidy.Spat

Examples

Run this code

library(terra)

f <- system.file("extdata/cyl_temp.tif", package = "tidyterra")

r <- rast(f)

as_coordinates(r)
as_coordinates(r, as.raster = TRUE)

as_coordinates(r, as.raster = TRUE) |> plot()

Run the code above in your browser using DataLab