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.
vapour_read_raster(
x,
band = 1,
window,
resample = "nearestneighbour",
...,
sds = NULL,
native = FALSE,
set_na = TRUE,
band_output_type = "",
unscale = TRUE
)
data source
index of which band to read (1-based)
src_offset, src_dim, out_dim
resampling method used (see details)
reserved
index of subdataset to read (usually 1)
apply the full native window for read, FALSE
by default
specify whether NA values should be set for the NODATA
numeric type of band to apply (else the native type if ''), is mapped to one of 'Byte', 'Int32', or 'Float64'
default is TRUE
so native values will be converted by offset and scale to floating point
list of numeric vectors (only one for 'band')
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').
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))
#> $Band1
#> [1] 285.743 285.786 285.999 286.064 286.038 285.763 285.698 285.831 286.265
#> [10] 286.134 286.070 285.931 286.092 286.450 286.501 286.264 286.076 285.915
#> [19] 286.335 286.702 285.870 285.940 286.252 286.549 287.142
#>
vapour_read_raster(f, window = c(0, 0, 10, 10, 5, 5), resample = "Lanczos")
#> $Band1
#> [1] 285.7112 285.7088 285.9000 286.0153 285.9586 285.7220 285.7106 285.7733
#> [9] 286.1091 286.2422 286.0036 285.8829 285.9075 286.3403 286.4126 286.2443
#> [17] 286.1346 285.9894 286.3176 286.6353 286.0227 285.9557 286.0615 286.3574
#> [25] 286.8593
#>
## 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]))
#> List of 143
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> $ : num [1:40898] 286 286 286 286 286 ...
#> [list output truncated]
#> - attr(*, "dim")= int [1:2] 143 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))
#> List of 15
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> $ : num [1:375] 286 286 286 286 286 ...
#> - attr(*, "dim")= int [1:2] 15 1