{"id":484,"date":"2015-05-22T21:08:42","date_gmt":"2015-05-22T19:08:42","guid":{"rendered":"http:\/\/hannes.enjoys.it\/blog\/?p=484"},"modified":"2015-05-22T21:54:30","modified_gmt":"2015-05-22T19:54:30","slug":"fancy-shaded-and-scaled-contour-lines-in-qgis","status":"publish","type":"post","link":"https:\/\/hannes.enjoys.it\/blog\/2015\/05\/fancy-shaded-and-scaled-contour-lines-in-qgis\/","title":{"rendered":"Fancy shaded and scaled contour lines in QGIS"},"content":{"rendered":"<p><a href=\"http:\/\/cargocollective.com\/somethingaboutmaps\">Daniel P. Huffman<\/a> <a href=\"https:\/\/twitter.com\/pinakographos\/status\/601747993197293568\">shared<\/a> this gorgeous map earlier. ArcMap <a href=\"http:\/\/blogs.esri.com\/esri\/arcgis\/2015\/05\/21\/take-your-terrain-mapping-to-new-heights\/\">just got<\/a> the functionality to create such contour lines.<\/p>\n<p><a href=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/CFnWnA5UkAAuFm9.png\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"525\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/CFnWnA5UkAAuFm9-700x525.png\" alt=\"CFnWnA5UkAAuFm9\" class=\"alignnone size-large wp-image-512\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/CFnWnA5UkAAuFm9-700x525.png 700w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/CFnWnA5UkAAuFm9-250x188.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/CFnWnA5UkAAuFm9-120x90.png 120w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/CFnWnA5UkAAuFm9.png 1024w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\n<p>Naturally I had to try to re-create that style in QGIS. I semi-succeeded:<\/p>\n<p>You have a DEM, eg <a href=\"http:\/\/extract.cr.usgs.gov\/public\/NED\/mtsthelens_after.zip\">mtsthelens_after.zip<\/a>. Generate a hillshade from DEM. Generate contour lines from DEM.<br \/>\n<a href=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/dem.png\"><img loading=\"lazy\" decoding=\"async\" width=\"250\" height=\"190\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/dem-250x190.png\" alt=\"dem\" class=\"alignnone size-medium wp-image-500\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/dem-250x190.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/dem-700x531.png 700w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/dem-120x91.png 120w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/dem.png 1040w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a> <a href=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/hillshade.png\"><img loading=\"lazy\" decoding=\"async\" width=\"250\" height=\"190\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/hillshade-250x190.png\" alt=\"hillshade\" class=\"alignnone size-medium wp-image-501\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/hillshade-250x190.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/hillshade-700x531.png 700w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/hillshade-120x91.png 120w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/hillshade.png 1040w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a> <a href=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/contours.png\"><img loading=\"lazy\" decoding=\"async\" width=\"250\" height=\"190\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/contours-250x190.png\" alt=\"contours\" class=\"alignnone size-medium wp-image-502\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/contours-250x190.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/contours-700x531.png 700w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/contours-120x91.png 120w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/contours.png 1040w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>Split the lines by segment, for example with the &#8220;Network&#8221; plugin. Select all features on your layer and then use its &#8220;Split&#8221; function.<br \/>\nCalculate the azimuth of each line. See <a href=\"http:\/\/gis.stackexchange.com\/questions\/24260\/how-to-add-direction-and-distance-to-attribute-table\">this magical formula<\/a> (I wish QGIS would have a function ready).<br \/>\nRotate the angle according to your hillshade light angle. For example:<br \/>\n<code>CASE<br \/>\n&nbsp;WHEN (\"azimuth\"+270) > 360<br \/>\n&nbsp;&nbsp;THEN (\"azimuth\"+270-360)\/500<br \/>\n&nbsp;ELSE (\"azimuth\"+270)\/500<br \/>\nEND<\/code><br \/>\nAnd use that to scale your lines&#8217; widths (the 500 is a constant factor here to get them small enough).<\/p>\n<p>Disable all layers but hillshade and contour lines.<br \/>\nMove hillshade above contour lines.<br \/>\nSet map background to black (equals 0 in the blending multiplication later).<br \/>\nUse black to white as color ramp for the hillshade.<br \/>\nSet hillshade&#8217;s blending mode to multiply.<br \/>\nYou now have the bright parts of the contour lines. Unfortunately QGIS does not yet support blending modes for whole groups so you will have to combine this with the next step in a raster graphics tool of your choice. Gimp works fine.<br \/>\nTake a screenshot of something.<\/p>\n<p>Invert hillshade color ramp to white to black.<br \/>\nRotate your angle by 180 (so it would be 90 instead of 270 in the example above).<br \/>\nYou now have the dark lines.<br \/>\nTake another screenshot.<br \/>\n<a href=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul270.png\"><img loading=\"lazy\" decoding=\"async\" width=\"250\" height=\"190\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul270-250x190.png\" alt=\"conscalehilmul270\" class=\"alignnone size-medium wp-image-509\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul270-250x190.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul270-700x531.png 700w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul270-120x91.png 120w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul270.png 1040w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a> <a href=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul90.png\"><img loading=\"lazy\" decoding=\"async\" width=\"250\" height=\"190\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul90-250x190.png\" alt=\"conscalehilmul90\" class=\"alignnone size-medium wp-image-510\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul90-250x190.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul90-700x531.png 700w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul90-120x91.png 120w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/conscalehilmul90.png 1040w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><br \/>\nAdd both images to a image in Gimp, Color to Alpha with black, invert the dark one, choose nice background, done!<\/p>\n<p><a href=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/scaled-line-width.png\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"531\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/scaled-line-width-700x531.png\" alt=\"scaled line width\" class=\"alignnone size-large wp-image-498\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/scaled-line-width-700x531.png 700w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/scaled-line-width-250x190.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/scaled-line-width-120x91.png 120w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/scaled-line-width.png 1040w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\n<p>This is still pretty rough as it&#8217;s mostly hack after hack and not &#8220;done properly&#8221;\u2122. The blending adds some shadows where there should not be. In a way the lines end up being same width because of this. The scaling was done arbitrarily, there is probably some smart way with a better scale. Some fancy smoothing of the lines would look great. Coloring the areas between the lines would probably improve it as well. Once QGIS gets support for blending modes of groups, this will be much easier.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Daniel P. Huffman shared this gorgeous map earlier. ArcMap just got the functionality to create such contour lines. Naturally I had to try to re-create that style in QGIS. I semi-succeeded: You have a DEM, eg mtsthelens_after.zip. Generate a hillshade from DEM. Generate contour lines from DEM. Split the lines by segment, for example with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,29,31],"tags":[],"class_list":["post-484","post","type-post","status-publish","format-standard","hentry","category-cartography","category-gis","category-qgis"],"_links":{"self":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/comments?post=484"}],"version-history":[{"count":18,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/484\/revisions"}],"predecessor-version":[{"id":520,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/484\/revisions\/520"}],"wp:attachment":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/media?parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/categories?post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/tags?post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}