0

Referring to this post I want to add the maximum and minimum raster value in the script loop to do a normalization calculation.

The normalization calculation I want to do:

(((Rasterlayer - Minimum Value of Rasterlayer) / (Maximum Value of Rasterlayer - Minimum Value of Rasterlayer))-1)*(-1)

The original source code (by @Joseph and modified by @Angelina Savchuk) which so far only divides and multiplies the values of the given raster with each other:

from qgis.analysis import QgsRasterCalculatorEntry, QgsRasterCalculator
from qgis.core import QgsProject

lddLrs = [tree_layer.layer() for tree_layer in QgsProject.instance().layerTreeRoot().findLayers()]
path = "path/to/output"
for lyr in lddLrs:
    entries = []
    ras = QgsRasterCalculatorEntry()
    ras.ref = 'ras@1'
    ras.raster = lyr
    ras.bandNumber = 1
    entries.append( ras )
    calc = QgsRasterCalculator( '(ras@1 / ras@1) * ras@1', path + lyr.name() + "_suffix.tif", 'GTiff', lyr.extent(), lyr.width(), lyr.height(), entries )
    calc.processCalculation()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.