1

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>
  • Have you tried using other anchor points (1,1 or 0.5,0.5) just to see if they are working? It looks like the label point is the centroid of the polygon so even if the <AnchorPoint> was in the bottom right (0,0) it would just be the bottom right of the center(I could be wrong). I would say you could use the displace but since they are so irregular it probably wouldn't work. – landocalrissian Oct 7 '16 at 14:37
  • AnchorPoint changed nothing. I think I can remove it. – Magno C Oct 7 '16 at 16:05
1

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.

  • Ya I was thinking you could create a point layer in the locations you wanted to be labeled and only render the labels. This would just be a workaround though. – landocalrissian Oct 7 '16 at 15:29
  • Jesus iant... your SLD is too tricky for me. As all timezones have same width at bottom I think I could try the Chris approach. Maybe finding the 180 / 24 , y position.... – Magno C Oct 7 '16 at 15:52
  • I agree this demands more for a custom function taking into account the area of visualization, clipping to it, and then getting the a point of the lowest part of the polygon (centroid might not work for some polygons) – Andrea Aime Oct 7 '16 at 15:55

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.