rio calc

A raster data calculator

Evaluates an expression using input datasets and writes the result to a new dataset.

Command syntax is lisp-like. An expression consists of an operator or function name and one or more strings, numbers, or expressions enclosed in parentheses. Functions include read (gets a raster array) and asarray (makes a 3-D array from 2-D arrays).

* (read i) evaluates to the i-th input dataset (a 3-D array).
* (read i j) evaluates to the j-th band of the i-th dataset (a
2-D array).
* (take foo j) evaluates to the j-th band of a dataset named foo
(see help on the –name option above).
* Standard numpy array operators (+, -, *, /) are available.
* When the final result is a list of arrays, a multiple band
output file is written.
* When the final result is a single array, a single band output
file is written.


$ rio calc “(+ 2 (* 0.95 (read 1)))” tests/data/RGB.byte.tif
> /tmp/out.tif

The command above produces a 3-band GeoTIFF with all values scaled by 0.95 and incremented by 2.

$ rio calc “(asarray (+ 125 (read 1)) (read 1) (read 1))”
> tests/data/shade.tif /tmp/out.tif

The command above produces a 3-band RGB GeoTIFF, with red levels incremented by 125, from the single-band input.

The maximum amount of memory used to perform caculations defaults to 64 MB. This number can be increased to improve speed of calculation.



-o, --output <output>

Path to output file (optional alternative to a positional arg).

-f, --format, --driver <driver>

Output format driver

--name <name>

Specify an input file with a unique short (alphas only) name for use in commands like “a=tests/data/RGB.byte.tif”.

-t, --dtype <dtype>

Output data type.


ubyte | uint8 | uint16 | int16 | uint32 | int32 | float32 | float64

--masked, --not-masked

Evaluate expressions using masked arrays (the default) or ordinary numpy arrays.


Always overwrite an existing output file.

--mem-limit <mem_limit>

Limit on memory used to perform calculations, in MB.

--co, --profile <NAME=VALUE>

Driver specific creation options. See the documentation for the selected output driver for more information.



Required argument


Required argument(s)