RasterSubsampler¶
Aggregates a raster to a coarser one, whose cells cover a block of input cells each, with the average, the minimum, the maximum, the sum or the most frequent value of the block. Unlike the resampling of RasterResolutionResampler, which reads the input at the center of the new cells, every input cell weighs on the result: a land cover keeps the class that covers most of each new cell, a map of counts keeps its total.
Details¶
Every output cell covers a block of factor x factor input cells and gets the average, the min, the max, the sum or the most frequent value of its valid cells: the novalues are left out, and a block without valid cells is novalue. The resolution is exactly the input one times the factor and the grid starts at the north-west corner of the input: the last columns and rows that don’t fill a whole block are left out, so the east and south borders can move inwards by less than one output cell.
The average suits the continuous variables, as an elevation model taken to a coarser resolution, the sum the counts and the amounts per cell, the most frequent value (on ties the smallest) the classes, as a land cover. On a block with novalues the sum is of the valid cells only. The nearest mode takes the value of the input cell at the center of the block (for an even factor, the one south-east of the center), novalue included: it is the nearest neighbour resampling of RasterResolutionResampler, on the grid of the blocks.
Parameters¶
Aggregates a raster to a coarser one, of cells of factor x factor input cells.
Toolbox folder: Raster Processing
Status: Certified
Keywords: Raster, Subsampling, Aggregation, Resolution
Authors: Andrea Antonello
Class: org.hortonmachine.modules.RasterSubsampler
Inputs
Parameter |
Type |
Unit |
Default |
Description |
|---|---|---|---|---|
|
raster file |
The raster to aggregate. |
||
|
int |
|
The number of input cells per side of an output cell (default is 2). |
|
|
String |
|
The aggregation of the cells of a block (default is avg). Allowed values: |
Outputs
Parameter |
Type |
Unit |
Description |
|---|---|---|---|
|
output file |
The aggregated raster. |
Example¶
The example runs on the sample elevation model of the manual, dtm_flanginec.tif in docs/manual/modules/maps/data, each module on the outputs of the previous ones:
import org.hortonmachine.modules.RasterSubsampler
// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"
// the elevation belts of RangeLookup in cells of 100 m, with the most frequent belt of each
var subsampler = new RasterSubsampler()
subsampler.inRaster = folder + "elevation_belts.tif"
subsampler.pFactor = 10
subsampler.pMode = "majority"
subsampler.outRaster = folder + "belts_100m.tif"
subsampler.process()
// the mean elevation of the same cells
subsampler = new RasterSubsampler()
subsampler.inRaster = folder + "dtm_flanginec.tif"
subsampler.pFactor = 10
subsampler.pMode = "avg"
subsampler.outRaster = folder + "dtm_mean_100m.tif"
subsampler.process()
The elevation belts of RangeLookup in cells of 100 m, with the belt that covers most of each cell.¶