RasterToCog¶
Converts a raster into a Cloud Optimized GeoTIFF (COG): a GeoTIFF organized so that it can be read efficiently from a web server. The image is cut in square tiles, with overviews at lower resolutions, and the index of all of them is at the beginning of the file. So a client, as a web map, QGIS or GDAL, reads only the tiles of the area and of the resolution it shows, with a few HTTP range requests, without downloading the whole file.
The module writes the COG in pure Java, as the COG driver of GDAL does, with a lossless compression, Deflate or LZW. The overviews are computed from 2x2 cells, averaging the values of continuous data, as elevations, and taking the most frequent value of classes and codes: the default, auto, chooses from the data type. Large GeoTIFFs are read by windows, so they don’t need to fit in memory.
A COG is still a GeoTIFF, readable by any GIS: converting the rasters to publish, as on a STAC catalog, makes them usable from the web.
Details¶
The COG is written as the COG driver of GDAL does: square tiles, overviews halving the resolution until the image fits a single tile, all the image directories at the beginning of the file, then the tiles of the smallest overview first and those of the full resolution last. So a client reading the file over HTTP, as a web map or QGIS, gets the part and the resolution it needs with a few range requests, without downloading the file.
The compression is lossless, and the tiles are compressed in parallel. The input is read by windows when it is a GeoTIFF, and the compressed tiles go to a temporary file next to the output, so rasters larger than the memory can be converted; BigTIFF is used when the file exceeds 4 GB. The nodata of the file is the one of the input if it has one, else NaN for floating point data and the novalue of the raster for integer data.
Parameters¶
Converts a raster to a Cloud Optimized GeoTIFF (COG): tiled, with overviews, directories before the data and lossless compression. Large GeoTIFFs are read by windows, so they don’t need to fit in memory.
Toolbox folder: Raster Processing
Status: Experimental
Keywords: IO, COG, Cloud Optimized GeoTIFF, Raster, Overviews, Writing
Authors: Andrea Antonello
Class: org.hortonmachine.modules.RasterToCog
Inputs
Parameter |
Type |
Unit |
Default |
Description |
|---|---|---|---|---|
|
raster file |
The raster to convert. |
||
|
String |
|
How the overviews are computed from 2x2 cells: auto (average for floating point data, mode for integer data like codes or classes), average, nearest (upper left cell) or mode (most frequent value). Allowed values: |
|
|
String |
|
The lossless compression: deflate (default) or lzw. Allowed values: |
|
|
int |
|
The deflate level, from 1 (fastest) to 9 (smallest), default is 6. |
|
|
boolean |
|
Use the TIFF predictor that fits the data type (horizontal for integers, floating point for floats), usually giving smaller files (default is true). |
|
|
int |
|
The size of the tiles, a multiple of 16 (default is 512). |
|
|
int |
number of processors |
The number of threads compressing the tiles (defaults to the number of available processors). |
Outputs
Parameter |
Type |
Unit |
Description |
|---|---|---|---|
|
output file |
The output COG file. |
Example¶
The example converts the sample elevation model of the manual, dtm_flanginec.tif in docs/manual/modules/maps/data, with the default settings:
import org.hortonmachine.modules.RasterToCog
// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"
// the elevation model as a Cloud Optimized GeoTIFF, with the default settings:
// 512x512 tiles, deflate compression and averaged overviews
var cog = new RasterToCog()
cog.inRaster = folder + "dtm_flanginec.tif"
cog.outCog = folder + "dtm_flanginec_cog.tif"
cog.process()