I'm a working on a QGIS script that could activate/deactivate rule-based styles of the vector layer in a loop (one active layer per iteration). On the every iteration this scenario should:

  1. Activate one of the prearranged style rules for a given vector layer and deactivate all other;
  2. Save current view as JPEG screenshot;

In my particular case the vector layer is a PostGIS table that contains the contours derived from some raster layer. Rules are based on the distinct values of the isolines. I take screenshot of the map for the every activated rule and finally put them all into the animated gif.

Animated gif

Since list of the rule-based styles can be very long, I'm looking torward the PyQGIS code snippet that could go through the one in a loop.

1 Answer 1


Even without programming, I think it should be possible to achieve this using the idea presented in http://nathanw.net/2014/09/23/qgis-atlas-on-non-geometry-tables/: use the Atlas functionality to loop through a coverage layer containing values for the rule-based rendering of e.g. your contours.

I imagine you will want to compare one of the contour attributes to a value in the coverage layer and control e.g. the line color transparency. To do that, you can expand on the example Nathan showed in his post:

enter image description here

CASE WHEN "contour_value" = attribute($atlasfeature,'value') 
     THEN color_rgba(0,0,255,255)
     ELSE color_rgba(0,0,255,0)

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.