[GIS] Label background in SLD

labelingsldweb-mapping

Is there any possibility to construct SLD style which displays label with rectangular background?

Background has to have sizes which automatically fit to sizes of text content. I would prefer not to use any vendor parameters because SLD has to be used in more than one application.

This is an example of desired label generated in QGIS (unfortunately QGIS doesn't export label specification from this label configuration):

enter image description here

Best Answer

I know you specified you would rather not use vendorparameters, but this is the only way I know how to do it. I'm not sure if you have tried this already.

Add a square graphic to the textsymbolizer and use the vendoroptions graphic-resize and graphic-margin.

      <TextSymbolizer>
        <Label>
         <ogc:PropertyName>NAME</ogc:PropertyName>
        </Label>
        <Font>
          <CssParameter name="font-weight">bold</CssParameter>
          <CssParameter name="font-size">15</CssParameter>
        </Font>
        <Fill>
          <CssParameter name="fill">#FFFFFF</CssParameter>
        </Fill>
       <Graphic>
          <Mark>
            <WellKnownName>square</WellKnownName>
            <Fill>
          <CssParameter name="fill">#DE230A</CssParameter>                  
            </Fill>
          </Mark>
        </Graphic>
        <VendorOption name="graphic-resize">stretch</VendorOption>                         
        <VendorOption name="graphic-margin">2</VendorOption>             
      </TextSymbolizer>