I have SHP layer loaded in QGIS. It consists of lines with attribute column z, containing integer value associated with line elevation in meters. Lines are drawn at 10 meter increment, and I want to apply style to lines on 50 meter increment.

For that purpose in "Style" tab in "Layer Properties" dialog, I use "rule based" style and want to define above described rule. From available operators I can see only one possibility with this filter expression:

z/50 - toint(z/50) = 0

However it returns true for all lines, while I expected just those with 50 meter increment.

There is also "Expression builder" dialog, but it does not return results from typed expression, for some reason, and I'm not able to determine what is the problem?

Any ideas?


I'm not sure, as already mentioned expression output is not available, but I guess that expression evaluation is like in Python - if float number isn't used result is integer regardless real value. So this worked for me:

z/50.0 - toint(z/50.0) = 0

in lack of modulo operator

  • 2
    Mod is the symbol %. Yes the QGIS expression engine will return a int if both sides are ints, if one is a float it will return a float. – Nathan W Dec 2 '12 at 22:18

The modulo operator, % isn't listed in the Expression builder window, but does work. I had the same goal as you and have taken the following steps to style my 10-feet-appart topo-lines so that the lines every 50 feet are heavier "index" lines that also have a label displayed:

enter image description here

After clicking on the properties of my contour line layer (which in my case has the elevation in an ELEV attribute)...

Style the index lines heavier

  1. Under Style, change the style to Rule Based, this should leave the default style with no filter.
  2. Add a rule (which I labeled "Index lines") and use "ELEV" % 50 = 0 as the filter.
  3. Increase the weight of the line to something pleasing. I went from a default of 0.25 to 0.5 for the index lines.
  4. Save the Rule

Add labels for index lines

  1. Under Labels change the mode to Rule-based labeling.
  2. Add a rule (which I labeled "Index lines") and use "ELEV" % 50 = 0 as the filter.
  3. Check the Scale Range box to halt label printing at low zooms.
  4. Under Labels choose to label with your ELEV field.
  5. Set your font color to nicely match your contour lines.
  6. Save the rule.

Then hit OK to apply these new properties.


To get Index contours I use this on QGIS Field Calculator:

if(((round("level", 0) * 10) % (200 * 10)) = 0, 1, 0)

""level"" Set to contour height field "200" Set to interval of index contours

Then: "1" is an index contour and "0" is not an index contour

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.