14.6. 课: 使用地图集工具创建详细地图

系统抽样设计已准备就绪,现场团队也已将GPS坐标加载到其导航设备中。他们还有一个现场数据表单,在那里将收集每个取样地测量的信息。为了更容易地找到每个取样地,他们要求提供一些详细地图,其中可以清楚地看到一些地面信息,以及较小取样地子集和一些有关地图区域的信息。您可以使用地图集工具自动生成许多具有共同格式的地图。

本课目标: 学习使用QGIS中的地图集工具生成详细的可打印地图,以协助实地清查工作。

14.6.1. basic 跟我做: 准备打印布局

在我们可以自动操作林区和取样地块的详细地图之前,需要创建一个地图模板,其中包含我们认为对实地工作有用的所有元素。当然,最重要的是正确的样式,但正如您之前所看到的,还需要添加许多其他元素来完成打印地图。

  1. Open the QGIS project from the previous lesson forest_inventory.qgs. You should have at least the following layers:

    • forest_stands_2012 (with a 50% transparency, green fill and darker green border lines)

    • systematic_plots_clip

    • rautjarvi_aerial

  2. Save the project with a new name, map_creation.qgs.

要创建可打印地图,请记住要使用 布局管理器:

  1. Open Project ► layoutManager Layout Manager....

  2. In the Layout manager dialog:

    1. Under New from template, press the Create... button next to the Empty layout entry

    2. Name your print layout forest_map.

    3. Press OK. A new print layout is created and opened, showing a blank paper.

  3. In the print Layout window, ensure properties are set for an A4 paper:

    1. Right-click over the paper and select Page properties. The Page properties panel is open on the right side of the layout.

    2. Check Size is A4.

    3. Check Orientation is Landscape.

  4. Enable the Layout tab next to the Page properties panel and set Export resolution to 300 dpi.

如果使用画布网格来定位不同的元素,则排版地图会更容易。检查布局网格的设置:

  1. In the Layout tab expand the Guides and Grid region.

  2. Check that Grid spacing is set to 10 mm and that Snap tolerance is set to 5 px.

您需要激活网格的使用:

  1. 打开 视图 菜单。

  2. Check Show grid.

  3. 勾选 捕捉到网格

  4. Notice that options for using Guides are checked by default, which allows you to see guiding lines when you are moving elements in the layout.

  5. 现在可以开始向布局中添加元素了。首先添加地图元素,以便在更改图层符号时查看地图画布的外观:

    1. 单击 addMap 添加地图 按钮。

    2. 在画布上单击并拖动一个框,使地图占据其中大部分。

    ../../../_images/composer_1.png

请注意鼠标光标是如何捕捉到画布网格的,添加其他元素时也可以使用此功能。如果要获得更高的精度,请更改网格 间距 设置。如果出于某种原因不想在某个点捕捉到网格,可以随时在 视图 菜单中勾选或取消勾选。

14.6.2. basic 跟我做: 添加背景地图

Leave the layout open but go back to the map. Let's add some background data and create some styling so that the map content is as clear as possible.

  1. 添加背景栅格 basic_map.tif ,您可以在 exercise_data\forestry\ 文件夹找到此文件。

  2. If prompted select the ETRS89 / ETRS-TM35FIN CRS for the raster.

    如您所见,背景地图已经设置了样式。这种即用类型制图栅格非常常见。它是从矢量数据创建,以标准格式设置样式并储存为栅格,这样您就不必费心设置多个矢量图层的样式,也不必担心会得到不理想的结果。

  3. 现在缩放到取样地,以便您只能看到大约四到五行的地块。

The current styling of the sample plots is not the best:

../../../_images/plots_zoom1-2.png

While during the last exercises, the white buffer was OK on top of the aerial image, now that the background image is mostly white you barely can see the labels. But how does it look in the print layout? Let's check it:

  1. Go to the print layout window.

  2. Use the select Select/Move item button to select the map element in the layout.

  3. 转到 项属性 标签页。

  4. Click on setToCanvasExtent Set map extent to match main canvas extent.

  5. If you need to refresh the element, click on refresh Update map preview.

