4

I am looking for ArcGIS's dynamic range adjustment (DRA) analouge in QGIS for raster data sets. And I have found such button:

enter image description here

But I have to click it every time I move raster's extent.

There is any way to automate manual clicking the button?

2
  • You can right-click on the Layer -> Stretch to current Extent. But that is not automatic.
    – pLumo
    Commented Sep 29, 2017 at 11:03
  • Will be available in 3.0. See here
    – pLumo
    Commented Sep 29, 2017 at 11:08

3 Answers 3

5

Nice find by @RoVo! There is also an alternative.


For QGIS 2.x

We could use a little bit of Python where each time the extent of the canvas changes, we connect the signal that is emitted to a function which triggers the button you mentioned.

So you could use something like the following in the Python Console:

from PyQt4.QtGui import QAction

def stretch_raster():
    try:
        layer = iface.activeLayer()
        if layer.type() == QgsMapLayer.RasterLayer:
            iface.mainWindow().findChild( QAction, 'mActionLocalCumulativeCutStretch' ).trigger()
    except AttributeError:
        pass

iface.mapCanvas().extentsChanged.connect(stretch_raster)

Note that the button will only be triggered if a raster layer is selected from the Layers Panel. When you want to disconnect the signal from the function, you can use:

iface.mapCanvas().extentsChanged.disconnect(stretch_raster)
2
  • Nice one. Maybe the better answer ... ;-)
    – pLumo
    Commented Sep 29, 2017 at 11:45
  • @RoVo - Thanks but eventually this answer will be obsolete, particularly when QGIS 3.0 comes out relatively soon :)
    – Joseph
    Commented Sep 29, 2017 at 11:48
5

Unfortunately, this feature is not available without some python scripting, but will be available in 3.0.

See https://github.com/qgis/QGIS-Documentation/issues/1583

@QGIS-feature-tracker QGIS-feature-tracker added this to the QGIS 3.0 milestone on Dec 16, 2016

5

To turn on ArcGIS's dynamic range adjustment (DRA) analouge in QGIS 3.12 go to:

Raster Layer Properties => Symbology => Min / Max Value Settings

and set Statistic extent to Updated canvas.

How it works video (size - 20 MB).

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.