Skip to contents

This function calculates and extracts the resolution (in metres) of a single pixel (centre) from a raster file. It determines the central pixel of the raster, crops to that single pixel, and returns its resolution in the specified CRS. Uses terra::rast(), terra::ext(), terra::crop(), and terra::project() to perform these operations.

Usage

ngr_spk_res(path, crs_out = "EPSG:3005")

Arguments

path

character A file path to the input raster.

crs_out

character The desired CRS (default is "EPSG:3005").

Value

numeric A vector of length two representing the resolution of the single pixel in metres in the specified CRS.

Details

The function first calculates the extent and resolution of the raster, identifies the central pixel, and crops the raster to that pixel. It then projects the cropped raster to the specified CRS and calculates the resolution of the single pixel.

Examples

path <- system.file("extdata", "test.tif", package = "ngr")
crs_out <- "EPSG:32609"
ngr_spk_res(path, crs_out)
#> Error: [rast] filename is empty. Provide a valid filename