Automating Map Creation with Print Layout Atlas (QGIS3)

If your organization publishes printed or online maps, you often would need to create many maps with the same template - usually one for each administrative unit or a region of interest. Creating these maps manually can take a long time and if you want to update these on a regular basis, it can turn into a chore. QGIS has a tool called Atlas that can help you create a map template and easily publish a large number of maps for different geographic regions. If you are not familiar with the basics of Print Layout, please go through the 製作地圖 tutorial.

內容說明

本教學將示範如何為夏威夷州的每個縣製作濕地地圖。

你還會學到這些

  • 使用 反轉多邊形 樣式設定多邊形外側的區域樣式

  • Write an expression in the Rule Based style renderer to show only the current feature in Atlas.
  • Write an expression to create dynamic labels in Print Layout.
  • Using Shapeburst fill style renderer to create a dual-tone polygon fill.

取得資料

本章中我們使用的是夏威夷州 Office of Planning提供的 GIS 資料圖層

下載隸屬於生物與生態類別的濕地圖層

下載隸屬於文化與人口統計類別的 2010 郡縣邊界 圖層

為了方便起見,你也可以直接用下面的連結下載這兩份資料集:

HI_Wetlands.shp.zip

county10.shp.zip

資料來源 [HAWAII]

操作流程

  1. Locate the HI_Wetlands.shp.zip file in the QGIS Browser and expand it. Select the HI_Wetlands_Poly.shp file and drag it to the canvas. This layer contains polygons representing wetlands in the entire state of Hawaii.
../../_images/110.png
  1. Since we want to make separate wetlands map for each county in the state, we will need the county boundaries layer. Browse to the county10.shp.zip file and expand it. Select the county10.shp file and drag it to the canvas.
../../_images/22.png
  1. Turn off the visibility of the HI_Wetlands_Poly layer temporarily. You will see the polygons from the county10 layer clearly now. There are 5 features contained in this layer, with each feature having 1 or more polygons associated with it. The features represent 5 counties. We will use this layer as the coverage layer and configure QGIS to create 5 separate maps - one for each feature - automatically.
../../_images/32.png
  1. Turn on the visibility of the HI_Wetlands_Poly layer. Go to Project ‣ New Print Layout...
../../_images/42.png
  1. Leave the print layout title empty and click OK.
../../_images/52.png
  1. In the Print Layout window, go to Layout ‣ Add Map.
../../_images/62.png
  1. 在地圖版面上拖曳一塊你想插入地圖的區域。

../../_images/72.png
  1. In QGIS3, the Atlas tab is not visible by default. Select View ‣ Panels ‣ Atlas.
../../_images/82.png
  1. Switch to the Atlas tab. Check the Generate an atlas box.
../../_images/92.png
  1. Select the county10 as the Coverage layer. This will indicate that we want to create 1 map each for every polygon feature in the county10 layer. You can also check the Hidden coverage layer so that the features themselves will not appear on the map.
../../_images/102.png
  1. Switch to the Item Properties tab. Scroll down and check the Controlled by atlas box. This will indicate the layout that the content of the map displayed in this item will be determined by the Atlas tool.

註解

You must enable the Generare an atlas box in the Atlas tab, otherwise the Controlled by atlas checkbox will be diasbled.

../../_images/111.png
  1. Now that you have configuring the Atlas settings, go to Atlas ‣ Preview Atlas.
../../_images/122.png
  1. You will see the map refresh and show how individual map will look like. You can preview how the map will look for each of the county polygons. Go to Atlas ‣ Next Feature. Atlas will render the map to the extent of the next feature in the coverage layer.
../../_images/132.png
  1. 來加點標記吧!選擇 圖層 ‣ 加入標記

../../_images/142.png
  1. Under the Item properties tab, locate the Main properties section and click Insert an Expression... button.
../../_images/152.png
  1. 在此功能中,標記文字可以使用覆蓋圖層的屬性。我們要使用 concat 函數來把兩段字串合併,而要合併的字串分別為 County ofcounty10 圖層中的 NAME10 屬性值。加入以下的表達式後,按下 確定

concat('County of ', "NAME10")
../../_images/162.png
  1. Delete the leading Lorem ipsum placeholder text so that the textbox contains only the expression. Scroll down to the Appearance section and click on the Font dropdown. Choose the font and adjust the size to your liking.
