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 |
|---|---|---|---|---|
|
raster file |
The raster to convert. |
||
|
String |
The data type of the output: byte, short, integer, float or double. If not given, the type doesn’t change. Allowed values: |
||
|
Double |
The north bound of the region to consider |
||
|
Double |
The south bound of the region to consider |
||
|
Double |
The west bound of the region to consider |
||
|
Double |
The east bound of the region to consider |
||
|
Double |
The requested resolution in x. |
||
|
Double |
The requested resolution in y. |
||
|
Integer |
The rows of the region to consider |
||
|
Integer |
The cols of the region to consider |
Outputs
Parameter |
Type |
Unit |
Description |
|---|---|---|---|
|
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()