MapServer – Adding Background Buffer Around Labels with GEOMTRANSFORM ‘labelpoly’

backgroundbufferlabelingmapserver

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

Best Answer

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.

Related Question