../../_images/172.png
  1. Choose Center as the Horizontal alignment and Middle as the Vertical alignment option.
../../_images/182.png
  1. 加入另一個標記,然後在 主要屬性 下輸入 Wetlands Map。由於沒有使用表達式,此文字在所有的地圖中都會相同。

../../_images/192.png
  1. 選擇 輿圖 ‣ 最後一個圖徵,然後確認地圖標記有照我們所想的運作。目前濕地地圖上的多邊形也延伸到了海中,看起來不怎麼美觀,所以接著我們就要來改變樣式,隱藏郡縣邊界外側的多邊形圖徵。

../../_images/201.png
  1. 切換到 QGIS 主視窗,在 county10 圖層上按右鍵選擇 屬性

../../_images/212.png
  1. In the Symbology tab, select the Inverted polygons renderer. This renderer styles the outside of the polygon - not inside. Select white as the fill color and click OK.
../../_images/221.png
  1. You will notice that the polygons extending outside of the county boundaries are now disappeared. In reality, they are hidden by the white color fill extending out from the county polygons because of the Inverted polygons style.
../../_images/23.png
  1. Switch to the Layout window. If we want the effect of the inverted polygons to show, we need to uncheck the Hidden coverage layer box under Atlas tab. Once unchecked, the rendered image will appear clean and areas outside the coverage polygon is not visible.
../../_images/24.png
  1. There is one more problem though. You will notice that in some cases, parts of the map that are outside the coverage layer boundary are still visible. This is because Atlas doesn’t automatically hide other features. This can be useful in some cases, but for our purpose, we only want to show wetlands of the county whose map is being generated. To fix this, switch back to the main QGIS window and right-click the county10 layer and select Properties.
../../_images/25.png
  1. In the Symbology tab, select Rule-based as the Sub renderer. Double-click the area under Rule.
../../_images/26.png
  1. In the Edit rule dialog, click the Expression button next to Filter.
../../_images/27.png
  1. In the Expression string builder, expand the Variables group of functions. The @atlas_featureid variable stores the id of the the currently selected feature. We will construct an expression that will select only the currently selected Atlas feature. Enter the expression as below and click OK.
$id = @atlas_featureid
../../_images/28.png
  1. Close all intermediate dialogs and switch back to the Layout window. Select Map 1 item and click the Update preview button under Item properties tab to see the changes. Notice that now only the area covering the county boundary is shown.

註解

If you do not see the Update preview button, it may help to select another Item element first and then select Map 1 again.

../../_images/29.png
  1. 我們再來加入另一個新的標記,用來標示現在的日期。選擇 圖層 ‣ 加入標記 然後選擇地圖上的任一區域,完成後按下 插入表示式 鈕。

../../_images/30.png
  1. Expand the Date and Time functions group and you will find the $now function. This holds the current system time. The function todate() will convert this to a date string. Enter the expression as below and click OK.
concat('Created on: ', todate($now))
../../_images/311.png
  1. 再加入另外一個標記,引用資料來源。你也可以順道加入其他的地圖元素,例如指北針等等,請參考 製作地圖 一章的說明。

../../_images/321.png
  1. We will make one last styling improvement. Switch back to the main QGIS window and right-click the HI_Wetlands_Poly layer and select Properties.
../../_images/33.png
  1. In the Symbology tab, click on Simple fill and select Shapeburst fill as the Symbol layer type. Choose the Two color option and select shades of green and blue that you like. Click OK.
../../_images/34.png
  1. Select Map 1 item and click the Update preview button under Item properties tab to see the changes.
../../_images/35.png
  1. Once you are satisfied with the map layout and styling, go to Atlas ‣ Export Atlas as Images.
../../_images/36.png
  1. 選擇電腦中的某資料夾,然後按下 選擇 鈕。

../../_images/37.png
  1. Leave the default options in the Image Export Options and click Save.
../../_images/38.png
  1. 輿圖工具會自動地使用我們剛剛建立的範本,為覆蓋圖層中的每個圖徵創造各自的地圖。處理完成後,在資料夾中就能找到這些地圖。

../../_images/39.png
  1. 這裡放上完成版地圖以供參考。

../../_images/output_1.png ../../_images/output_2.png ../../_images/output_3.png ../../_images/output_4.png ../../_images/output_5.png
comments powered by Disqus

This work is licensed under a Creative Commons Attribution 4.0 International License