raster (version 1.0.4)

aggregate: Aggregate

Description

Aggregate a RasterLayer to create a new RasterLayer with a lower resolution (larger cells). Aggregation groups rectangular areas of RasterLayer cells to create a new RasterLayer with larger cells. A new value is computed for the resulting cells according to a specified function (default value = mean).

Usage

aggregate(x, ...)

Arguments

x
A RasterLayer object
...
Additional arguments. See below, under Methods

Value

  • A new RasterLayer object, and in some cases the side effect of a new file on disk.

Details

A full call to the aggregate method for a RasterLayer is: aggregate(x, fact=2, fun=mean, expand=TRUE, na.rm=TRUE, filename="", ... ) rll{ x a RasterLayer object fact Integer. Aggregation factor expressed as number of cells in each direction (horizontally and vertically). Or two integers (horizontal and vertial aggregation factor). Default is 2. See below fun Function used to aggregate values (default=mean) expand logical. If TRUE the output RasterLayer will be larger then the input RasterLayer if a division of the number of columns or rows with factor is not an integer na.rm logical. If TRUE, NA cells are removed from calculations filename Character. Output filename ... Additional arguments, see below } Additional arguments: rll{ format Character. Output file type. See writeRaster datatype Character. Output data type. See dataType overwrite Logical. If TRUE, the file will be overwritten if it exists progress Character. Valid values are "text", "tcltk", "windows" (on that platform only) and "" } Aggregation will result in a RasterLayer with fact*fact fewer cells; if necessary this number is adjusted according to the value of expand. For example, fact=2 will result in a new RasterLayer with 2*2=4 times fewer cells. If two numbers are supplied, e.g., fact=c(2,3), the first will be used for aggregating in the horizontal direction, and the second for aggregating in the vertical direction, and the new RasterLayer will have 2*3=6 times fewer cells. Aggregation starts at the upper-left end of a raster. If a division of the number of columns or rows with factor does not return an integer, the extent of the resulting RasterLayer will either be somewhat smaller or somewhat larger then the original RasterLayer. For example, the input RasterLayer has 100 columns, and fact=12, the output RasterLayer will have either 8 columns (expand=FALSE) (using 8 x 12 = 96 of the original columns) or 9 columns (expand=TRUE). In both cases, the maximum x coordinate of the output RasterLayer would, of course, also be adjusted. The function fun should take multiple numbers, and return a single number. For example mean, modal, min or max.

See Also

disaggregate

Examples

Run this code
r <- raster()
# a new aggregated raster, no values
ra <- aggregate(r, fact=10)
r <- setValues(r, runif(ncell(r)))
ra <- aggregate(r, fact=10, fun=max)
# a new aggregated raster, max of the values

Run the code above in your browser using DataCamp Workspace