2

In an elevation file I want to find all the 5m contours and mark a column up as major. This has to be done in QGIS in the field calculator or modeler.

I want to do something like the following based on this post

CASE WHEN "elevation" %% 5 THEN 'major'
 WHEN "elevation" %% 1 THEN "moderate"
 ELSE "Minor"
 END

But this doesn't work -

Parser Error: syntax error, unexpected MOD

Eval Error: No root node! Parsing failed?

Ideally I want to run it as part of the following (which works but level 50 includes 1m and 5m contours)

CASE WHEN  "contour_level" = 48 THEN 'minor'
 WHEN  "contour_level" = 49 THEN 'minor'
 WHEN  "contour_level" = 50 THEN 'moderate'
 ELSE 'Check'
 END
  • 2
    You've tagged "python" in this question, but your code looks nothing like python. – Fezter Nov 12 '15 at 4:13
  • If it does get through to Python then the modulus operator is % rather than %%. – PolyGeo Nov 12 '15 at 4:18
  • @Fezter -it is python within qgis modeler – GeorgeC Nov 12 '15 at 4:22
  • @PolyGeo I tried with % as well, both give the same error. – GeorgeC Nov 12 '15 at 4:23
  • 2
    @GeorgeC - Awesome, glad you got it working! Thanks but I will let you post the answer :) – Joseph Nov 13 '15 at 10:28
3

Based on the reply from @Joseph, I found that the following worked.

I needed 1m and 5m intervals not just 1m and 5m lines. I ended up with

[[CASE
  WHEN "elevation" % 1 THEN 'minor'
  WHEN "elevation" % 5 THEN 'moderate'
  ELSE 'major'
END]] 
  • 1
    @Joseph thanks I have added it as an answer. – GeorgeC May 20 at 3:13

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.