4.2. Lesson: 标签工具The Label Tool

标签可以被添加到地图来显示关于某对象的任何信息。任何矢量图层可以有与之关联的标签。这些标签是依靠其属性数据的内容创建的。Labels can be added to a map to show any information about an object. Any vector layer can have labels associated with it. These labels rely on the attribute data of a layer for their content.


图层属性对话框里面有个标签选项,也有本节课所讲的功能,但是本节主要以工具栏上的标签工具来解说。The Layer Properties dialog does have a Labels tab, which now offers the same functionality, but for this example we’ll use the Label tool, accessed via a toolbar button.

本节目标:为某个图层添加有用好看的标签。The goal for this lesson: To apply useful and good-looking labels to a layer.

4.2.1. basic 跟我做:使用标签Follow Along: Using Labels

在使用标签工具之前,请先确定该工具已被激活。Before being able to access the Label tool, you will need to ensure that it has been activated.

  • 执行: 视图 ‣ 工具栏.Go to the menu item View ‣ Toolbars.
  • 确保标签 选项已被选中,若没被选中,那就现在选中它。Ensure that the Label item has a check mark next to it. If it doesn’t, click on the Label item, and it will be activated.
  • 在图层列表中点击places 图层,你会看到该层会被高亮显示。Click on the places layer in the Layers list, so that it is highlighted.
  • 点击工具栏上的这个按钮mActionLabeling。Click on the following toolbar button: mActionLabeling

这会打开 图层标签设置 对话框。This gives you the Layer labeling settings dialog.

  • 选中 给该图层加上标签,标签字段为…….Check the box next to Label this layer with….

这时候,你需要选择一个用于绘制标签的字段。根据之前的课程对本数据的了解,我们选择最适合做标签的 NAME 字段。You’ll need to choose which field in the attributes will be used for the labels. In the previous lesson, you decided that the NAME field was the most suitable one for this purpose.

  • 从列表中选择 name 字段。Select name from the list:


  • 点击 确定 。 Click OK.

现在,地图将添加上标签了,如下图。The map should now have labels like this:


4.2.2. basic 跟我做:更改标签选项Follow Along: Changing Label Options

基于之前课程你所设置的地图样式,你可能会发现标签的格式不太合适,或者他们距离其标注点太远/太近等等。Depending on the styles you chose for your map in earlier lessons, you’ll might find that the labels are not appropriately formatted and either overlap or are too far away from their point markers.

  • 点击工具栏上的按钮,再次打开 标签  工具。Open the Label tool again by clicking on its button as before.
  • 确保对话框左下方列表中的 文本  被选中。然后,你可以在其右侧的选项中更改其文本样式。Make sure Text is selected in the left-hand options list, then update the text formatting options to match those shown here:

../../../_images/label_formatting_options.png这样就可以解决字体不合适等问题了。接下来要解决标签与标注点重合的问题。开始之前,我们先看一下 使用轮廓缓冲区  选项。That’s the font problem solved! Now let’s look at the problem of the labels overlapping the points, but before we do that, let’s take a look at the Buffer option.

  • 还是打开标签工具对话框。Open the Label tool dialog.
  • 从左下框里面选使用轮廓缓冲区 。Select Buffer from the left-hand options list.
  • 勾选 绘制文本缓冲区 ,然后按照下图设置。Select the checkbox next to Draw text buffer, then choose options to match those shown here:


  • 点击应用。Click Apply.

这时你会看到我们给标签添加了一个彩色的缓冲区(或边框),让标签从地图上看起来更清楚。You’ll see that this adds a colored buffer or border to the place labels, making them easier to pick out on the map:

../../../_images/buffer_results.png现在我们来设置标签与标记点之间的位置。Now we can address the positioning of the labels in relation to their point markers.

  • 图层标签  对话框中,左下框中选中位置  。In the Label tool dialog, go to the Placement tab.
  • 选中 点周围 ,并将 距离 设置为2mm 。Change the value of Distance to 2mm and make sure that Around point is selected:


  • 点击应用。Click Apply.

这时候你会看到标签将不会重叠在它们的标记点上了。You’ll see that the labels are no longer overlapping their point markers.

4.2.3. moderate 跟我做:用标签代替图层符号Follow Along: Using Labels Instead of Layer Symbology

在许多情况下,点的位置并不需要非常具体。例如, places 层中大多数点是代表了整个城镇或郊区,并与这些与要素关联的特定点在大比例尺下并不是很具体。事实上,给出一堆很具体的点往往会把阅读地图的人弄得更糊涂。In many cases, the location of a point doesn’t need to be very specific. For example, most of the points in the places layer refer to entire towns or suburbs, and the specific point associated with such features is not that specific on a large scale. In fact, giving a point that is too specific is often confusing for someone reading a map.

举一个例子: 在世界地图上,欧盟的点可能标注在波兰的某个地方,但阅读地图的人看到这个点在波兰后,他会认为欧盟的总部在波兰(【译者注】实际上在比利时首都布鲁塞尔)。To name an example: on a map of the world, the point given for the European Union may be somewhere in Poland, for instance. To someone reading the map, seeing a point labeledEuropean Union in Poland, it may seem that the capital of the European Union is therefore in Poland.

因此,为了防止这种误解,我们会停用点符号并将它们完全用标签来替代。So, to prevent this kind of misunderstanding, it’s often useful to deactivate the point symbols and replace them completely with labels.

在 QGIS,你可以通过改变标签位置,直接在它们引用点的位置来呈现。In QGIS, you can do this by changing the position of the labels to be rendered directly over the points they refer to.

  • 打开 places 图层的图层标签设置  对话框。Open the Layer labeling settings dialog for the places layer.
  • 选择 位置 选项。Select the Placement option from the options list.
  • 选中离点便宜量  单选按钮。Click on the Offset from point button.

这将显示象限选项,您可以使用象限选项设置标签与点标记的位置关系。在本例中,我们想要以点为中心,所以选择中心象限标签:This will reveal the Quadrant options which you can use to set the position of the label in relation to the point marker. In this case, we want the label to be centered on the point, so choose the center quadrant:


  • 通过编辑图层样式的方式来不显示点样式,具体为:将椭圆标记的宽度和高度的大小设置为 0,如下图。Hide the point symbols by editing the layer style as usual, and setting the size of the Ellipse marker width and height to 0:


  • 点击确定来查看结果。Click OK and you’ll see this result:

../../../_images/hide_point_marker_results.png如果你是要缩小地图,你会看到一些标签会消失以避免在缩小的地图上重叠。有时这是你想要的效果,特别是处理有很多点的数据集时;但在其他时候,这种方式将失去一些有用的信息。除这两种外,还有另一种可能性,我们将在以后的练习中了解学习。If you were to zoom out on the map, you would see that some of the labels disappear at larger scales to avoid overlapping. Sometimes this is what you want when dealing with datasets that have many points, but at other times you will lose useful information this way. There is another possibility for handling cases like this, which we’ll cover in a later exercise in this lesson.

4.2.4. moderate 动手试:自定义标签Try Yourself Customize the Labels

  • 返回到之前对标签和样式的设置,让点标记和标签偏移量为 2.00 毫米。在本阶段,你可以随意调整的点标记和标签的样式。Return the label and symbol settings to have a point marker and a label offset of 2.00mm. You may like to adjust the styling of the point marker or labels at this stage.

Check your results

  • 将比例尺设置为1:100000。可以在状态栏比例尺框中直接输入。Set the map to the scale 1:100000. You can do this by typing it into the Scale box in theStatus Bar.
  • 将标签调整到此比例尺下合适的样式。Modify your labels to be suitable for viewing at this scale.

Check your results



电子邮件地址不会被公开。 必填项已用*标注

填写验证码: *