Title: | Native Raster Files |
---|---|
Description: | Provides a loose couplings between the facilities of `raster` and `ff`, to allow a file-backed raster grid to be modified as if it were an array in memory. |
Authors: | Michael D. Sumner [aut, cre] |
Maintainer: | Michael D. Sumner <[email protected]> |
License: | GPL-3 |
Version: | 0.0.1.9001 |
Built: | 2024-11-21 05:21:59 UTC |
Source: | https://github.com/hypertidy/ffraster |
The dimension order as used by ff and raster native grid, see 'raster::writeRaster'. The raster package uses the named conventions "BSQ", "BIL" and "BIP" which are domain-specialized ways to record the dimension order of (virtual) 3D arrays. They stand for "band sequential" "band interleaved" and ... correspond to c(1, 2, 3) etc. etc.
dim_order(x, ...) ## S3 method for class 'BasicRaster' dim_order(x, ...) ## S3 method for class 'character' dim_order(x, ...)
dim_order(x, ...) ## S3 method for class 'BasicRaster' dim_order(x, ...) ## S3 method for class 'character' dim_order(x, ...)
x |
filename or raster object or ff object |
... |
ignored |
This function always returns an integer vector indicating the order of the dims of a 'length(dim_order(x))' array oriented relative to the R array convention.
integer vector of dimension positions (1-based)
r <- raster::raster(volcano) dim_order(r) w <- raster::writeRaster(r, raster::rasterTmpFile(), bandorder = "BIP") dim_order(w) dim_order(raster::filename(w))
r <- raster::raster(volcano) dim_order(r) w <- raster::writeRaster(r, raster::rasterTmpFile(), bandorder = "BIP") dim_order(w) dim_order(raster::filename(w))
Create an file-backed 'ff' object from a raster, or a raster-enabled file.
ff_object(x, readonly = TRUE, filename = NULL, ...) ## S3 method for class 'BasicRaster' ff_object(x, readonly = TRUE, filename = NULL, ...) ## S3 method for class 'character' ff_object(x, readonly = TRUE, filename = NULL, ...)
ff_object(x, readonly = TRUE, filename = NULL, ...) ## S3 method for class 'BasicRaster' ff_object(x, readonly = TRUE, filename = NULL, ...) ## S3 method for class 'character' ff_object(x, readonly = TRUE, filename = NULL, ...)
x |
raster or raster-able file |
readonly |
open in read-only mode (TRUE by default) |
filename |
path to file to create |
... |
arguments to methods |
When the object is created from a filename, ‘raster::brick' is used. The ’dim'ension for raster and for ff in this context always keeps degenerate singletons. Please get in touch if this causes you problems.
'ff' object
f <- system.file("extdata", "raster", "sst.grd", package = "ffraster") ff_object(raster::brick(f)) if (interactive()) { arr <- ff_object(f, filename = "afile.grd") }
f <- system.file("extdata", "raster", "sst.grd", package = "ffraster") ff_object(raster::brick(f)) if (interactive()) { arr <- ff_object(f, filename = "afile.grd") }
Use a raster template to set up an ff array for filling.
ff_raster(x, nlayers = NULL, filename = NULL, ..., setZ = NULL)
ff_raster(x, nlayers = NULL, filename = NULL, ..., setZ = NULL)
x |
a raster object, used as the template for the data to come |
nlayers |
the number of layers to instantiate |
filename |
the .grd filename |
... |
arguments passed to .writeGRD |
setZ |
optional z values, must be of length 'nlayers' |
Note that no data is transferred, this is a set up function to give an ff array to be populated.
There is currently no control over the bandorder, set to band interleaved (BIL) currently.
## Not run: n <- 5 files <- raadtools::sstfiles()[1:n, ] library(raster) fun <- function(date) raadtools::readsst(date, xylim = extent(120, 160, -50, -30), inputfiles = files) arr <- ff_raster(fun(files$date[1]), nlayers = n, filename = "afile.grd", overwrite = TRUE) for (i in seq_along(files$date)) { arr[,,i] <- raster::values(t(fun(files$date[i]))) } # plot(brick("afile.grd")) ## End(Not run)
## Not run: n <- 5 files <- raadtools::sstfiles()[1:n, ] library(raster) fun <- function(date) raadtools::readsst(date, xylim = extent(120, 160, -50, -30), inputfiles = files) arr <- ff_raster(fun(files$date[1]), nlayers = n, filename = "afile.grd", overwrite = TRUE) for (i in seq_along(files$date)) { arr[,,i] <- raster::values(t(fun(files$date[i]))) } # plot(brick("afile.grd")) ## End(Not run)
ff type from raster type
ff_type(x, ...) ## S3 method for class 'character' ff_type(x, ...) ## S3 method for class 'BasicRaster' ff_type(x, ...) ## S3 method for class 'raster_ini' ff_type(x, ...)
ff_type(x, ...) ## S3 method for class 'character' ff_type(x, ...) ## S3 method for class 'BasicRaster' ff_type(x, ...) ## S3 method for class 'raster_ini' ff_type(x, ...)
x |
filename, raster object, or ini object |
... |
ignored |
type of ff, see 'ff::vmode'
ff_type("LOG1S")
ff_type("LOG1S")
Build a ff array to be used as a raster.
For mapping between raster and ff types, see vmode
and dataType
ffrarr(dim, mode, filename, readonly = TRUE)
ffrarr(dim, mode, filename, readonly = TRUE)
dim |
dimensions in Raster order (nrow, ncol, nlayer) |
mode |
ff data mode see details |
filename |
file name as per |
readonly |
open in readonly mode (TRUE is default) |
ff
mat <- volcano library(raster) b <- brick(raster(mat), raster(mat), raster(mat)) fn <- rasterTmpFile() dt <- "byte" ffraster:::.writeGRD(b, dataType = dt, filename = fn) a <- ffrarr(dim(b), mode = dt, filename = fn, readonly = FALSE)
mat <- volcano library(raster) b <- brick(raster(mat), raster(mat), raster(mat)) fn <- rasterTmpFile() dt <- "byte" ffraster:::.writeGRD(b, dataType = dt, filename = fn) a <- ffrarr(dim(b), mode = dt, filename = fn, readonly = FALSE)
Read the configuration file in raw list form, you can use either the filename (.grd) or a raster object.
ini_file(x) ## S3 method for class 'character' ini_file(x) ## S3 method for class 'BasicRaster' ini_file(x)
ini_file(x) ## S3 method for class 'character' ini_file(x) ## S3 method for class 'BasicRaster' ini_file(x)
x |
file name or raster |
f <- system.file("extdata", "raster", "sst.grd", package = "ffraster") ini_file(f)
f <- system.file("extdata", "raster", "sst.grd", package = "ffraster") ini_file(f)