Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

2 Answers 2

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
    
@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

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.