14

Is there a way within QGIS to prevent text labels from overlapping icons used to label a point layer?

In the example map shown below, there are two layers:

  1. Roads layer which is labeled using the new labeling engine.
  2. A point layer which uses svg icons to show highway shields.

I have other use cases for this such as preventing overlapping of rail station icons. In this example, I could simply move the point, however, in other cases, such as a subway station, that is not a workable solution.

A possible solution which I am considering would involve:

  1. Adding a column to the point layer's dbf file.
  2. Filling the added column with either Null or a space.
  3. Enabling QGIS's [new style] labeling for the added column.

Is this the way to go or is there a better method?

Sample Map

QGIS info: I am using versions 1.7.4 and a recently compiled version of 1.8 on Mac OS 10.7.4. Linux and Windows versions are also available to me.


Progress Update: The method I described above works though two modifications to the process are required.

  1. Instead of using a space character or a Null, a non-breaking space has to be used. While testing I found, fields with Null are not rendered and fields with only a space(s) are converted to Null. (See this Wikipedia page for information on how to type a non-breaking space.)
  2. While setting the Layer Labeling Settings, on the Advanced tab, set the Placement to Over Point. Also set the Priority such that it is higher than any other labeled layers.

Depending on the size of the icon used, some experimentation may be required to get things to work as expected. Depending on the circumstance, it may be easier to use multiple characters rather than attempting to increase the font weight and/or size.

Sample Map 2

Tested with QGIS 1.7 and a recently compiled of 1.8 on Mac OS 10.7.4.

2
  • 1
    You can also answer your own questions. I would like to vote your solution up.
    – underdark
    Jun 17, 2012 at 9:06
  • You can do concatenation as i did: here
    – jlSta
    Feb 22, 2017 at 15:37

4 Answers 4

8

The best consistent solution I have so far is along the lines of what I have laid out above. Assuming a SHP file is used, the steps are:

  1. Open the dbf file either with a spreadsheet application such as LibreOffice, Excel, or the QGIS Table Manager plugin.
  2. Add a column to the table. If a data type is required, use string.
  3. Fill the cells with a non-breaking space. Once complete, save the changes. (See this Wikipedia page for information on how to type a non-breaking space.)
  4. Open the Layer Labeling Settings for the point layer. On the Advanced tab, set the Placement to Over Point and set the Priority such that it is higher than any other labeled layers.
1
  • 2
    In 2.14 you don't even need to add a new column, just put ' ' as the label
    – raphael
    Jun 28, 2016 at 19:33
3

I know this is old but you could add an "X Coordinate" and "Y Coordinate" (double precision) column to the table that holds that information and then go to the "Data Defined Settings" tab under Labels in the layer properties and change X coordinate and Y coordinate accordingly. Once you do that you can move the label by freehand using the move label button.

1

I just posted another answer to a similar problem. The approach uses svg symbols instead of layers and makes use of data defined override to set the path to a distinct svg symbol for each attribute value, cp. my answer to Symbols above labels in map QGIS

0

You could experiment with the offset of the label.

I find that allows label positioning to be more dynamic, if I set it to 2 mm or so.

2
  • No, I have not attempted to do this. The main reason I have not altered the label positioning is because on other areas of the map (not pictured), the road network is considerably denser. In the example above, moving the icon by about 2mm (any direction) would correct the problem. However on other parts of the map, it would likely push the icon deeper into another label.
    – DMan
    Jun 17, 2012 at 2:06
  • Give it a go, the label will likely shift to a new dynamic position. Maybe not what you want, but only way to find out is to try. The option I use is in the advanced tab of the new label tool (which is found in the toolbar not the from the properties dialog of the layer).
    – Willy
    Jun 17, 2012 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.