1

I'm struggling on MapServer trying to create better and smoother background buffer around labels using GEOMTRANSFORM 'labelpoly' function documented here https://mapserver.gis.umn.edu/mapfile/geomtransform.html#labelpnt-and-labelpoly

Actual labelling state

  CLASS
    NAME "Chantiers forestiers"
    TEXT "[type_travaux]$[situation]$ Du [date_debut] $ Au [date_fin]"
    STYLE
      COLOR 0 255 0
      OUTLINECOLOR 0 0 0
    END
    LABEL
      MAXSCALEDENOM 20000
      FONT arial
      TYPE truetype
      SIZE 10
      COLOR 0 0 0
      POSITION AUTO
      WRAP "$"
      STYLE
        OPACITY 80
        GEOMTRANSFORM 'labelpoly'
        COLOR 255 255 255
        OFFSET 2 2
      END
    END

Any idea on how we could achieve this? (trying to achieve it on MapServer)

Minimal would be larger than 1px rectangle buffer (eg 5px)

Better Labelling rectangle

Better would be rounded rectangle buffer which I was not able to achieve on QGIS yet

enter image description here

2
  • 1
    Could you add an example of the better and smoother background from QGIS?
    – user30184
    Commented Apr 26, 2022 at 10:38
  • Not so easy to achieve on QGIS as I thought, we miss maybe some rounded rectangle buffer option or to be able to use the geometry generator on the label extent.
    – Nono
    Commented Apr 28, 2022 at 8:40

2 Answers 2

2

I fear that fine tuning the labelpoly option is not possible without touching the source code.

labelpoly generates the bounding rectangle for the text, with 1 pixel of padding added in all directions.

I believe that the desired result could be achieved if it was possible to apply a buffer to labelpoly

GEOMTRANSFORM (buffer([labelpoly], 5))

It is already possible to color the boundary of the labelpoly with OUTLINECOLOR but for my mind it does not make the result much nicer. I suggest to write mail to mapserver-users mailing list and introduce your problem. A minimal improvement might be to change the default padding of labelpoly into 3 or 5 pixels. With 1 pixel the box is rather cramped.

1

As suggested by @user30184 it is possible to add some OUTLINECOLOR AND WIDTH to the generated labelpoly

Smoothed polygons

  CLASS
    NAME "Chantiers forestiers"
    TEXT "[type_travaux]$[situation]$ Du [date_debut] $ Au [date_fin]"
    STYLE
      COLOR 0 255 0
      OUTLINECOLOR 0 0 0
    END
    LABEL
      MAXSCALEDENOM 20000
      FONT arial
      TYPE truetype
      SIZE 10
      COLOR 0 0 0
      POSITION AUTO
      WRAP "$"
      STYLE
        OPACITY 80
        GEOMTRANSFORM 'labelpoly'
        COLOR 255 255 255
        OFFSET 2 2
        OUTLINECOLOR 255 255 255
        WIDTH 15.0
      END
    END
  END

This is not perfect on transparent shapes (since there is an overlap between border and fill) but is as expected smoothed and

Smoothed

Your Answer

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

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