I commonly deal with new areas where I would like to quickly visualize contours. My aim is to be able to apply a style that contains a color ramp from the lowest to highest values but also to show all contours at multiples of 10m as thicker lines and those at multiples of 100m as thicker still.

The procedure to change the line thickness is well explained, for example in this post: Changing contour line stroke weight based on elevation in QGIS. However, I'm struggling to apply this logic after applying a color ramp from the lowest to highest.

3 Answers 3


Step 1 - Configuring the symbology type (only necessary if your contours are polygons)

Change the symbology of the fill from "Simple Fill" to "Outline: Simple Line"

Step 2 - Stroke weights

To set the stroke weight to be thicker for contours that are multiples of 10, click the expression box to the right of Stroke width and click Edit: enter image description here

Add this expression using the appropriate field name: IF("ELEV" % 10 = 0, 1, 0.4)

Step 3 - Colour ramp

Now change the symbology from "Single Symbol" to "Categorised" or "Graduated" and set up your colour ramp as you normally would based on the elevation value.

The stroke weight expression should persist into the newly generated classes.

Note: It's important to set up the stroke weight before you change the symbology to categorised or graduated, otherwise you would have to set it up for each class individually.

  • 3
    You can in fact set up the stroke weight after you change the symbology to Graduated, but you just need to apply the stroke weight logic to the generic symbol, and not the class symbol. Commented Mar 4, 2023 at 2:37

Thanks to the insightful answers and comments I realized that, after applying color by graduated symbols or a color ramp, I could follow the logic suggested by both @Kadir Şahbaz and @TeddyTedTed in applying a data-defined override to line thickness and the best way to do that was a CASE statement:

  WHEN "ELEV_N" % 1000=0 THEN 0.5
  WHEN "ELEV_N" % 100= 0 THEN 0.3
  WHEN "ELEV_N" % 10 =0 THEN 0.15
  ELSE 0.05
  1. After making graduated symbols by elevation, click the line symbol.

enter image description here

  1. Click "Data defined override" button for "Width" option, select "Edit..."

enter image description here

  1. Use this expression:

        array(10, 100), -- values 
        "Elevation"),   -- Elevation field
      1,  -- width for true condition
      0.2 -- width for false condition

enter image description here

  • Does this only work up to an elevation of 100? Commented Mar 3, 2023 at 12:57
  • No. You can add additional values to array(10, 100). For example, array(10, 100, 200, 300, etc.) Commented Mar 3, 2023 at 13:02
  • Thanks Kadir Şahbaz and @TeddyTedTed for two great answers to the question I asked but on reflection it is not the question I meant to ask. I have cheekily edited it and hope you will be able to amend answers accordingly. Hoping this is not out of order. Commented Mar 3, 2023 at 22:52
  • You can still use @TeddyTedTed's answer below, but just change the expression formula slightly eg: IF("ELEV" % 100 = 0, 1, IF("ELEV" % 10 = 0, 0.5, 0.25)) Commented Mar 4, 2023 at 2:30

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.