RasterConverter

Converts a raster to another data type: byte, short, integer, float or double. The smaller types save space, as the elevation in meters stored as short integers in a quarter of the size of the double raster, or the classes of a map stored as bytes. The novalues of the input become the novalue of the new type, and the values are rounded for the integer types.

Without a type the module only reads the raster and writes it again, which converts its format, as an ASCII grid to a GeoTIFF; the optional bounds, resolution or rows and columns read only a part of the raster or resample it.

Details

The values are rounded to the nearest integer for the byte, short and integer types, and to about 7 significant digits for the float one, that so halves the size of a double raster. The short type, from -32768 to 32767, takes half the space of the integer one and suits the elevations in meters; the byte type, from 0 to 254, a quarter, and suits the classes and the masks. The novalue of the input, whatever it is, becomes the -9999 of the HortonMachine, or 255 for the byte type, as the values that don’t fit in the type. A cell whose value is the novalue, as a -9999 in an integer raster, is read as novalue too.

Without a type the raster is only read and written again, which converts its format, as an ASCII grid to a GeoTIFF.

The bounds, the resolution or the rows and columns, all optional, read only a part of the raster or resample it, with the nearest cell, as the raster reader does.

Parameters

Converts a raster to another data type, byte, short, integer, float or double, keeping its novalues.

Toolbox folder: Raster Processing
Status: Certified
Keywords: Raster, Conversion, Type, Integer, Float
Authors: Andrea Antonello
Class: org.hortonmachine.modules.RasterConverter

Inputs

Parameter

Type

Unit

Default

Description

inRaster

raster file

The raster to convert.

pOutType

String

The data type of the output: byte, short, integer, float or double. If not given, the type doesn’t change. Allowed values: BYTE, SHORT, INTEGER, FLOAT, DOUBLE.

pNorth

Double

The north bound of the region to consider

pSouth

Double

The south bound of the region to consider

pWest

Double

The west bound of the region to consider

pEast

Double

The east bound of the region to consider

pXres

Double

The requested resolution in x.

pYres

Double

The requested resolution in y.

pRows

Integer

The rows of the region to consider

pCols

Integer

The cols of the region to consider

Outputs

Parameter

Type

Unit

Description

outRaster

output file

The converted 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. It stores the elevation as short integers and the elevation belts of RangeLookup as bytes:

import org.hortonmachine.modules.RasterConverter

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

// the elevation rounded to the meter, as short integers: a quarter of the size of the double raster
var converter = new RasterConverter()
converter.inRaster = folder + "dtm_flanginec.tif"
converter.pOutType = "SHORT"
converter.outRaster = folder + "dtm_short.tif"
converter.process()

// the elevation belts of RangeLookup as bytes, the smallest type for classes
converter = new RasterConverter()
converter.inRaster = folder + "elevation_belts.tif"
converter.pOutType = "BYTE"
converter.outRaster = folder + "elevation_belts_byte.tif"
converter.process()