Reprojects an sf point layer to match the CRS of a reference
SpatRaster. The raster is never modified.
Usage
harmonize_crs(points, raster = ab_grid(), warn = TRUE)Details
When raster is left at its default — the package reference grid
— reprojection is the intended outcome and is reported as a
message. When the caller supplies a raster, a differing CRS may
be unintended, so a warning is issued instead: reprojecting the
raster is the alternative approach, though it is typically
costlier and introduces resampling artefacts.
Examples
if (FALSE) { # \dontrun{
library(terra)
library(sf)
ref <- rast(nrows = 10, ncols = 10, crs = "EPSG:3400")
pts <- st_as_sf(
data.frame(x = c(-114, -113), y = c(53, 54)),
coords = c("x", "y"),
crs = 4326
)
pts_proj <- harmonize_crs(pts, ref)
# Onto the default ABMI 1 km Alberta grid (EPSG:3400)
pts_ab <- harmonize_crs(pts)
} # }