3

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?

  • You can right-click on the Layer -> Stretch to current Extent. But that is not automatic. – pLumo Sep 29 '17 at 11:03
  • Will be available in 3.0. See here – pLumo Sep 29 '17 at 11:08
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

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)
  • Nice one. Maybe the better answer ... ;-) – pLumo Sep 29 '17 at 11:45
  • @RoVo - Thanks but eventually this answer will be obsolete, particularly when QGIS 3.0 comes out relatively soon :) – Joseph Sep 29 '17 at 11:48

Your Answer

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

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