Skip to contents

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)

Arguments

points

An sf object (any geometry, but typically points).

raster

A SpatRaster whose CRS is the target CRS. Defaults to the ABMI 1 km Alberta grid, ab_grid(), whose CRS is ab_crs().

warn

Logical; if TRUE (default), report when reprojection is performed.

Value

An sf object with the same features as points but projected to the CRS of raster.

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)
} # }