[GIS] SLD style: put all labels at polygon bottom

geoserversldstyle

I have the timezone polygons in my database and create a layer to it.

Now I try to apply some style but I can't find a way to put all zone labels at bottom.

Already read this http://docs.geoserver.org/stable/en/user/styling/sld-reference/labeling.html and this http://docs.geoserver.org/2.1.1/user/styling/sld-reference/labeling.html.

The result until now:
http://i.stack.imgur.com/RJOYU.png

My style is

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0" 
 xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" 
 xmlns="http://www.opengis.net/sld" 
 xmlns:ogc="http://www.opengis.net/ogc" 
 xmlns:xlink="http://www.w3.org/1999/xlink" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <NamedLayer>
    <Name>timezone_polygon</Name>
    <UserStyle>
      <Title>Polygon Timezone Style</Title>
      <Abstract>A Timezone polygon style</Abstract>
      <FeatureTypeStyle>
        <Rule>
          <Name>rule1</Name>
          <Title>Timezone</Title>
          <Abstract>A Timezone polygon style</Abstract>
          <PolygonSymbolizer>
            <Fill> 
            <CssParameter name="fill">#f5a6ad</CssParameter>
              <CssParameter name="fill-opacity">0.2</CssParameter>
            </Fill> 
            <Stroke>
              <CssParameter name="stroke">#9c0c1f</CssParameter>
              <CssParameter name="stroke-width">0.1</CssParameter>
            </Stroke>
          </PolygonSymbolizer>

       <TextSymbolizer>
         <Label>
           <ogc:PropertyName>zona</ogc:PropertyName>
         </Label>
         <Font>
           <CssParameter name="font-family">Arial</CssParameter>
           <CssParameter name="font-size">9</CssParameter>
           <CssParameter name="font-style">normal</CssParameter>
         </Font>
         <LabelPlacement>
           <PointPlacement>
             <AnchorPoint>
               <AnchorPointX>0.0</AnchorPointX>
               <AnchorPointY>0.0</AnchorPointY>
             </AnchorPoint>
           </PointPlacement>
         </LabelPlacement>
       </TextSymbolizer>          

        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

Best Answer

I think you could lash something up from a combination of functions but it might be easiest to pre-calculate a position and store it in a shapefile or database table.

A possible SLD might be (untested):

<sld:TextSymbolizer>
    <sld:Geometry>
      <ogc:Function name="geomFromWKT">
          <![CDATA[POINT(]]>
        <ogc:Function name="getX">
          <ogc:Function name="centroid">
             <ogc:PropertyName>the_geom</ogc:PropertyName>
          </ogc:Function>
        </ogc:Function>
         <![CDATA[, -85)]]
     </ogc:Function>
    </sld:Geometry>
    <sld:Label>

Which would be fine until you zoom in and then they are lost, so you would really need to play with the predefined variables (wms_bbox)

 <ogc:Function name="env">
      <ogc:Literal>wms_bbox</ogc:Literal>
 </ogc:Function> 

and try to intersect a vertical line from the centroid to the south pole with it to get a label point. However at that point you may well find it easier to write a custom function.

Related Question