vapour (version 0.5.5)

vapour_read_raster: 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
)

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, FALSE by default

set_na

specify whether NA values should be set for the NODATA

Value

list of numeric vectors (only one for 'band')

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).

Examples

Run this code
# NOT RUN {
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))

# }

Run the code above in your browser using DataCamp Workspace