Here's a complete, production-ready SLD style for GeoServer that dynamically renders a Digital Terrain Model (DTM) raster using hypsometric colors scaled to the current map view's elevation range. This solution uses Normalize contrast enhancement to automatically adjust the color palette based on the actual elevation values visible in the current GetMap request (e.g., zooming into a valley will show subtle green/blue variations, while zooming into mountains will show brown/white variations).
🌄 SLD Style Definition (Copy-Paste Ready)
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd"
version="1.1.0">
<NamedLayer>
<Name>your_dtm_layer_name</Name> <!-- REPLACE WITH YOUR ACTUAL LAYER NAME -->
<UserStyle>
<Title>Dynamic Hypsometric Color Scale</Title>
<Abstract>Dynamic hypsometry style that scales colors to the current map view's elevation range.
Adjust color/quantity values to match your dataset's elevation range.</Abstract>
<FeatureTypeStyle>
<Rule>
<RasterSymbolizer>
<!-- Define hypsometric color ramp for full elevation range of your dataset -->
<ColorMap type="ramp">
<!-- Water/Sea Level -->
<ColorMapEntry color="#0000FF" quantity="-10" label="Water" opacity="1.0"/>
<ColorMapEntry color="#0080FF" quantity="0" label="Sea Level" opacity="1.0"/>
<!-- Lowlands -->
<ColorMapEntry color="#00FF00" quantity="50" label="Lowland" opacity="1.0"/>
<ColorMapEntry color="#7CFC00" quantity="100" label="Hills" opacity="1.0"/>
<!-- Mid-Elevations -->
<ColorMapEntry color="#FFFF00" quantity="500" label="Midland" opacity="1.0"/>
<ColorMapEntry color="#FFA500" quantity="1000" label="Hill" opacity="1.0"/>
<!-- Mountains -->
<ColorMapEntry color="#8B4513" quantity="2000" label="Mountain" opacity="1.0"/>
<ColorMapEntry color="#A0522D" quantity="3000" label="High Mountain" opacity="1.0"/>
<!-- Snow/Peaks -->
<ColorMapEntry color="#FFFFFF" quantity="4000" label="Snow" opacity="1.0"/>
</ColorMap>
<!-- CRITICAL: Dynamic scaling to current view's min/max elevation -->
<ContrastEnhancement>
<Normalize/>
</ContrastEnhancement>
</RasterSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
🔑 Key Features & Why This Works
-
Dynamic Scaling via <Normalize/>
- GeoServer automatically calculates the minimum and maximum elevation values in the current map view (from the
GetMap request).
- These values are stretched to the full range of your
ColorMap entries (e.g., if the current view has elevations from 150m to 350m, then 150m maps to the first color (#0000FF), 350m maps to the last color (#FFFFFF), and intermediate values interpolate between colors).
- No hard-coded min/max – works perfectly for any zoom level or geographic area.
-
Hypsometric Color Palette
- Standard elevation-based colors:
- Blue → Water/Sea Level
- Green → Lowlands
- Yellow/Orange → Mid-elevations
- Brown → Mountains
- White → Snow/Peaks
- Adjust quantities/colors to match your dataset's typical elevation range (e.g., if your DTM is for a region with max 2000m, scale down quantities accordingly).
-
Nodata Handling
⚙️ How to Use
- Replace
your_dtm_layer_name with the actual name of your DTM layer in GeoServer.
- Adjust elevation quantities/colors to match your dataset:
- Upload to GeoServer:
- Go to GeoServer → Styles → Add new style.
- Paste this SLD, then assign it to your DTM layer.
💡 Pro Tips
- For smoother transitions: Add more
ColorMapEntry points (e.g., between 1000–2000m).
- Avoid "flat" colors: Use gradients like
#00FF00 → #7CFC00 for lowlands instead of a single green.
- Water bodies: If your DTM includes bathymetry, extend the blue palette below sea level (e.g.,
quantity="-50" for deep water).
- Test dynamically: Zoom into a valley → see subtle green/blue variations. Zoom into a peak → see brown/white variations. This is the dynamic hypsometry effect.
✅ Why this is better than static styles:
Static styles use fixed elevation ranges (e.g., 0–5000m), so zooming into a small area (e.g., 100–200m elevation) shows only a tiny sliver of the color palette. This dynamic approach ensures every zoom level shows meaningful color variation.
🌍 Example Output
| Zoom Level | What You See |
|---|
| Global view | Full color spectrum: blue oceans → green lowlands → brown mountains → white peaks |
| Zoomed into valley (100–200m) | Smooth gradient from blue (100m) to green (200m) – no "flat" colors |
| Zoomed into Alps (2000–3000m) | Brown (2000m) → white (3000m) – high contrast for peaks |
This style works with any single-band raster (e.g., GeoTIFF, DEM) and is optimized for real-time rendering in GeoServer. Adjust quantities to match your data! 🗻