1

I am trying to get labels to follow the linestring. I have inserted the following sld text into a geoserver style, but the label is displayed at the horizontally at linestring centroid

          <sld:TextSymbolizer>

       <sld:Geometry>
          <ogc:Function name="centroid">
           <ogc:PropertyName>shape</ogc:PropertyName>
          </ogc:Function>
       </sld:Geometry>

        <sld:Label>
          <ogc:PropertyName>road_name</ogc:PropertyName>
        </sld:Label>

        <sld:Font>
          <sld:CssParameter name="font-family">MS Shell Dlg 2</sld:CssParameter>
          <sld:CssParameter name="font-size">6.0</sld:CssParameter>
          <sld:CssParameter name="font-style">normal</sld:CssParameter>
          <sld:CssParameter name="font-weight">normal</sld:CssParameter>
        </sld:Font>            

        <sld:LabelPlacement>
          <sld:LinePlacement>
            <sld:PerpendicularOffset>10.0</sld:PerpendicularOffset>
          </sld:LinePlacement>
        </sld:LabelPlacement>

        <Halo>
            <Radius>
                <ogc:Literal>2</ogc:Literal>
            </Radius>
            <Fill>
                <CssParameter name="fill">#FFFFFF</CssParameter>
                <CssParameter name="fill-opacity">0.85</CssParameter>               
            </Fill>
        </Halo>

        <sld:Fill>
          <sld:CssParameter name="fill">#000000</sld:CssParameter>
        </sld:Fill>

       <sld:VendorOption name="followLine">true</sld:VendorOption>

      </sld:TextSymbolizer>

I thought that by adding the VendorOption -> "followLine" the label would be displayed inline with the line. Is there something that i have missed in the documentation to make this work?

2

You must remove the geometry transformation turning the line into a point:

   <sld:Geometry>
      <ogc:Function name="centroid">
       <ogc:PropertyName>shape</ogc:PropertyName>
      </ogc:Function>
   </sld:Geometry>

With the above in, the code is labelling a point, not a line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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