RasterValueRounder

Rounds the values of a raster to a number of decimals, given by a pattern. It removes the meaningless decimals of the results of interpolations and conversions, for the readability of the values and the size of the compressed files.

Details

The pattern is a Java DecimalFormat pattern, with the dot as decimal separator whatever the language of the system: 0.00 rounds to two decimals, # to the integer. The values are rounded half up, so 2.5 becomes 3 and 2.25 with 0.0 becomes 2.3. The novalues stay novalue.

The rounded values are doubles, nearest to the rounded decimals: 6.35 is not exact in binary. The rounding removes the noise of the last decimals, as in the output of an interpolation, and makes the files compress better; to round to steps that are not decimals, as to the half meter, Mapcalc does it with round(value * 2) / 2.

Parameters

Rounds the values of a raster to a number of decimals.

Toolbox folder: Raster Processing
Status: Certified
Keywords: Round, Raster
Authors: Andrea Antonello
Class: org.hortonmachine.modules.RasterValueRounder

Inputs

Parameter

Type

Unit

Default

Description

inRaster

raster file

The raster of which to round the values.

pPattern

String

The rounding pattern, as 0.00 for two decimals.

Outputs

Parameter

Type

Unit

Description

outRaster

output file

The rounded 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.RasterValueRounder

// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"

// the elevation to the decimeter
var rounder = new RasterValueRounder()
rounder.inRaster = folder + "dtm_flanginec.tif"
rounder.pPattern = "0.0"
rounder.outRaster = folder + "dtm_rounded.tif"
rounder.process()

The rounded elevation is compared with the original one in the example of RasterCompare.