GeoServer Labeling – Split Label Style in GeoServer CSS or SLD

cssgeoserverlabelingsldstyle

I would like to split the style of my labels, which consist of 2 attributes.
I already managed to separate the lines, but I need to style them differently as well, as the second line should be bold.

Currently my map looks like this:

how it looks like

And I would like it to look like this:

how it should look like

I would prefer to do it in CSS, but I also prepared the style in SLD, so I would be happy for a solution in either of them.

My code looks like this in CSS:

* {
    label: [IDENT][LOWERLIMIT];
    -gt-label-auto-wrap: 1;
    font-weight: normal;
    font-fill: black;
}

and like this in SLD:

<Rule>
  <TextSymbolizer>
     <Label>
       <ogc:PropertyName>IDENT</ogc:PropertyName><![CDATA[
]]>
       <ogc:PropertyName>LOWERLIMIT</ogc:PropertyName>
      </Label>
      <Font>
       <CssParameter name="font-fill">black</CssParameter>
       <CssParameter name="font-weight">normal</CssParameter>
      </Font>
  </TextSymbolizer>
</Rule>

Best Answer

Here is a solution in SLD but I think you should be able to generate the same in CSS.

enter image description here

The trick is to use 2 TextSymbolizers and offset them so that they don't overlap.

     <TextSymbolizer>
        <Label>
          <ogc:PropertyName>STATE_ABBR</ogc:PropertyName>
        </Label>
        <Font>

          <CssParameter name="font-family">Arial</CssParameter>
          <CssParameter name="font-style">Normal</CssParameter>
          <CssParameter name="font-size">10</CssParameter>
        </Font>
        <LabelPlacement>
          <PointPlacement>
            <AnchorPoint>
              <AnchorPointX>0.5</AnchorPointX>
              <AnchorPointY>1.0</AnchorPointY>
            </AnchorPoint>
            <Displacement>
              <DisplacementX>
                0
              </DisplacementX>
              <DisplacementY>
                10
              </DisplacementY>
            </Displacement>
          </PointPlacement>
        </LabelPlacement>
      </TextSymbolizer>
      <TextSymbolizer>
        <Label>
          <ogc:PropertyName>MALE</ogc:PropertyName>
        </Label>
        <Font>

          <CssParameter name="font-family">Arial Bold</CssParameter>
          <CssParameter name="font-style">Normal</CssParameter>
          <CssParameter name="font-weight">bold</CssParameter>
          <CssParameter name="font-size">10</CssParameter>
        </Font>
        <LabelPlacement>
          <PointPlacement>
            <AnchorPoint>
              <AnchorPointX>0.5</AnchorPointX>
              <AnchorPointY>0.0</AnchorPointY>
            </AnchorPoint>
            <Displacement>
              <DisplacementX>
                0
              </DisplacementX>
              <DisplacementY>
                -10
              </DisplacementY>
            </Displacement>
          </PointPlacement>
        </LabelPlacement>
      </TextSymbolizer>

Depending on your font and polygon sizes you can play with the AnchorPoints and Displacements to adjust the exact placement of the labels.

Related Question