Автоматизація створення мап за допомогою Print Composer Atlas

Попередження

A new version of this tutorial is available at Автоматизація створення мап за допомогою Print Composer 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 Composer, please go through the Створення мапи tutorial.

Огляд завдання

В цьому уроці показано як створити мапу водно-болотяних угідь для кожного округу штату Гаваї.

Додаткові навички

  • How to use the Inverted Polygons style renderer to fill areas outside of polygons.

  • How to use an expression in the Rule Based style renderer to show only the current feature in Atlas.

  • Apply expressions to create dynamic labels in Print Composer.

Отримання даних

We will use the GIS Data Layers from State of Hawaii - Office of Planning

Download the Wetlands layer from Biologic and Ecologic category.

Download the Census County Boundaries 2010 layer from the Cultural and Demographic category.

Для зручності, ви можете безпосередньо завантажити копію обох наборів даних за допомогою наведених нижче посилань:

HI_Wetlands.shp.zip

county10.shp.zip

Джерело даних [HAWAII]

Виконання

  1. Запустіть QGIS і перейдіть у меню Layer ‣ Add Layer ‣ Add Vector Layer.

../_images/1156.png
  1. Виберіть файл HI_Wetlands.shp.zip і натисніть кнопку Open.

../_images/2129.png
  1. Виберіть шар HI_Wetlands_Poly і натисніть кнопку OK.

../_images/366.png
  1. You will see the polygons representing the wetlands in the entire state of Hawaii. Since we want to make separate wetlands map for each county in the state, we will need the county boundaries layer. Go to Layer ‣ Add Layer ‣ Add Vector Layer and browse to the county10.shp.zip file. Click Open.

../_images/436.png
  1. Перейдіть у Project ‣ New Print Composer.

../_images/535.png
  1. Leave the composer title field empty and click OK.

../_images/634.png
  1. Перейдіть у Layout ‣ Add Map.

../_images/734.png
  1. Drag a rectangle while holding the left mouse button where you would like to insert the map.

../_images/833.png
  1. Scroll down in the Item Properties tab and check the Controlled by atlas box. This will indicate the composer that the extent of the map displayed in this item will be determined by the Atlas tool.

../_images/934.png
  1. Switch to the Atlas generation tab. Check the Generate an atlas box. 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/1041.png
  1. You will notice that the map image does not change after configuring the Atlas settings. Go to Atlas ‣ Preview Atlas.

../_images/1157.png
  1. Now you will see the map refresh and show how individual map will look like. Notice that it shows the current feature number from the coverage layer at the bottom right.

../_images/1244.png
  1. You can preview how the map will look for each of the county polygons. Go to Atlas ‣ Next Feature.

../_images/1342.png
  1. Atlas will render the map to the extent of the next feature in the coverage layer.

../_images/1439.png
  1. Let’s add a label to the map. Go to Layout ‣ Add Label.

../_images/1536.png
  1. Under the Item properties tab, click Insert an expression… button.

../_images/1634.png
  1. The label of the map can use the attributes from the coverage layer.he concat function is used to join multiple text items into a single text item. In this case we will join the value of the NAME10 attribute of the county10 layer with the text County of. Add an expression like below and click OK.

concat('County of ', "NAME10")
  1. Налаштуйте розмір шрифту на ваш смак.

../_images/1829.png
  1. Add another label and enter Wetlands Map under the Main properties. Since there is no expression here, this text will remain the same on all maps.

../_images/1923.png
  1. Go to Atlas ‣ Last Feature and verify that the map labels do work as intended. You will notice that the wetland map has polygons extending out in the ocean that looks ugly. We can change the style to that areas outside the county boundaries are hidden.

../_images/2020.png
  1. Switch to the main QGIS window. Right-click the county10 layer and select Properties.

../_images/2130.png
  1. In the Style 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/2222.png
  1. Switch to the Print Composer window. If we want the effect of the inverted polygons to show, we need to uncheck the Hidden coverage layer box under Atlas generation. You will now see that the rendered image is clean and areas outside the coverage polygon is not visible.

../_images/2319.png
  1. There is one problem though. You can see areas of the map that are outside the coverage layer boundary but 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/2419.png
  1. In the Style tab, select Rule-based renderer as the Sub renderer. Double-click the area under Rule.

../_images/2519.png
  1. Click the button next to Filter.

../_images/2616.png
  1. In the Expression string builder, expand the Atlas group of functions. The $atlasfeatureid function will return the currently selected feature. We will construct an expression that will select only the currently selected Atlas feature. Enter the expression as below:

$id = $atlasfeatureid
../_images/2715.png
  1. Back in the Print Composer window, 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.

../_images/2816.png
  1. We will now add another dynamic label to show the current date. Go to Layout ‣ Add Label and select the area on the map. Click Insert an expression button.

../_images/2914.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:

concat('Created on: ', todate($now))
../_images/3013.png
  1. Add another label citing the data source. You may also add other map elements such as a north arrow, scalebar etc. as described in Створення мапи tutorial.

../_images/3116.png
  1. Once you are satisfied with the map layout, go to Atlas ‣ Export Atlas as Images.

../_images/3213.png
  1. Виберіть директорію на вашому комп’ютері і натисніть Вибрати.

../_images/3310.png
  1. The Atlas tool will now iterate through each feature in the coverage layer and create a separate map image based on the template we created. You can see the images in the directory once the process completes.

../_images/3410.png
  1. Here are the map images for refeence.

../_images/35_1.jpg ../_images/35_2.jpg ../_images/35_3.jpg ../_images/35_4.jpg ../_images/35_5.jpg

If you want to report any issues with this tutorial, please comment below. (requires GitHub account)