The new QGis 2.12 tagging engine

The QGis tagging engine has been significantly enriched in version 2.12. In this article we will discuss advances:

  • Quadrant from the data
  • Priority from the data
  • Control over the action of polygons as obstacles
  • Draw labels that fit completely into a polygon
  • Rule-based tagging

Quadrant from the data

For point layer labels, you could set the quadrant of the label using the option Offset Over Point. In this case, all the labels of the layer were forced in the selected quadrant. Now you can link the quadrant to use in each label of the layer with a field from the attribute table. Each label will be forced into the quadrant indicated by this field. If the value of the field is null, the label will be placed according to the classical algorithm and will be positioned automatically.

First, which are the values ​​to use? The following image shows the link between the quadrant and the value to be specified in the table field:

To configure the placement of the label according to a field (integer type), which we have called “quadrant”

In the layer Properties, Tab Labels Tab -> Location , Check Around Point , Deploy Quadrant and select Field Type: String, Integer, Double , and then check the field containing the quadrants to use.

In order to place automatically the tags regardless of the quadrant, leave the value of the Quadrant field to null.

Priority from the data

Until now you could set the priority of the tags of a layer relative to other layers. Now you can define the priority of tags within a layer, based on the value of a field in the attribute table.

Let’s take for example the toponyms of cities. You can force the display of tags by population, if you have this value in the attribute table. Entities with a higher value in this field will have priority over those with lower values.

To configure this setting:

 

In Properties the Layer tab Tags -> Location in the Priority block   Deploy Values ​​defined by the data and select Field Type: String, Integer, Double, and then check the field containing the values ​​to use.

Definition of a barrier layer for the Tags.

You can now define an independent layer of the tagged layer as a barrier for tags. This means that you force the tags to not overlap with features in another layer.

Suppose you have a Commons layer and a stream layer. You want to display the tags with the names of the communes but you do not want these tags to hide sections of the watercourse. You will, therefore, define the Stream layer as an obstacle to the common layer tags.

Here is the Commons layer, tagged by default:

We configure the watercourse layer not to overlap with labels:

And we get the following result:

You can see that the tag at the top left is superimposed on the watercourse. There is not enough room to respect the obstacle. In this case, the tag is positioned regardless of the obstacle.

Control over the action of polygons as obstacles

When you have a continuous layer of polygons, the default option for placing the labels of the other layers, which is to try to put the minimum on the inner surface of the polygons, is not very convenient.

For example:

 

Both tags that spill out of the town are not very aesthetic. Now you can fix this problem:

 

Open the properties of the Commons -> Tags layer , select the Rendering tab , and select in Minimize tag placement the option Over the entity boundaries.

You get the following result:

Caution : You must tag the polygon layer so that this option is taken into account by other tag layers.

Draw tags that fit completely into a polygon

In Return you have a new option that only draws tags that fit completely into the corresponding polygon.

For example:

You can force QGis to place the tags completely inside or if there is not enough space, to omit them.

Open the properties of the layer   -> Tags, select the Rendering tab , and then select the Draw only tags that are entirely in the entity  and check the box .

You will get a result like this:

Rule-based tagging

This is the most powerful option of this new version of the tagging engine.

Let’s take the following map as an example:

To get the same map but with conditional formatting of labels like this:

You must return a complex expression, such as this one:

CASE WHEN length (“htmlname”)> 13 AND strpos (“htmlname”, ”)> 6 THEN replace (“htmlname”, ”, ”) WHEN length (“htmlname”)> 20 AND “htmlname” LIKE ‘ % Golf Course ‘THEN regexp_replace (‘ htmlname ‘,’ Golf Course ‘,’ Golf Course ‘) WHEN length (“htmlname”)> 20 AND “htmlname” LIKE’ Nature Reserve ‘THEN regexp_replace (“htmlname”,’ Nature Reserve ‘,’ Nature Reserve ‘) WHEN length (“htmlname”)> 20 AND “htmlname” LIKE’% Church Of England% ‘THEN regexp_replace (“htmlname”,’ Church Of England ‘,’ Church Of England ‘) WHEN length ( “htmlname”)> 13 AND “htmlname” LIKE ‘% Of The%’ THEN regexp_replace (“htmlname”, “Of The ‘,’ Of The ‘) WHEN length (” htmlname “)> 13 AND” htmlname “LIKE’% of% ‘AND “fontcolour” <> 2 AND “fontcolour” <> 4 THEN regexp_replace (“htmlname”, “of’, ‘of’) WHEN” htmlname “LIKE ‘% /%’ THEN regexp_replace (” htmlname “, ‘ / ‘,’ / ‘) WHEN length (“htmlname”)> 30 THEN replace (“htmlname”,’ ‘,’ ‘) ELSE “htmlname” END

Now you can do the same thing by entering formatting rules in the same way as formatting styles:

In Properties Layer -> Tags, select Rule-Based Tags

Here are the rules that allow you to have the same formatting as the previous complex expression:

Leave a Reply

Your email address will not be published. Required fields are marked *