If you follow my blog, you’ve most certainly seen the post How to create illuminated contours, Tanaka-style from earlier this year. As Victor Olaya noted correctly in the comments, the workflow to create this effect lends itself perfectly to being automated with a Processing model.
The model needs only two inputs: the digital elevation model raster and the interval at which we want the contours to be created:
The model steps are straightforward: the contours are generated and split into short segments before the segment orientation is computed using the following code in the Advanced Python Field Calculator:
p1 = $geom.asPolyline() p2 = $geom.asPolyline()[-1] a = p1.azimuth(p2) if a < 0: a += 360 value = a
You can find the finished model on Github. Happy QGISing!