All raster maps (those imported for the first time and those newly
generated) are compressed by default using the ZSTD compression
method if available, otherwise ZLIB compression is used (see below).
Related no data files (i.e.: NULL files), if present, are compressed by
default unless a specific environment variable is set to explicitly
disable NULL file compression (GRASS_COMPRESS_NULLS
, see
below).
During compression or re-compression, r.compress compresses
raster maps using the method specified by means of the environment
variable GRASS_COMPRESSOR
. The default compression method is
ZSTD if available, otherwise ZLIB's "deflate" algorithm (LZ77-based).
Raster maps that contain very little information (such as boundary,
geology, soils and land use maps) can be greatly reduced in size. Some
raster maps are shrunk to roughly 1% of their original sizes.
All newly generated raster maps are automatically stored as compressed
data with varying methods depending on the raster format (i.e.,
CELL: integer; FCELL: single precision; DCELL: double precision; see
below). All GRASS GIS modules are able to read both compressed and
uncompressed raster maps.
Raster maps that are already compressed might be compressed again,
either by setting a different method with GRASS_COMPRESSOR
(supported methods: RLE, ZLIB, LZ4, BZIP2, ZSTD) or, for the case of
ZLIB compression, by changing the compression level with the
environment variable GRASS_ZLIB_LEVEL
.
Compressed raster maps may be decompressed using r.compress with the -u flag. If a raster map was already decompressed and the -u flag is set, the module simply informs the user that the map is already decompressed and exits.
Information about the compression method and data type of the input
raster map(s) can be printed in shell style with the -g flag. In
this case, the module prints to stdout
one line per input map
with the fields "input map name", "data type",
"name of data compression method", "NULL file
compression" separated by the pipe character. NULL file
compression is indicated with "YES" or "NO".
export GRASS_COMPRESSOR=method
):
NONE
(uncompressed)RLE
(generic Run-Length Encoding of single bytes; deprecated)ZLIB
(DEFLATE, good speed and compression)
export GRASS_ZLIB_LEVEL=X
): -1..9
(-1 is default which corresponds to ZLIB level 6)export GRASS_ZLIB_LEVEL=0
is equal to copying the data
as-is from source to destinationLZ4
(fastest, low compression)BZIP2
(slowest, high compression)ZSTD
(compared to ZLIB, faster and higher compression,
much faster decompression - default compression)export GRASS_COMPRESS_NULLS=0
. Raster maps with NULL file
compression can only be opened with GRASS GIS 7.2.0 or later. NULL file
compression for a particular raster map can be managed with r.null -z.
The NULL file compression is using the LZ4 method as being the best compromise
between speed and compression rate.
GRASS_COMPRESSOR
the compression method can be set to RLE,
ZLIB, LZ4, BZIP2, or ZSTD.
Integer (CELL type) raster maps can be compressed with RLE if
the environment variable GRASS_COMPRESSOR
exists and is set to
RLE. However, this is not recommended.
Floating point (FCELL, DCELL) raster maps never use RLE compression; they are either compressed with ZLIB, LZ4, BZIP2, ZSTD or are uncompressed.
GRASS_ZLIB_LEVEL
.cellhd
file, the value for "compressed" is 1 for RLE, 2
for ZLIB, 3 for LZ4, 4 for BZIP2, and 5 for ZSTD.
Obviously, decompression is controlled by the raster map's compression, not by the environment variable.
FCELL maps always have 4 bytes per cell and DCELL maps always have 8 bytes per cell.
Since GRASS GIS 7.0.0, the default compression method for Integer (CELL) raster maps is ZLIB and no longer RLE.
GRASS_ZLIB_LEVEL
exists and
its value can be parsed as an integer, it determines the compression
level used when newly generated raster maps are compressed using ZLIB
compression. This applies to all raster map types (CELL, FCELL, DCELL).
If the variable does not exist, or the value cannot be parsed as an integer, ZLIB's compression level 1 will be used.
r.compress compressed_no -p <compressed_no> (method 0: NONE). Data type: <CELL>
# compression of map using ZLIB compression g.copy raster=compressed_no,compressed_ZLIB export GRASS_COMPRESSOR=ZLIB # ZLIB r.compress compressed_ZLIB r.compress compressed_ZLIB -p <compressed_ZLIB> is compressed (method 2: ZLIB). Data type: <CELL> unset GRASS_COMPRESSOR # switch back to default
# compression of map using BZIP2 compression g.copy raster=compressed_ZLIB,compressed_BZIP2 export GRASS_COMPRESSOR=BZIP2 # BZIP2 r.compress compressed_BZIP2 r.compress compressed_BZIP2 -p <compressed_BZIP2> is compressed (method 4: BZIP2). Data type: <CELL> unset GRASS_COMPRESSOR # switch back to default
# compression of map using ZSTD compression g.copy raster=compressed_BZIP2,compressed_ZSTD export GRASS_COMPRESSOR=ZSTD # ZSTD r.compress compressed_ZSTD r.compress compressed_ZSTD -p <compressed_ZSTD> is compressed (method 5: ZSTD). Data type: <CELL> unset GRASS_COMPRESSOR
Compression algorithms: bzip2, LZ4, zlib, zstd
Markus Metz
Available at: r.compress source code (history)
Latest change: Tuesday Dec 17 20:17:20 2024 in commit: d962e90c026708a4815ea2b9f46c0e84c17de22d
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
© 2003-2024 GRASS Development Team, GRASS GIS 8.4.1dev Reference Manual