r.compress(1)
π r.compress(1) β the GRASS GIS manual, but make it make sense
okay bestie, this is r.compress, straight out of the GRASS GIS User's Manual. it's a little guy that squishes raster maps down and unsquishes them back. let's get into it π«Ά
β¨ NAME β¨
r.compress β compresses and decompresses raster maps. that's the whole job. iconic.
π KEYWORDS π
raster, map management, compression
πΈ SYNOPSIS πΈ
r.compress
r.compress --help
r.compress [-upg] map=name[,name,...] [--help] [--verbose] [--quiet]
[--ui]
π Flags:
-uβ uncompress the map (yes, it un-does the squish)-pβ print compression information and data type of input map(s)-gβ print compression information in shell script style--helpβ print usage summary--verboseβ verbose module output--quietβ quiet module output--uiβ force launching GUI dialog
π¦ Parameters:
map=name[,name,...][required] β name of existing raster map(s)
π DESCRIPTION π
r.compress can compress or decompress raster maps, and ngl it also prints info about the compression method and the data type of the input raster map(s). multitasking queen.
every raster map β the ones you import for the first time AND the ones you generate fresh β gets compressed by default, using ZSTD if it's available, otherwise ZLIB (more on those below, don't worry). and the related no data files (aka NULL files), if they exist, are compressed by default too β unless a specific environment variable is set to explicitly turn NULL file compression off (GRASS_COMPRESS_NULLS, see below π).
when it's compressing or re-compressing, r.compress uses whatever method the environment variable GRASS_COMPRESSOR tells it to. the default is ZSTD if available, otherwise ZLIB's "deflate" algorithm (LZ77-based). raster maps that carry very little information β think boundary, geology, soils and land use maps β can be massively reduced in size. some raster maps get shrunk down to roughly 1% of their original sizes, which is honestly giving main character energy. and every newly generated raster map is 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 can read both compressed and uncompressed raster maps, so nobody's left out π
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, in the case of ZLIB compression, by changing the compression level with the environment variable GRASS_ZLIB_LEVEL.
compressed raster maps can be decompressed with r.compress plus the -u flag. if a raster map was already decompressed and you set -u anyway, the module just tells you the map is already decompressed and exits. no drama, no error, it's very chill about it.
info about the compression method and data type of the input raster map(s) can be printed in shell style with the -g flag. in that 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", all separated by the pipe character. NULL file compression shows up as "YES" or "NO". slay.
π TERMINOLOGY
- INTEGER map (CELL data type): a raster map of INTEGER type (whole numbers only)
- FLOAT map (FCELL data type): a raster map of FLOAT type (4 bytes, 7-9 digits precision)
- DOUBLE map (DCELL data type): a raster map of DOUBLE type (8 bytes, 15-17 digits precision)
- NULL: represents
"no data"in raster maps; to be distinguished from 0 (zero) data value
π OVERVIEW OF AVAILABLE COMPRESSION ALGORITHMS
these are the compression methods on the menu (set with export GRASS_COMPRESSOR=method):
- NONE (uncompressed)
- RLE (generic Run-Length Encoding of single bytes; deprecated)
- ZLIB (DEFLATE, good speed and compression)
- with zlib compression levels (
export GRASS_ZLIB_LEVEL=X):-1..9(-1is default which corresponds to ZLIB level 6) - note:
export GRASS_ZLIB_LEVEL=0is equal to copying the data as-is from source to destination
- with zlib compression levels (
- LZ4 (fastest, low compression)
- BZIP2 (slowest, high compression)
- ZSTD (compared to ZLIB, faster and higher compression, much faster decompression - default compression)
Important: the NULL file compression can be turned off withexport 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 withr.null -z. The NULL file compression is using the LZ4 method as being the best compromise between speed and compression rate.
π§ COMPRESSION ALGORITHM DETAILS
all GRASS GIS raster map types are by default ZSTD compressed if available, otherwise ZLIB compressed. through the environment variable 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 β and this is a big 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. periodt.
RLE
DEPRECATED Run-Length Encoding, poor compression ratio but fast. It is kept for backwards compatibility to read raster maps created with GRASS 6. It is only used for raster maps of typeCELL.FCELLandDCELLmaps are never and have never been compressed with RLE.
ZLIB
ZLIB's deflate is the default compression method for all raster maps, if ZSTD is not available. GRASS GIS 8 uses by default 1 as ZLIB compression level, which is the best compromise between speed and compression ratio, also when compared to other available compression methods. Valid levels are in the range [1, 9] and can be set with the environment variable GRASS_ZLIB_LEVEL.
LZ4
LZ4 is a very fast compression method, about as fast as no compression. Decompression is also very fast. The compression ratio is generally higher than for RLE but worse than for ZLIB. LZ4 is recommended if disk space is not a limiting factor.
BZIP2
BZIP2 can provide compression ratios much higher than the other methods, but only for large raster maps (> 10000 columns). For large raster maps, disk space consumption can be reduced by 30 - 50% when using BZIP2 instead of ZLIB's deflate. BZIP2 is the slowest compression and decompression method. However, if reading from / writing to a storage device is the limiting factor, BZIP2 compression can speed up raster map processing. Be aware that for smaller raster maps, BZIP2 compression ratio can be worse than other compression methods. π
ZSTD
ZSTD (Zstandard) provides compression ratios higher than ZLIB but lower than BZIP2 (for large data). ZSTD compresses up to 4x faster than ZLIB, and usually decompresses 6x faster than ZLIB. ZSTD is the default compression method if available. π₯
β NOTES β
π Compression method number scheme
the used compression method is encoded with numbers. in the internal 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. the map decides, not you, bestie.
π Formats
conceptually, a raster data file consists of rows of cells, with each row containing the same number of cells. a cell consists of one or more bytes. for CELL maps, the number of bytes per cell depends on the category values stored in the cell. category values in the range 0-255 require 1 byte per cell, while category values in the range 256-65535 require 2 bytes, and category values in the range above 65535 require 3 (or more) bytes per cell.
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. glow up β¨
π ZLIB compression levels
if the environment variable 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.
π EXAMPLES π
π Printing of current compression state
example for an uncompressed raster map:
r.compress compressed_no -p
<compressed_no> (method 0: NONE). Data type: <CELL>
π Applying ZLIB compression
applying ZLIB compression to a copy of the uncompressed map from above:
# 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
π Applying BZIP2 compression
applying BZIP2 compression to a copy of the ZLIB-compressed map from above:
# 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
π Applying ZSTD compression
applying ZSTD compression to a copy of the BZIP2-compressed map from above:
# 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
π SEE ALSO π
r.info, r.null, r.support
Compression algorithms: bzip2, LZ4, zlib, zstd
π«Ά AUTHORS π«Ά
James Westervelt and Michael Shapiro, U.S. Army Construction Engineering Research Laboratory
Markus Metz
π SOURCE CODE π
Available at: r.compress source code (history)
Accessed: Saturday Jan 17 05:40:44 2026
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
okay that's the whole page, no cap π this was GRASS 8.4.2, and the manual is the Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual. go forth and compress, bestie, you've got this πβ¨
π¦ where this page comes from
- fedora 44: grass 8.4.2-4.fc44 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms