Geoserver SLD style - Labeling lines with shields

2.2k views Asked by At

I'm novice in Geoserver (Geoserver 2.10.0 in Tomcat 9 + Apache 2.14, on Win 10 Pro x64) and for some time trying to style roads labels as shields for highways, principal hwy ...

Checked Geoserver Trainings/sld-references/cookbook but can't locate any "real life" example with complete code.

Made and export SLD for line styles with QGIS 2.18.1, but since labels aren't supported, used OSGB SLD as a source code :

https://github.com/OrdnanceSurvey/Strategi-stylesheets/blob/master/ESRI%20Shapefile%20stylesheets/GeoServer%20stylesheets%20(SLD)/Full%20Colour%20style/motorway.sld#L348

and copy/paste TextSymbolizer... /TextSymbolizer portion of the code regarding label shields into Geoserver sld file -

( also edit original code with se:, ogc:, se:SvgParameter )

  <se:FeatureTypeStyle>
    <se:Rule>
      <se:Name>MARKED_TR labels</se:Name>
      <se:Description>
        <se:Title>MARKED_TR</se:Title>
      </se:Description>
      <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
        <ogc:PropertyIsEqualTo>
          <ogc:PropertyName>GRMN_TYPE</ogc:PropertyName>
          <ogc:Literal>MARKED_TR</ogc:Literal>
        </ogc:PropertyIsEqualTo>
      </ogc:Filter>
      <se:MaxScaleDenominator>250000</se:MaxScaleDenominator>
     <se:TextSymbolizer>
       <se:Label>
         <ogc:PropertyName>NAME_UTF</ogc:PropertyName>
       </se:Label>
       <se:Font>
         <se:SvgParameter name="font-family">Arial</se:SvgParameter>
         <se:SvgParameter name="font-size">9</se:SvgParameter>
         <se:SvgParameter name="font-weight">bold</se:SvgParameter>
       </se:Font>
        <se:LabelPlacement>
          <se:PointPlacement>
            <se:AnchorPoint>
              <se:AnchorPointX>0.5</se:AnchorPointX>
              <se:AnchorPointY>0.5</se:AnchorPointY>
            </se:AnchorPoint>
            <se:Displacement>
              <se:DisplacementX>0</se:DisplacementX>
              <se:DisplacementY>0</se:DisplacementY>
            </se:Displacement>
          </se:PointPlacement>
        </se:LabelPlacement>
       <se:Fill>
         <se:SvgParameter name="fill">#FFFFFF</se:SvgParameter>
       </se:Fill>
       **<se:Graphic>**
         <se:Mark>
           <se:WellKnownName>square</se:WellKnownName>
           <se:Fill>
             <se:SvgParameter name="fill">#009FB8</se:SvgParameter>
           </se:Fill>
         </se:Mark>
         <se:Size>6</se:Size>
       </se:Graphic>
       <se:Priority>450</se:Priority>
       <se:VendorOption name="graphic-resize">stretch</se:VendorOption>
       <se:VendorOption name="graphic-margin">2.3</se:VendorOption>
       <se:VendorOption name="maxDisplacement">200</se:VendorOption>
       <se:VendorOption name="repeat">500</se:VendorOption>       
       <se:VendorOption name="spaceAround">10</se:VendorOption>
       <se:VendorOption name="group">yes</se:VendorOption>  
     </se:TextSymbolizer>          
   </se:Rule>
  </se:FeatureTypeStyle>

Unfortunately, Geoserver Validation returns error as shown in screenshot:

Geoserver screenshot

2

There are 2 answers

1
Ian Turton On

Your code will not validate because it is an extension to the SLD standard schema. If you press submit and view the map you will see it works just fine.

0
DFic_zg On

Screenshot with "invisible" shield

As of now, it's seems that syntax in section Graphic -- /Graphic isn't correct ?!