Is it possible to restyle a Geoserver WMS so that the color ramp is stretched across the min max values for the current map extent (bounding box)?

I want to do this for a single band DEM dataset. This way, when zooming in to an area, the fine detail will be visible.

I have used a custom SLD_BODY parameter in WMS requests to restyle rasters in a previous project. But this approach requires knowledge of the min and max values for the current map extent!

Perhaps the only practical option is client side styling with COG rasters?

  • I would try the normalize function docs.geoserver.org/latest/en/user/styling/sld/reference/….
    – user30184
    Commented Aug 22, 2022 at 5:26
  • I think for the normalize function we would need to specify the min and max of the raster data we want shown in the current bounding box, or it will just use the min and max of the entire band... Am I wrong?
    – staf
    Commented Aug 22, 2022 at 6:16
  • If you use a simple raster style it will do this by default
    – Ian Turton
    Commented Aug 22, 2022 at 6:55
  • see gis.stackexchange.com/questions/422532/…
    – Ian Turton
    Commented Aug 22, 2022 at 11:51
  • @IanTurton I think this differs from that question because it applies to panning too (I'm assuming), not just zooming. I actually meant to ask a similar question but never got around to it. Commented Aug 22, 2022 at 12:17

1 Answer 1


I think the best solution would be to make a WPS request to calculate the min and max for current viewport on demand (i.e. via a button 'Stretch Color Ramp to View Extent'), and then submit a new WMS request using the min and max in a SLD_BODY parameter to restyle it.

  • That seems like the most obvious solution, but how fast is it in practice? You have to loop through 1M+ values and then paint 1M+ pixels after that. Or are you suggesting a halfway measure: only recompute the min and max when the user pushes a button (which I had also considered)? Commented Aug 25, 2022 at 13:32
  • Hi Barry, yes I think just when the user pushes a button. Something like 'Stretch Color Ramp'. Whats your use case out of interest? Thanks for your contribution to this issue
    – staf
    Commented Aug 29, 2022 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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