split_replace: Splits a Raster* object into smaller chunks and allows to...

View source: R/split_replace.R

split_replaceR Documentation

Splits a Raster* object into smaller chunks and allows to replace cell values

Description

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.

Usage

split_replace(
  raster,
  partPerSide,
  h,
  v,
  outputPath,
  name,
  save = TRUE,
  replace = FALSE,
  valToReplace,
  replacedBy,
  dataType,
  format = "GTiff",
  parallelProcessing = FALSE,
  numCores = 20,
  cellsToProcess,
  ...
)

Arguments

raster

Raster* object.

partPerSide

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.

h

integer indicating number of horizontal cells in which raster will be split.

v

integer indicating number of vertical cells in which raster will be split.

outputPath

character with full path name where the resulting Raster* objects will be saved.

name

character with the name to assign to final products.

save

logical, should the output be saved, default is TRUE.

replace

logical, default FALSE, when TRUE, valToReplace and replacedBy must by specified.

valToReplace

indicates a value to be replaced across raster cells.

replacedBy

indicates the value by which valToReplace is replaced.

dataType

character, output data type. See dataType.

format

character, output file type, default "GTiff". See writeFormats.

parallelProcessing

logical, default FALSE, when TRUE raster splitting is done in parallel. See Details.

numCores

numeric indicating the number of cores used in parallel processing.

cellsToProcess

numeric vector indicating which smaller cells should be processed/saved. See Details.

...

additional arguments used by writeRaster.

Details

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.

Value

At outputPath the user will find length(cellsToProcess) Raster* files

See Also

writeRaster, aggregate, rasterOptions


geoTS documentation built on Nov. 18, 2022, 1:08 a.m.