{"id":1158,"date":"2019-01-09T18:03:40","date_gmt":"2019-01-09T17:03:40","guid":{"rendered":"https:\/\/hannes.enjoys.it\/blog\/?p=1158"},"modified":"2019-07-07T23:56:07","modified_gmt":"2019-07-07T21:56:07","slug":"data-defined-images-in-qgis-atlas","status":"publish","type":"post","link":"https:\/\/hannes.enjoys.it\/blog\/2019\/01\/data-defined-images-in-qgis-atlas\/","title":{"rendered":"Data-defined images in QGIS Atlas"},"content":{"rendered":"\n<p>Say you want to display a feature specific image on each page of a QGIS Atlas.<\/p>\n\n\n\n<p>In my example I have a layer with two features:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n  \"type\": \"FeatureCollection\",\n  \"features\": [\n    {\n      \"type\": \"Feature\",\n      \"properties\": {\n        \"image_path\": \"\/tmp\/1.jpeg\"\n      },\n      \"geometry\": {\n        \"type\": \"Polygon\",\n        \"coordinates\": [[[9,53],[11,53],[11,54],[9,54],[9,53]]]\n      }\n    },\n    {\n      \"type\": \"Feature\",\n      \"properties\": {\n        \"image_path\": \"\/tmp\/2.jpeg\"\n      },\n      \"geometry\": {\n        \"type\": \"Polygon\",\n        \"coordinates\": [[[13,52],[14,52],[14,53],[13,53],[13,52]]]\n      }\n    }\n  ]\n}<\/pre>\n\n\n\n<p>And I also have two JPEG images, named &#8220;1.jpeg&#8221; and &#8220;2.jpeg&#8221; are in my \/tmp\/ directory, just as the &#8220;image_path&#8221; attribute values suggest.<\/p>\n\n\n\n<p>The goal is to have a map for each feature and its image displayed on the same page.<\/p>\n\n\n\n<p>Create a new print layout, enable Atlas, add a map (controlled by Atlas, using the layer) and also an image.<\/p>\n\n\n\n<p>For the &#8220;image source&#8221; enable the data-defined override and use <code>attribute(@atlas_feature, 'image_path')<\/code>&nbsp;as&nbsp;expression.<\/p>\n\n\n\n<p>That&#8217;s it, now QGIS will try to load the image referenced in the feature&#8217;s &#8220;image_path&#8221; value as source for the image on the Atlas page. Yay kittens!<\/p>\n\n\n\n<ul class=\"wp-block-gallery columns-2 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"374\" height=\"264\" src=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/output_1.jpg\" alt=\"\" data-id=\"1160\" data-link=\"https:\/\/hannes.enjoys.it\/blog\/?attachment_id=1160\" class=\"wp-image-1160\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/output_1.jpg 374w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/output_1-250x176.jpg 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/output_1-120x85.jpg 120w\" sizes=\"auto, (max-width: 374px) 100vw, 374px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"374\" height=\"264\" src=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/output_2.jpg\" alt=\"\" data-id=\"1161\" data-link=\"https:\/\/hannes.enjoys.it\/blog\/?attachment_id=1161\" class=\"wp-image-1161\" srcset=\"https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/output_2.jpg 374w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/output_2-250x176.jpg 250w, https:\/\/hannes.enjoys.it\/blog\/wp-content\/uploads\/output_2-120x85.jpg 120w\" sizes=\"auto, (max-width: 374px) 100vw, 374px\" \/><\/figure><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Say you want to display a feature specific image on each page of a QGIS Atlas. In my example I have a layer with two features: { &#8220;type&#8221;: &#8220;FeatureCollection&#8221;, &#8220;features&#8221;: [ { &#8220;type&#8221;: &#8220;Feature&#8221;, &#8220;properties&#8221;: { &#8220;image_path&#8221;: &#8220;\/tmp\/1.jpeg&#8221; }, &#8220;geometry&#8221;: { &#8220;type&#8221;: &#8220;Polygon&#8221;, &#8220;coordinates&#8221;: [[[9,53],[11,53],[11,54],[9,54],[9,53]]] } }, { &#8220;type&#8221;: &#8220;Feature&#8221;, &#8220;properties&#8221;: { &#8220;image_path&#8221;: &#8220;\/tmp\/2.jpeg&#8221; }, [&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,40],"tags":[],"class_list":["post-1158","post","type-post","status-publish","format-standard","hentry","category-cartography","category-gis","category-qgis","category-small-things"],"_links":{"self":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/1158","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=1158"}],"version-history":[{"count":4,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/1158\/revisions"}],"predecessor-version":[{"id":1299,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/posts\/1158\/revisions\/1299"}],"wp:attachment":[{"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/media?parent=1158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/categories?post=1158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hannes.enjoys.it\/blog\/wp-json\/wp\/v2\/tags?post=1158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}