R/spatial_helpers.R
prep_agg_lonlat_raster.RdExtends a template raster to a target extent, reprojects it to a geographic (lon/lat, EPSG:4326) coordinate reference system, and aggregates it to an approximate target resolution. This is used to prepare a coarse point grid for climate-data retrieval (e.g. BioSIM, ERA5).
prep_agg_lonlat_raster(ext, rtm, agg_to = 1000)A SpatExtent (or object coercible to one by terra::extend())
giving the target extent.
A SpatRaster template ("raster to match") supplying the source
resolution and CRS.
Numeric. Target resolution (in the units of rtm) used to
compute the aggregation factor relative to terra::res(rtm). Defaults to
1000.
A SpatRaster extended, reprojected to EPSG:4326, and aggregated.
Other spatial helpers:
calc_centroid(),
create_bbox(),
extract_coords(),
save_gpkg(),
spatial_join_intersects()
r <- terra::rast(
xmin = 0, xmax = 100, ymin = 0, ymax = 100,
resolution = 10, crs = "epsg:3005"
)
terra::values(r) <- seq_len(terra::ncell(r))
prep_agg_lonlat_raster(terra::ext(r), r, agg_to = 50)
#> class : SpatRaster
#> size : 2, 3, 1 (nrow, ncol, nlyr)
#> resolution : 0.0005704349, 0.0005704349 (x, y)
#> extent : -138.4461, -138.4444, 44.19935, 44.20049 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> name : lyr.1
#> min value : NaN
#> max value : NaN