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 have a client application, "talking" to my GeoWebCache service (using TMS), showing a map. The map is built out or a few raster layers. I need to show only one of them a time - depending on the zoom level (scale), one of the layers should be shown - the rest not visible.

The client can use only one "link" to access the map - I cannot switch the layers on the client.

I created a group layer on GeoServer (2.1.4) built out of the two layers I am using (250k and StreetView from OS). I cannot see any way to specify that one of them should be seen when the scale is less then N and the other otherwise. I tried a style for raster layer, specifying opacity depending on the scale, but it does not seem to work. How is it done on GeoServer?

If it is doable on GeoWebCache level, that would be fine too. I successfully added the layers to geowebcache.xml file (I need the epsg:27700 projection, that is why the config was needed), but cannot find a way of saying "use this wms url when scale is less than N".

Any help will be much appreciated, thank you.

---- UPDATE after the answer - the solution ----

I have two styles created, called raster-0-50k and raster-50k-up. Here is the first one of them, which I applied to the layer at the bottom of the stack (the top one in the list of the group layer):

  <NamedLayer>
    <Name>raster-0-50k</Name>
    <UserStyle>
    <!-- Styles can have names, titles and abstracts -->
      <Title>Raster 0 to 50k</Title>
      <Abstract>Raster, showing scale 0 to 50000</Abstract>
      <!-- FeatureTypeStyles describe how to render different features -->
      <!-- A FeatureTypeStyle for rendering rasters -->
      <FeatureTypeStyle>
        <Rule>
          <Name>rule1</Name>
          <Title>Opaque Raster</Title>
          <Abstract>A raster with 100% opacity</Abstract>
          <MaxScaleDenominator>50000</MaxScaleDenominator>
          <RasterSymbolizer>
            <Opacity>1.0</Opacity>
          </RasterSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>

the other style does exactly opposite - sets opacity to 1 for scale 50k and higher. In the group layer's list, I associated the two styles with my two layers.

It does work now :) Thank you.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

You need to specify a min/max scale denominator in your SLD files. Use the same figure in each style, that is the max in one is the min in the other, so that only one layer is drawn at any scale. Then combine the layers in a layer group and away you go. See http://docs.geoserver.org/latest/en/user/styling/sld-reference/rules.html for more details on the syntax.

share|improve this answer
    
Thank you, iant. I have applied your suggestion and it helped. Can you have a look at my update above - I put there one of the styles. There is still some problem with the GeoServer processing both (all) the layers. Is there any way to stop this happening? –  mapuser Jun 15 '12 at 9:09
    
Just leave out rule2 - if the rule doesn't apply at the scale requested then nothing will be drawn. –  iant Jun 15 '12 at 9:33
    
It does work! Thanks a lot :) I will update the xml above to show the final result. I was assuming that if no rule applies to the NamedLayer element, the layer would be rendered with some default style. I was wrong. –  mapuser Jun 15 '12 at 11:03

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.