Obviously this is not good enough; you want to make the plot numbers as clearly visible as possible for the field teams.

14.6.3. basic 试一试 更改图层符号

您曾经在 单元: 创建和探索基本地图 使用符号,在 单元: 分类矢量数据 使用过标注。如果需要重新了解某些可用选项和工具,请返回这些单元。您的目标是在始终允许查看背景地图元素的前提下使地块位置及其名称尽可能清晰可见。可以从这张图像中得到一些启发:

../../../_images/plots_zoom2_symbology.png

You will use later the the green styling of the forest_stands_2012 layer. In order to keep it, and have a visualization of it that shows only the stand borders:

  1. Right click on forest_stands_2012 and select Duplicate

  2. You get a new layer named forest_stands_2012 copy that you can use to define a different style, for example with no filling and red borders.

    现在,您有了两种不同的林分可视化,可以决定哪一个显示详细地图。

  3. Go back to the print layout window often to see what the map would look like. For the purposes of creating detailed maps, you are looking for a symbology that looks good not at the scale of the whole forest area (left image below) but at a closer scale (right image below). Remember to use refresh Update map preview and setToCanvasExtent Set map extent to match main canvas extent whenever you change the zoom in your map or the layout.

    ../../../_images/composer_2-3.png

14.6.4. basic 试一试 创建底图模板

  1. Once you have a symbology you are happy with, you are ready to add some more information to your printed map. Add at least the following elements:

    • 标题。

    • 比例尺。

    • 地图的网格框架。

    • 网格两侧的坐标。

  2. You have created a similar layout already in 单元: 布局地图. Go back to that module as you need. You can look at this example image for reference:

    ../../../_images/map_template1.png
  3. 将地图导出为图像并查看效果。

    1. 布局 ► 导出为图像...

    2. Use for example the JPG format.

这就是打印时的样子。

14.6.5. basic 跟我做: 向打印布局添加更多元素

正如您可能在推荐地图模板图像中注意到的,画布的右侧有很多空间。让我们看看还有什么可以放进去。就我们的地图而言,图例并不是真正需要的,但鹰眼图和一些文本框可以为地图增加实用价值。

鹰眼图将帮助现场团队将详细地图放置在整个森林区域内显示:

  1. 将另一个地图元素添加到画布,位于标题文本的正下方。

  2. 项属性 标签页,打开 鹰眼图 下拉列表。

  3. 地图框架 (鹰眼图框架) 设置为 Map 0 。这将在较小的地图上创建一个阴影矩形,表示较大地图的可见范围。

  4. Check also the Frame option with a black color and a Thickness of 0.30.

../../../_images/more_elements1.png

请注意,您的鹰眼图并没有真正给出您想要的林区总览。您希望此地图表示整个林区,并希望仅显示背景地图和 forest_stands_2012 图层,而不显示取样地。此外,还需要锁定其视图,以便在更改图层的可见或顺序时不再更改。

  1. 返回地图,但不要关闭 打印布局 窗口。

  2. Right click the forest_stands_2012 layer and click on Zoom to Layer Extent.

  3. Deactivate all layers except for basic_map and forest_stands_2012.

  4. Expand the Manage map themes tool on the Layers panel and select Add theme.

  5. Name it basic_overview.

  6. Go back to the print layout.

  7. With the small map selected, click the Set map extent to match main canvas extent to set its extents to what you can see in the map window.

  8. Lock the view for the overview map by checking Follow map theme and selecting basic_overview under Main properties.

Now your overview map is more what you expected and its view will not change anymore. But, of course, now your detail map is not showing anymore the stand borders nor the sample plots. Let's fix that:

  1. Go to the map window again and select the layers you want to be visible (systematic_plots_clip, forest_stands_2012 copy and Basic_map).

  2. 再次缩放,仅显示几行取样地即可。

  3. 返回 打印布局 窗口。

  4. Select the bigger map in your layout.

  5. In Item properties click on Update preview and Set map extent to match main canvas extent.

