girs.rast.proc.calculate

calculate(calc, **kwargs)

Examples:

# Returns in 'MEM', applying the algebra to raster R, bands 1 and 2
calculate("(R1-R2)/(R1+R2)", R='C:/tmp/raster1.tif')
# Save to file
calculate("(R1-R2)/(R1+R2)", R='C:/tmp/raster1.tif', output_raster='C:/tmp/ndvi.tif')
# Using lists of bands. Note that [1:2] means band 1 and band 2. band numbers start at
# 1 and include the last index
calculate("(R[1, 2]+S[1, 2])/(R[1, 2]-S[1, 2])")
# ... which is equivalent to
calculate("(R[:2]+S[:2])/(R[:2]-S[:2])")
# Applying calculate to all bands
calculate("(R[:]+S[:])/(R[:]-S[:])")
# This is also possible:
calculate("(R[1, 2]+S[3, 4])/(R[:2]-S[1, 4])")

See also:

Parameters:
  • calc

    algebraic operation supported by numpy arrays “(R1-R2)/(R1+R2)”, where R1 and R2 are the keys used in the argument rasters:

    • R1: raster R band 1
    • R2: raster R band 2
  • kwargs
    • <letter> (a letter used in calc, string): filename or Raster instance
    • output_raster (str): filename of the new rasters
    • driver (str): driver name
Returns: