This function will split a Raster* object into smaller chunks. The size of these chunks (number of cells)
is controlled by partPerSide
, h
or v
. Additionally, it allows to replace cell values (valToReplace
)
within Raster* object by another value of user's choice (replacedBy
). When save = TRUE
,
the resulting cellsToProcess
Raster* objects are saved in directory outputPath
.
split_replace(
raster,
partPerSide,
h,
v,
outputPath,
name,
save = TRUE,
replace = FALSE,
valToReplace,
replacedBy,
dataType,
format = "GTiff",
parallelProcessing = FALSE,
numCores = 20,
cellsToProcess,
...
)
At outputPath
the user will find length(cellsToProcess)
Raster* files
Raster* object.
integer indicating number of cells in which raster
will be split
in each direction (horizontally and vertically). Use when nrow(raster)
and
ncol(raster)
are multiples of partPerSide
.
integer indicating number of horizontal cells in which raster
will be split.
integer indicating number of vertical cells in which raster
will be split.
character with full path name where the resulting Raster* objects will be saved.
character with the name to assign to final products.
logical, should the output be saved, default is TRUE
.
logical, default FALSE
, when TRUE
, valToReplace
and replacedBy
must by specified.
indicates a value to be replaced across raster
cells.
indicates the value by which valToReplace
is replaced.
character, output data type. See dataType
.
character, output file type, default "GTiff"
. See writeFormats
.
logical, default FALSE
, when TRUE
raster splitting is done in parallel. See
Details.
numeric indicating the number of cores used in parallel processing.
numeric vector indicating which smaller cells should be processed/saved. See Details.
additional arguments used by writeRaster
.
Before processing any of the cellsToProcess
the temporary raster
directory is re-directed. Basically, prior to process the i-th cell,
at outputPath
a new subdirectory is created, which, in turn, is erased
automatically once the i-th cell has been processed. As a result of several tests
we found that this measure avoids memory overflow.
When partPerSide
is used, cellsToProcess = 1:(partPerSide^2)
. When h
and v
are used, cellsToProcess = 1:(ncells(raster)/(h*v))
. Since the code
assumes that nrow(raster)
and ncol(raster)
are multiples of partPerSide
or h
and v
, respectively, the user must be careful when selecting these
parameters.
For parallelProcessing
the backend doParallel
is employed.