vapour_read_raster {vapour} | R Documentation |
Raster IO (read)
Description
Read a window of data from a GDAL raster source. The first argument is the source
name and the second is a 6-element window
of offset, source dimension, and output dimension.
Usage
vapour_read_raster(
x,
band = 1,
window,
resample = "nearestneighbour",
...,
sds = NULL,
native = FALSE,
set_na = TRUE,
band_output_type = "",
unscale = TRUE,
nara = FALSE
)
Arguments
x |
data source |
band |
index of which band to read (1-based) |
window |
src_offset, src_dim, out_dim |
resample |
resampling method used (see details) |
... |
reserved |
sds |
index of subdataset to read (usually 1) |
native |
apply the full native window for read, |
set_na |
specify whether NA values should be set for the NODATA |
band_output_type |
numeric type of band to apply (else the native type if ”), is mapped to one of 'Byte', 'Int32', or 'Float64' |
unscale |
default is |
nara |
logical whether to return a (scaled) nativeRaster |
Details
The value of window
may be input as only 4 elements, in which case the source dimension
Will be used as the output dimension.
This is analogous to the rgdal
function readGDAL
with its arguments offset
, region.dim
and output.dim
. There's no semantic wrapper for this in vapour, but see
https://github.com/hypertidy/lazyraster
for one approach.
Resampling options will depend on GDAL version, but currently 'NearestNeighbour' (default), 'Average', 'Bilinear', 'Cubic', 'CubicSpline', 'Gauss', 'Lanczos', 'Mode' are potentially available. These are compared internally by converting to lower-case. Detailed use of this is barely tried or tested with vapour, but is a standard facility used in GDAL. Easiest way to compare results is with gdal_translate.
There is no write support in vapour.
Currently the window
argument is required. If this argument unspecified and native = TRUE
then
the default window specification will be used, the entire extent at native resolution. If 'window'
is specified and native = TRUE
then the window is used as-is, with a warning (native is ignored).
'band_output_type' can be 'raw', 'integer', 'double', or case-insensitive versions of the GDAL types 'Byte', 'UInt16', 'Int16', 'UInt32', 'Int32', 'Float32', or 'Float64'. These are mapped to one of the supported types 'Byte' ('== raw'), 'Int32' ('== integer'), or 'Float64' ('== double').
Value
list of numeric vectors (only one for 'band')
Examples
f <- system.file("extdata", "sst.tif", package = "vapour")
## a 5*5 window from a 10*10 region
vapour_read_raster(f, window = c(0, 0, 10, 10, 5, 5))
vapour_read_raster(f, window = c(0, 0, 10, 10, 5, 5), resample = "Lanczos")
## find the information first
ri <- vapour_raster_info(f)
str(matrix(vapour_read_raster(f, window = c(0, 0, ri$dimXY, ri$dimXY)), ri$dimXY[1]))
## the method can be used to up-sample as well
str(matrix(vapour_read_raster(f, window = c(0, 0, 10, 10, 15, 25)), 15))