4

The process in Changing to alternate label if first label does not fit in QGIS? seems to be close to what's needed but given that was 2 years ago, I am wondering if there is a new way of doing this like in the ArcMap label engine?

Stacking - http://desktop.arcgis.com/en/arcmap/10.3/map/working-with-text/stacking-labels-about-stacking-labels.htm

Truncation - http://desktop.arcgis.com/en/arcmap/10.3/map/working-with-text/abbreviating-and-truncating-about.htm

Another option is Key numbering - desktop.arcgis.com/en/arcmap/10.3/map/working-with-text/

To clarify further Strategy 1 - place label as is, Strategy 2 - stack label (break into 2 lines), strategy 3 - truncate, last option -don't show. So that it tries to place the label using 3 strategies before it drops it.

1 Answer 1

6

In the documentation, for QGIS 3.x, you can configure Apply label text substitutes :

The Apply label text substitutes option gives you ability to specify a list of texts to substitute to texts in feature labels (e.g., abbreviating street types). Replacement texts are thus used to display labels in the map canvas. Users can also export and import lists of substitutes to make reuse and sharing easier.

In QGIS, check the checkbox (in the layer properties or in the style panel) and click on the ... button on the right for add manually or with a file label text substitutions.

6
  • 1
    wow ... nice feature ... a bit hidden in qgis interface i feel ... Is there a way to access it programmatically (i'd like to define a dynamic replacement list ...) ? I only see a save config button ... no way to download an .xml configuration file ?
    – Snaileater
    Commented Aug 1, 2019 at 8:25
  • 1
    You have it here in the class QgsPalLayerSettings (QgsVectorLayer.labeling() > QgsAbstractVectorLayerLabeling.settings() > QgsPalLayerSettings) Commented Aug 1, 2019 at 8:47
  • 1
    Is there a way to access a given feature labeling property ? My aim would be to detect the features for which a label collision has been detected ...
    – Snaileater
    Commented Aug 1, 2019 at 11:19
  • 1
    This is good but what I'm really after is not for it to replace all the time but only if it can't place it because it's to long rather than not placing it at all. Also rather than having to create a dictionary for replacements (we use short names Rd instead of Road anyway) is logic like the following from the arcgis link I included in the question - "the church label Ascension Episcopal Church (Historical Site) has been truncated to Asn.E.C.(H.Sit.). Each part of the label that has been truncated has had a period added to the end."... so the truncation should happen only if it doesn't fit.
    – GeorgeC
    Commented Aug 1, 2019 at 11:28
  • To clarify further Strategy 1 - place label as is, Strategy 2 - stack label (break into 2 lines), strategy 3 - truncate, last option -don't show. So that it tries to place the label using 3 strategies before it drops it. Another option is Key numbering - desktop.arcgis.com/en/arcmap/10.3/map/working-with-text/…
    – GeorgeC
    Commented Aug 1, 2019 at 11:43

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