4

Is it possible to modify the following syntax somehow that it would be applicable in Field Calculator in QGIS? The input layer is point layer and I would like to do following calculations which I can't do in Excel due to large amount of data.

if(  "VALUE1" < 0.01, 2,
  if( AND( "VALUE1" >= 0.01, "VALUE1" < 0.1 ), 3,
    if( OR( "VALUE1" >= 0.1, "VALUE2"  >= 2 ),  4, 0 )
  )
)

Any ideas?

3
  • Please describe more detailled what you are trying to achieve. Currently your chaining of if, and and or is absolutely wrong.
    – Erik
    Mar 23, 2020 at 8:19
  • ... or right ... but not in QGIS syntax at least ...
    – Snaileater
    Mar 23, 2020 at 8:20
  • @Erik Its not QGIS syntax. I would like to transform this Excel syntax to QGIS syntax for field calculator if possible?
    – Petr
    Mar 23, 2020 at 8:23

2 Answers 2

7

You can use the CASE WHEN statement. I will give you an example, adapt it.

CASE WHEN  "VALUE1" < 0.01 THEN 2
WHEN "VALUE1" >= 0.01 AND "VALUE1" < 0.1 THEN 3 
ELSE 4
END 

I applied this formula to the VALUE2 field, here is the result:

enter image description here

1
  • Thanks, your method worked.
    – Petr
    Mar 23, 2020 at 14:15
5

Just offset the logical operators and petr's syntax is right (imho)

if("VALUE1"<0.01,2,if("VALUE1">=0.01 AND "VALUE1"<0.1,3,if("VALUE1" >=0.1 OR "VALUE2">=2,4,0)))
3
  • Thank you, in the end my expression turned out to be close to correct one.
    – Petr
    Mar 23, 2020 at 14:16
  • Yep you're right ... where does your syntax come from ?
    – Snaileater
    Mar 23, 2020 at 15:28
  • What do you mean? Its from Ecxel and has been edited by someone here on this thread to this form. My original idea was to do it in Excel, however I have over 1.200.000 points with more columns and Ecel could not handle the data. After the calculalation was done I used rasterize tool to create a raster with values 2,3, and 4.
    – Petr
    Mar 23, 2020 at 16:43

Your Answer

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

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