Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use WMS to display my points on the map. I would like to display points labels(name_ID) starting at certain zoom level. From What I have read I understand I can do it with GeoServer rules, but I need a clear example to clarify this.

share|improve this question
up vote 6 down vote accepted

You have to define 2 different sld:Rules using MaxScaleDenominator. In the first one, add the style to render the label (the TextSymbolizer in my example), and specify the desired zoom level with the right MaxScaleDenominator. In the second rule, define a different style without the label. Basically, a rule contains a style, an only the style whith the satisfied rule is applied to the features.

This is one of my sld

<?xml version="1.0" encoding="UTF-8"?>
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld"              xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
  <sld:NamedLayer>
    <sld:Name>locations_table</sld:Name>
    <sld:UserStyle>
      <sld:Name>locations_table</sld:Name>
      <sld:Title>A boring default style</sld:Title>
      <sld:Abstract>A sample style that just prints out a green line</sld:Abstract>
      <sld:FeatureTypeStyle>
        <sld:Name>name</sld:Name>
        <sld:Rule>
          <sld:MaxScaleDenominator>68000.0</sld:MaxScaleDenominator>
          <sld:PointSymbolizer>
            <sld:Graphic>
              <sld:Mark>
                <sld:WellKnownName>circle</sld:WellKnownName>
                <sld:Fill>
                  <sld:CssParameter name="fill">#FF0000</sld:CssParameter>
                </sld:Fill>
              </sld:Mark>
              <sld:Size>
                <ogc:Literal>4</ogc:Literal>
                  </sld:Size>
            </sld:Graphic>
          </sld:PointSymbolizer>
          <sld:TextSymbolizer>            
            <sld:Label>            
              <ogc:PropertyName>name1</ogc:PropertyName> <![CDATA[
              ]]><ogc:PropertyName>name2</ogc:PropertyName>
            </sld:Label>
            <sld:Font>
          <sld:CssParameter name="font-family">Arial</sld:CssParameter>
          <sld:CssParameter name="font-size">11</sld:CssParameter>
          <sld:CssParameter name="font-style">normal</sld:CssParameter>
          <sld:CssParameter name="font-weight">bold</sld:CssParameter>
        </sld:Font>
        <sld:LabelPlacement>              
          <sld:PointPlacement>
            <sld:AnchorPoint>
              <sld:AnchorPointX>
                <ogc:Literal>0.5</ogc:Literal>
              </sld:AnchorPointX>
              <sld:AnchorPointY>
                <ogc:Literal>0.0</ogc:Literal>
              </sld:AnchorPointY>
            </sld:AnchorPoint>
            <sld:Displacement>
              <sld:DisplacementX>
                <ogc:Literal>0</ogc:Literal>
              </sld:DisplacementX>
              <sld:DisplacementY>
                <ogc:Literal>5</ogc:Literal>
              </sld:DisplacementY>
            </sld:Displacement>
            <sld:Rotation>
              <ogc:Literal>0.0</ogc:Literal>
            </sld:Rotation>
          </sld:PointPlacement>
        </sld:LabelPlacement>            
        <sld:Fill>
          <sld:CssParameter name="fill">#000000</sld:CssParameter>
        </sld:Fill>
        <sld:VendorOption name="conflictResolution">true</sld:VendorOption>
      </sld:TextSymbolizer>
    </sld:Rule>
    <sld:Rule>
      <sld:MinScaleDenominator>68000.0</sld:MinScaleDenominator>
      <sld:PointSymbolizer>
        <sld:Graphic>
          <sld:Mark>
            <sld:WellKnownName>circle</sld:WellKnownName>
            <sld:Fill>
              <sld:CssParameter name="fill">#FF0000</sld:CssParameter>
            </sld:Fill>
          </sld:Mark>
          <sld:Size>
            <ogc:Literal>6</ogc:Literal>
          </sld:Size>
        </sld:Graphic>
      </sld:PointSymbolizer>
    </sld:Rule>
  </sld:FeatureTypeStyle>
</sld:UserStyle>

share|improve this answer
    
while this is technically a correct answer it doesn't really help the questioner figure out what to do – iant Apr 24 '13 at 7:34
1  
@iant I improved the answer, but actually there is not so much to explain...also the questioner was asking for an example :) – Tommaso Apr 24 '13 at 8:10
    
Doesn't this apply to the points as well as their labels? I think the question was about turning the labels on and off at different scales, not the points too. – geobar Feb 3 at 9:29

Checkout the following sentences:

 <sld:MinScaleDenominator>68000.0</sld:MinScaleDenominator>
 <sld:MaxScaleDenominator>68000.0</sld:MaxScaleDenominator>

They set the limits to apply a rule.

Examples: in the official Geoserver doc and this other doc

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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