请注意,只有较大的地图显示当前地图视图,而较小的鹰眼图保持与锁定时相同的视图。

还请注意,鹰眼图显示了详细地图所示范围的阴影框架。

../../../_images/more_elements2.png

您的模板地图即将就绪。现在在鹰眼图下方添加两个文本框,一个包含文本 'Detailed map zone: ',另一个为 'Remarks: '。如上图所示。

您还可以将指北针添加到鹰眼图 (新版中有专门的指北针工具,可自行尝试):

  1. Select the northArrow Add North Arrow tool.

  2. Click and drag a rectangle at the upper right corner of the overview map.

  3. In Item properties Check SVG image

  4. Browse SVG Browser ► SVG Groups for an arrow image.

  5. Under Image rotation, check the Sync with map and select Map 1 (the overview map).

  6. 将箭头图像调整为在小地图上看起来不错的尺寸。

基本地图布局已就绪,现在需要使用地图集工具以这种格式生成您认为必要的尽可能多的详细地图。

14.6.6. basic 跟我做: 创建地图集覆盖范围

地图集覆盖范围只是一个矢量图层,将用于生成详细地图,覆盖范围内的每个要素对应一幅地图。为了了解接下来的工作,这里有一整套林区的详细地图,供参考:

../../../_images/preview_atlas_results.png

覆盖范围可以是任何现有图层,但通常为特定目标创建一个范围更有意义。让我们创建一个遮盖林区的多边形网格:

  1. In the QGIS map view, open Vector ► Research Tools ► vectorGrid Create grid.

  2. 如图所示设置工具:

    ../../../_images/coverage_polygons.png
  3. Save the output as atlas_coverage.shp.

  4. Style the new atlas_coverage layer so that the polygons have no filling.

新多边形覆盖了整个林区,让您了解每幅地图 (从每个多边形创建) 将包含哪些内容。

../../../_images/atlas_coverage.png

14.6.7. basic 跟我做: 设置地图集工具

最后一步是设置地图集工具:

  1. Go back to the print layout.

  2. 在右侧面板,转到 生成地图集 (地图集) 标签页。

  3. 设置选项如下所示:

    ../../../_images/atlas_settings.png

    这告诉地图集工具使用 atlas_coverage 内的要素 (多边形) 作为每幅详细地图的焦点。它将为图层中的每个要素输出一幅地图。 隐藏范围图层 告诉地图集不要在输出地图中显示多边形。

还有一件事需要做,您需要告诉地图集工具每幅输出地图将更新哪些地图元素。到目前为止,您可能已经猜测,要为每个要素更改的地图是您准备好的包含取样地详细视图的地图,即画布中较大的地图元素:

  1. Select the bigger map element (Map 0).

  2. 转到 项属性 标签页。

  3. 在列表中,勾选 受控于地图集

  4. And set the Marging around feature to 10%. The view extent will be 10% bigger than the polygons, which means that your detail maps will have a 10% overlap.

    ../../../_images/controlled_by_atlas.png

现在,您可以使用地图集的预览工具查看地图的外观:

  1. 使用按钮 atlas 激活地图集预览,如果您的地图集工具栏不可见,请使用 地图集 ► 预览地图集

  2. 可以使用地图集工具栏或 地图集 菜单中的箭头浏览每个要素创建的地图。

Note that some of them cover areas that are not interesting. Let's do something about it and save some trees by not printing those useless maps.

14.6.8. basic 跟我做: 编辑范围图层

除了移除那些不感兴趣区域的多边形外,还可以自定义地图中的文本标注,以生成范围图层 属性表 中的内容:

  1. 返回地图视图。

  2. Enable editing for the atlas_coverage layer.

  3. 选择下图中选中的多边形 (黄色)。

  4. 移除选中的多边形。

  5. 关闭并保存编辑。

../../../_images/remove_polygons.png

You can go back to the print layout and check that the previews of the Atlas use only the polygons you left in the layer.

