{"id":739,"date":"2016-10-10T22:33:12","date_gmt":"2016-10-10T20:33:12","guid":{"rendered":"http:\/\/hannes.enjoys.it\/blog\/?p=739"},"modified":"2016-10-11T19:23:45","modified_gmt":"2016-10-11T17:23:45","slug":"doing-things-to-the-whole-map-canvas-in-qgis","status":"publish","type":"post","link":"https:\/\/hannes.enjoys.it\/blog\/2016\/10\/doing-things-to-the-whole-map-canvas-in-qgis\/","title":{"rendered":"Doing things to the whole map canvas in QGIS"},"content":{"rendered":"<blockquote><p><strong>Due to a <a href=\"https:\/\/hub.qgis.org\/issues\/15672\">minor bug<\/a> in QGIS you need a very recent testing build. 2.16.3 is not recent enough but 2.16.4 would be.<\/strong><\/p><\/blockquote>\n<p>For cool tricks like vignetting or other eye candy, having a geometry that spans the whole map canvas in QGIS can be very useful.<\/p>\n<p>Using the <code>@map_*<\/code> Variables available in expressions in combination with a Geometry generator style allows you to do this.<\/p>\n<p><code>@map_extent_center<\/code> returns a Point geometry of the current map canvas center, with <code>x(@map_extent_center)<\/code> and <code>y(@map_extent_center)<\/code> you get the x and y coordinates of it in the current CRS.<br \/>\n<code>@map_extent_width<\/code> and <code>@map_extent_height<\/code> return the width respectively height of the map canvas in CRS units.<\/p>\n<p>Our goal is to create a polygon that exactly matches the map canvas extents. Some simple math gets you there.<\/p>\n<p>First create Points for each of the corners by alternating the x+\/-width and y+\/-height. Then create a Line from all of them (the last point does not need to be the first again, <code>make_polygon<\/code> does that for you). And use the line as outer ring for a Polygon.<\/p>\n<pre lang=\"c\">\r\nmake_polygon(\r\n make_line(\r\n  make_point(x(@map_extent_center)-@map_extent_width\/2, y(@map_extent_center)-@map_extent_height\/2),\r\n  make_point(x(@map_extent_center)+@map_extent_width\/2, y(@map_extent_center)-@map_extent_height\/2),\r\n  make_point(x(@map_extent_center)+@map_extent_width\/2, y(@map_extent_center)+@map_extent_height\/2),\r\n  make_point(x(@map_extent_center)-@map_extent_width\/2, y(@map_extent_center)+@map_extent_height\/2)\r\n )\r\n)\r\n<\/pre>\n<p>To actually see this, you need to use the style on a layer with at least one feature that is always visible where you want to focus your map canvas. Just make a polygon layer with one polygon that encloses the whole area. The layer must be in the same CRS as the project I think.<\/p>\n<p>You now have a Polygon that corresponds with the map canvas. Give it a radial gradient fill with some transparency and party!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"671\" height=\"627\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/radialgradient.png\" alt=\"radialgradient\" class=\"aligncenter size-full wp-image-746\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/radialgradient.png 671w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/radialgradient-250x234.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/radialgradient-120x112.png 120w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><br \/>\n<img loading=\"lazy\" decoding=\"async\" width=\"671\" height=\"627\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/hh-bw.png\" alt=\"hh-bw\" class=\"aligncenter size-full wp-image-747\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/hh-bw.png 671w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/hh-bw-250x234.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/hh-bw-120x112.png 120w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><br \/>\n<img loading=\"lazy\" decoding=\"async\" width=\"671\" height=\"627\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/schiff-bw.png\" alt=\"schiff-bw\" class=\"aligncenter size-full wp-image-748\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/schiff-bw.png 671w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/schiff-bw-250x234.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/schiff-bw-120x112.png 120w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><br \/>\n<img loading=\"lazy\" decoding=\"async\" width=\"671\" height=\"627\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/stadion-bw.png\" alt=\"stadion-bw\" class=\"aligncenter size-full wp-image-749\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/stadion-bw.png 671w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/stadion-bw-250x234.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/stadion-bw-120x112.png 120w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><br \/>\n<img loading=\"lazy\" decoding=\"async\" width=\"671\" height=\"627\" src=\"http:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/stadion-red.png\" alt=\"stadion-red\" class=\"aligncenter size-full wp-image-750\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/stadion-red.png 671w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/stadion-red-250x234.png 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/stadion-red-120x112.png 120w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><\/p>\n<p>All aerial images in the examples are <\/p>\n<blockquote><p>Lizenz: Datenlizenz Deutschland Namensnennung 2.0<br \/>\nNamensnennung: Freie und Hansestadt Hamburg, Landesbetrieb Geoinformation und Vermessung<br \/>\n<a href=\"http:\/\/daten-hamburg.de\/geographie_geologie_geobasisdaten\/digitale_orthophotos\/DOP20\/DOP20_HH_fruehjahrsbefliegung_2015.zip\">http:\/\/daten-hamburg.de\/geographie_geologie_geobasisdaten\/digitale_orthophotos\/DOP20\/DOP20_HH_fruehjahrsbefliegung_2015.zip<\/a><\/p><\/blockquote>\n<p>To make sure the feature you want to highlight is in the center, you could use another layer and <code>@map_extent_center<\/code>.<\/p>\n<p>Yes, this totally is a hack but it&#8217;s fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Due to a minor bug in QGIS you need a very recent testing build. 2.16.3 is not recent enough but 2.16.4 would be. For cool tricks like vignetting or other eye candy, having a geometry that spans the whole map canvas in QGIS can be very useful. Using the @map_* Variables available in expressions in [&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-739","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\/739","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=739"}],"version-history":[{"count":11,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/739\/revisions"}],"predecessor-version":[{"id":756,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/739\/revisions\/756"}],"wp:attachment":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/media?parent=739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/categories?post=739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/tags?post=739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}