Feature request #16747

Add option to label connected polygons once

Added by Georg Wicke about 3 years ago. Updated about 3 years ago.

Pull Request or Patch supplied:No Resolution:
Easy fix?:No Copied to github as #:24646


The Problem

Under Layer Properties -> Labels -> Rendering -> Feature options, there is an option to "Merge connected lines to avoid duplicates" when working with a line layer. This feature is missing for polygon layers.

But can't you just merge the features together in an additional layer?

You can introduce new layers exclusively for labelling, but this is a very tedious workaround with many undesired side effects and poor performance. For example, when your map changes (even just a bit), you have to recreate all layers based on it. We want to make a tool to optimize constituencies, and we can't display the names of the constituencies if we don't want to duplicate them. Instead, we have to create complicated workarounds like creating single invisible points that are put at a fitting location and are labelled manually. Joining all the features together takes minutes, so we're not doing that. Also, it pollutes the legend with an additional layer that the user shouldn't be able to see.

But also in regular mapping scenarios, this can come in handy:
  • When mapping administrative areas you want to show labels for some regions, their cities, and their cities' districts (and maybe even a layer above or below that).
  • When mapping out buildings, you might want to label a bunch of buildings belonging to a complex at once.

ArcGIS does have this feature: http://resources.arcgis.com/en/help/main/10.1/index.html#//00s80000000m000000

labelled map.PNG - Example map: England, Scotland, Wales and Northern Ireland are forming the United Kingdom together. However, the geometry would be required to be duplicated to archieve this kind of labelling in QGIS. (Taken from OpenStreetMap) (152 KB) Georg Wicke, 2017-06-22 05:53 PM


#1 Updated by Regis Haubourg about 3 years ago

  • Status changed from Open to Feedback

Not sure I get exactly what you need.

Be aware that union on geometry are really heavy computation tasks and they can fail if input geometries are invalid, or if common boundaries leed to creating invalid dissolved geometries. In my experience, those aggregated datasets should be available in the long run and not recomputed on the fly for labeling purposes.

In see two different points in your request:
- remove duplicates on polygon layers. Not so easy considering the above warning, unless you accept some fuzziness in label placement (using a rough envelop instead of real geometry union)
- have a native manual label placement that keeps being in sync with the datasource? For this part, look at the QEP (QGIS Enhancement Proposals) here:

QEP #27 will add the ability to store auxiliary data - then labeling data - and keep them in sync with source dataset. That would adress your issues with duplicating some datasets.

Make a search on label improvement in the QEP and you'll find a lot of them about leader lines callouts, curved labels, label masking and please comment if you find something that could be improved. Those QEP lack fundings currently (I funded them and then quit my previous employer), please consider supporting them entirely or partially if you want the label area to keep moving forward.

#2 Updated by Harrissou Santanna about 3 years ago

I agree that would be a nice improvement to not have two contiguous polygon with same label...
@Regis, Couldn't some geometry validity check (and fix?) be done in the feature merging? I don't know the cost however.
@Georg, have you tried virtual layers to create your "to be labeled only"-layers? see https://docs.qgis.org/2.14/en/docs/user_manual/working_with_vector/virtual_layers.html

#3 Updated by Regis Haubourg about 3 years ago


@Regis, Couldn't some geometry validity check (and fix?) be done in the feature merging? I don't know the cost however.

I'm currently working on that, and yes it is costy :/ (Sometimes several hours). And validity check on individual features does not ensure that the merging will work, if topology of boundaries is not clean. Eventually, merging bbox of features can be fast, but this means the placement of labels will not be very accurate. I prefer by far to handle the right aggregated objects upstream in my database than having strange labeling option not working correctly and with nobody happy in the end.

Also available in: Atom PDF