您正在使用的范围图层还没有可用于自定义地图中标注内容的有用信息。第一步是进行创建,例如您可以添加多边形区域的区号和带有一些备注的字段,供现场团队参考:

  1. Open the Attribute table for the atlas_coverage layer.

  2. 启用编辑。

  3. 使用 calculateField 字段计算器创建并填充以下两个字段。

  4. Create a field named Zone of type Whole number (integer).

  5. In the Expression box write/copy/construct $rownum.

  6. Create another field named Remarks, of type Text (string) and a width of 255.

  7. In the Expression box write 'No remarks.'. This will set all the default value for all the polygons.

The forest manager will have some information about the area that might be useful when visiting the area. For example, the existence of a bridge, a swamp or the location of a protected species. The atlas_coverage layer is probably in edit mode still, add the following text in the Remarks field to the corresponding polygons (double click the cell to edit it):

  • For the Zone 2: Bridge to the North of plot 19. Siberian squirrel between p_13 and p_14.

  • For the Zone 6: Difficult to transit in swamp to the North of the lake.`

  • For the Zone 7: Siberian squirrel to the South East of p_94.

  • 关闭并保存编辑。

Almost ready, now you have to tell the Atlas tool that you want some of the text labels to use the information from the atlas_coverage layer's attribute table.

  1. 返回 打印布局 窗口。

  2. Select the text label containing Detailed map....

  3. Set the Font size to 12.

  4. 将光标设置在标注文本的末端。

  5. 项属性 标签页的 主要属性 内,单击 插入/编辑表达式...

  6. In the Function list double-click on the field Zone under Field and Values.

  7. 单击 确定

  8. The text inside the box in the Item properties should show Detail map inventory zone: [% "Zone" %]. Note that the [% "Zone" %] will be substituted by the value of the field Zone for the corresponding feature from the layer atlas_coverage.

  9. 通过查看不同地图集预览图来测试标注的内容。

  10. Do the same for the labels with the text Remarks: using the field with the zone information. You can leave a break line before you enter the expression. You can see the result for the preview of zone 2 in the image below:

    ../../../_images/preview_zone2.png
  11. 使用地图集预览浏览您即将创建的所有地图,并尽情享受吧!

14.6.9. basic 跟我做: 打印地图

最后,将地图打印或导出为图像文件或PDF文件。你可以使用 地图集 ► 地图集导出为图像...地图集 ► 地图集导出为PDF文件... 。目前SVG导出格式仍不理想,结果不佳,请注意查看提示信息。

将地图导出为单个PDF文件,您可以将其发送到现场办公室进行打印:

  1. 转到右侧面板的 生成地图集 (地图集) 标签页。

  2. 输出 中,勾选 可能时导出为单个文件 。这将把所有地图放在一个PDF文件中,如果未勾选此选项,则每幅地图导出一个文件。

  3. 打开 布局 ► 导出为PDF文件...

  4. Save the PDF file as inventory_2012_maps.pdf in your exercise_data\forestry\samplig\map_creation\ folder.

  5. 打开PDF文件,检查一切是否按预期进行。

  6. 可以同样轻松地为每幅地图创建单独的图像 (记住取消勾选单个文件创建),在此您可以看到将创建图像的缩略图:

    ../../../_images/maps_as_images.png
  7. In the Print Layout, press fileSave Save in order to save your print layout changes in the project. This also saves the project file. You can reopen the project at any time and run or edit the atlas.

    It is also possible to save your map as a layout template as forestry_atlas.qpt in your exercise_data\forestry\map_creation\ folder. Use Layout ► Save as Template. You will be able to use this template again and again in other projects.

  8. Close the Print Layout and the project.

14.6.10. In Conclusion

您已经成功创建了一个模板地图,可用于自动生成要在现场中使用的详图地图,以帮助导航到不同的地块。正如您所注意到的,这不是一项简单的任务,但当您需要为其他地区创建类似的地图时,可以使用刚刚保存的模板,这将节省许多时间。

14.6.11. What's Next?

In the next lesson, you will see how you can use LiDAR data to create a DEM and then use it to enhance your data and maps visibility.