ck_read() is ck_warp() that hands back pixels instead of writing a file:
it streams only the tiles the request touches, warps them with GDAL (the same
engine, sanitiser and defaults as ck_warp()), and returns the result as a
base-R matrix or array. Use it for quick extraction and inspection without
round-tripping through a file on disk.
Usage
ck_read(
src,
t_srs = NULL,
te = NULL,
te_srs = NULL,
tr = NULL,
ts = NULL,
tap = TRUE,
r = c("near", "bilinear", "cubic", "cubicspline", "lanczos", "average", "rms", "mode",
"max", "min", "med", "q1", "q3", "sum"),
bands = NULL,
cl_arg = character(0),
num_threads = "ALL_CPUS",
warp_memory = "auto",
cache_max = "auto",
config = NULL,
skip_nosource = TRUE,
overview = NULL,
margin = 8L,
io_concurrency = 16L,
max_bytes = NULL,
sanitise = TRUE
)Arguments
- src
Path/URL to a source GeoTIFF / COG, a
cog_source()handle, or a character vector of several sources to mosaic (each tile's overlapping window is fetched and the set is reprojected/mosaicked in one warp; non-overlapping tiles are skipped). Passing acog_source()reuses its already-open handle, skipping the metadata re-read – worthwhile when warping many AOIs from the same source.- t_srs
Target SRS (e.g.
"EPSG:3857"). IfNULL, the source CRS is used (no reprojection).- te
Target extent
c(xmin, ymin, xmax, ymax), inte_srsif given, otherwise int_srs. When supplied this is the AOI that drives the fetch.- te_srs
SRS of
te(defaults tot_srs).- tr
Target resolution
c(xres, yres)in target CRS units. Takes precedence overts: if both are given,tsis ignored (with a warning).- ts
Target size
c(width, height)in pixels. Ignored iftris also supplied.- tap
If
TRUE(default) andtris given, align output pixel boundaries to thetrgrid (gdalwarp-tap), anchored at the CRS origin, so outputs at the same resolution share a grid and stack cleanly. This snaps the output extent outward, so it is no longer exactlyte. No effect withtsor on the copy path. An explicit-tapincl_argis always honoured. (warp_remote()never adds this; pass-tapyourself.)- r
Resampling method, one of
"near"(default),"bilinear","cubic","cubicspline","lanczos","average","rms","mode","max","min","med","q1","q3","sum". Matched withrlang::arg_match(), so a typo reports the valid set. (A method added by a newer GDAL than this list knows can still be passed viacl_arg.)- bands
1-based source bands to read (default: all). Subsetting happens during the fetch, so only those bands' bytes are streamed.
- cl_arg
Character vector of extra raw
gdalwarpflags, forwarded verbatim togdalraster::warp()(e.g.c("-et", "0")). These are merged with the flags cptkirk builds from the named arguments above.- num_threads
Value for GDAL's warp
NUM_THREADSwarp option and theGDAL_NUM_THREADSconfig (default"ALL_CPUS"), parallelising the resampling computation and GeoTIFF (de)compression.NULLsets neither, deferring to the ambientGDAL_NUM_THREADS(env / session).- warp_memory
Warp working memory in MB (GDAL
-wm)."auto"(default) uses ~25% of system RAM, clamped to 256-2048 MB (bigger means fewer, larger chunks);NULLdefers to GDAL's own default; a number sets it explicitly.- cache_max
GDAL block cache in MB for this call.
"auto"(default) uses ~25% of RAM, clamped to 256-2000 MB;NULLdefers to the ambientGDAL_CACHEMAX(env /gdalraster::set_config_option()); a number sets it explicitly. Any value is restored to the previous setting afterwards.- config
Named character vector / list of extra GDAL config options to set for the duration of the call (restored on exit).
- skip_nosource
If
TRUE(default), passSKIP_NOSOURCE=YES+INIT_DESTso the warper skips output chunks with no source coverage (e.g. nodata margins from reprojection). No effect when output is fully covered. Ignored on the copy fast-path.- overview
Force a 1-based IFD/overview level instead of auto-selecting from the output resolution.
1= full resolution.- margin
Source-pixel margin added around the computed window to cover the resampling kernel and reprojection slop (default 8).
- io_concurrency
Number of concurrent tile reads – the width of the single global fetch pool shared across all source tiles. Default 16, which suits object stores that throttle around that many simultaneous range requests (e.g. S3 / source.coop). Raise (24-32) on a fast, stable link; lower if a store rate-limits.
- max_bytes
Safety ceiling (bytes) on the returned array, sized as
nrow * ncol * nbands * 8(R stores numerics as f64).NULL(default) uses ~1/3 of system RAM. Coarsentr/ts, narrowte, select fewerbands, or raise this to read a larger window.- sanitise
If
TRUE(default), validate the warp arguments against a tiny metadata-derived stand-in before fetching, so a bad CRS, resampling method, creation option or unknown flag fails in milliseconds instead of after a remote read. SetFALSEto skip the check.
Value
A numeric matrix (single band) or array with dimensions
[nrow, ncol, nband] (multi-band), carrying geotransform, crs and
(when set) nodata attributes so it is self-describing and convertible to
other raster classes. The R type follows the output data type (integer or
double).
Details
Two internal paths, chosen automatically:
Warp (the usual case – a reprojection / resolution change is requested): the result is materialised in an uncompressed
/vsimemGeoTIFF and read back withgdalraster.Native window (no
t_srs/tr/ts, single source): the fetched native bytes are decoded straight to an R array, with no GDAL round-trip at all.
See also
ck_warp() to write a warped file instead.
