1

I am using QGIS 3.8 and I have a raster named "Ri" with one band with values ranging from 0.00299858 to 0.198849 and second raster named "IP_Q" with one band with values ranging from 0.00100708 to 14.5811. I am trying to create one raster out of these two rasters using Raster calculator.

The output should have three cathegories based on this table:

  1. cathegory 1: Ri < 0.01
  2. cathegory 2: 0.01 =< Ri < 0.1
  3. cathegory 3: Ri >= 0.1 or IP_Q >= 2

The raster calculator expression I've used is as follows:

( "Ri" < 0.01 )  * 1 +  (  ( 0.01 <= "Ri" )  AND  ( "Ri" < 0.1 )  )  * 2 +  (  ( "Ri" >= 0.1 )  OR  ( "IP_Q" >= 2 )  )  * 3

However, the result is a raster with values ranging from 1 to 7. I am trying to get a raster with values ranging only from 1 to 3 so it corresponds to the table above.

It seems I am missing something.

Any ideas?

6
  • More than one condition can be true at the same time. Equally 7 seems a very large number, but Ri 0.05, IP_Q 2 must return a 5. Commented Nov 15, 2019 at 18:27
  • @GabrielDeLuca I am not sure whether I got your point - I didnt get your mention Ri 0.05 and IP_Q 2, can you please be more specific in your answer? What do you think about the expression? Should it work or would you formulate it differently?
    – Petr
    Commented Nov 18, 2019 at 7:57
  • 1
    Conditions must be mutually exclusive. If a pixel has the following values: "Ri" = 0.05, "IP_Q" = 2; it fits in category 2 (because 0.01 <= Ri < 0.1) and fits in category 3 (because IP_Q >= 2). In wich category must it be? Commented Nov 18, 2019 at 13:55
  • @GabrielDeLuca Very good point, thanks for that. I've check the data and such case is not occuring for 5yr, 20, yr and 100yr flooding event as the Ri value is calculted from IP. The IP stands for the fator of intensity of flood and the Ri stands for risk assessmet. The problem is for the 500yr flooding event, where the case that you are pointing to is occuring so I've used only the condition IP_Q>=2 from the 3rd category and the output now looks good. Thanks for help.
    – Petr
    Commented Nov 19, 2019 at 10:09
  • I am sorry but I do not see the difference that could be achieved by removing the condition of Ri from the third category in the example, the same case should continue to fall into categories 2 and 3 at the same time, even other cases would become badly undefined (Ri = 0.2 , IP_Q = 1 in which category would go now?). Redefine your conditions in a way that is mutually exclusive. I proposed a new formulation as an answer, but I do not know your categories, you should be able to describe them in a better way considering all possible combinations of values. Commented Nov 22, 2019 at 0:44

1 Answer 1

1

The conditions must be mutually exclusive, if you want all possible cases to fall into one and only one of those categories.

For example, if you want that whenever the IP_Q value is greater than or equal to 2, category 3 corresponds, and otherwise it is defined between categories 1 and 2 depending on the value of the Ri variable, then the categories should be defined as as follows:

  1. cathegory 1: ( Ri < 0.01 ) AND ( IP_Q < 2 )
  2. cathegory 2: ( Ri >= 0.01 ) AND ( Ri < 0.1 ) AND ( IP_Q < 2 )
  3. cathegory 3: ( Ri >= 0.1 ) OR ( IP_Q >= 2 )

The expression of the raster calculator would be as follows:

(( "Ri" < 0.01 ) AND ( "IP_Q" < 2 )) * 1 +
(( "Ri" >= 0.01 ) AND ( "Ri" < 0.1 ) AND ( "IP_Q" < 2 )) * 2 +
(( "Ri" >= 0.1 ) OR ( "IP_Q" >= 2 )) * 3

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.