11

I know how to make the visibility of an entire layer conditional on the zoom level.

Is there a way to do the same thing for specific features? I have a road data set, where each feature has a class attribute that roughly corresponds to the "size" of a road (major highway, minor road, etc). I would like to configure things so that when zoomed out, only major roads are visible, with more detail showing as one zooms in on the map.

I guess I could split each class of roads out into a separate layer, but is there a way to do this that allows me to keep all the features in a single layer?

2 Answers 2

14

You can change the style to be rule-based (it will preserve the classes if a categorized style was previously set), and there you can control the display scale of each class/rule.

enter image description here

enter image description here

1
  • Oh, that's handy! That's a bit more discoverable than the data-defined override.
    – larsks
    Commented Jun 30, 2021 at 13:42
11

Get ready for the probably most useful option when it comes to symbology: data defined override

My suggestion: For each of your classes, set the line type based on your current scale, e.g. if(@map_scale <250000,'solid','no') - this either draws a continuous line, while the scale is below 1:250000, or no line, if the scale is above.

Where to enter this? Have a look at the screenshot: enter image description here

Open the symbology of one of your classes, head for the line style, hit the data defined override symbol to the right of it, then go for "edit".

Naturally, this is a bit of a hassle if you have more complex line styles.

1
  • Thanks, this works, although for some reason I had to replace your if(...) expression with a case...end expression to make it work.
    – larsks
    Commented Jun 30, 2021 at 13:28

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.