[Qgis-user] Raster calculation: if Layer1 is > 1, then Layer2 should be 0

Nyall Dawson nyall.dawson at gmail.com
Thu Feb 17 15:22:34 PST 2022


On Fri, 18 Feb 2022 at 08:56, Bernd Vogelgesang
<bernd.vogelgesang at gmx.de> wrote:
>
> Hi Nyall,
>
> sorry, mixed things up. The native raster calculator only threw errors,
> while the GDAL worked.

Thanks for the clarification! Indeed there are some open tickets
regarding the native raster calculator.

FWIW, I'd actually suggest going with the native "reclassify by table"
to perform this task. It's a very efficient tool and will handle
massive rasters without issue. The table parameter would be set to a
single row with "minimum" = 1, "maximum" = blank/not set, and "value"
= 0. Leave everything else at their default values.

To explain: If you don't check the advanced parameter "use no data
when no range matches value" (the default is that it's unchecked!)
then any input pixel value which doesn't fall into one of the ranges
defined in the table will be copied unchanged to the output. So only
pixel values > 1 will match a rule, and will output a "0" value. By
not setting a "maximum" value in the row we indicate that the range is
from 100 < input value < +infinity. It's a bit clearer when you run
the algorithm, as the log will show a descriptive explanation of the
classes. Something like this:

"Using classes:
1) 1 < x ≤ ∞ → 0"

ie. values > 1 and <= infinity will map to 0, others will be unchanged.

Hope that helps!

Nyall











>
> Now that I tried again, everything is fine. Strange hickup.
>
> Anyway, everything ist fine now and things start getting sorted.
>
> Happy again :)
>
> Cheers,
>
> Bernd
>
>
>
> Am 17.02.22 um 23:22 schrieb Nyall Dawson:
> > On Fri, 18 Feb 2022 at 08:08, Bernd Vogelgesang
> > <bernd.vogelgesang at gmx.de> wrote:
> >> Hi Sebastian,
> >>
> >> thanx, that worked.
> >>
> >> But somehow, the hole process feels a bit clumsy.
> >>
> >> Having to fumble together a classification with "thru" (juck!), then the toolbox reclassify just seems to be broken,
> > Which reclassify tool are you referring to exactly? The native QGIS
> > ones are 100% NOT broken. (The SAGA one may be, but that's a 3rd party
> > tool.)
> >
> > Nyall
> >
> >
> > gladly gdal calculator does ...
> >> Why isn't there some "raster SQL" that saves one from all these stupid single steps?
> >>
> >> Ok, will then try to build a model and hope it will work for the tests to come…
> >>
> >> Thanks a lot,
> >>
> >> Bernd
> >>
> >>
> >> Am 17.02.22 um 22:19 schrieb Sebastian Gutwein:
> >>
> >> Reclassify your Layer 1 to be anything greater than 1 = 0 everything else equals 1. This will give you a binary 1 and 0 raster (Layer 3)  that you can use in the raster calculator: Layer 2 * Layer 3.  Anywhere where layer 3 is 1 your layer 2 values will stay the same and anywhere where layer 3 is 0 your layer 2 values will become 0.
> >>
> >> On Thu, Feb 17, 2022 at 3:19 PM Bernd Vogelgesang <bernd.vogelgesang at gmx.de> wrote:
> >>> Hi folk,
> >>>
> >>> I hardly never work with raster calculations, and unfortunately there is nowhere a collection of syntax examples for different use cases to be found (documentation :( ).
> >>>
> >>> Anything apart from +-*/ is beyond my scope.
> >>>
> >>> So,
> >>>
> >>> I made a viewshed analysis over a digital surface model (try the awesome Visibility Analysis plugin form Zoran Čučković and buy him a beer!)
> >>>
> >>> A lot of "views" are caught by tree canopy, but I am only interest in the flat grounds.
> >>>
> >>> So I substracted the surface model layer from the ground model layer, and this is Layer 1.
> >>>
> >>> Giving a threshold of 1 meters difference for inaccuracities, all pixels in this layer above 1 should result in 0 (zero) in my viewshed raster (Layer 2)
> >>>
> >>> Please give me some hints,
> >>>
> >>> Cheers,
> >>>
> >>> Bernd
> >>>
> >>>
> >>> _______________________________________________
> >>> Qgis-user mailing list
> >>> Qgis-user at lists.osgeo.org
> >>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> >>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
> >> _______________________________________________
> >> Qgis-user mailing list
> >> Qgis-user at lists.osgeo.org
> >> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> >> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


More information about the Qgis-user mailing list