I have a GeoServer WMS layer that I cropped using the ol-ext filter.crop in OpenLayers. This is a layer that has only one band and pixel values between 0 and 100. I want to calculate the statistics of this cropped layer, for example the mean pixel value. How should I save the cropped layer in order to be able to access its pixel values?

  • 1
    WMS only gives an image representation of data, not access to the data; you may want to use WCS instead of WMS.
    – nmtoken
    Commented Apr 19, 2023 at 16:15
  • 1
    Coding question on GIS SE site should include relevant existing code, otherwise it's most likely to be closed as not compliant with the site policy. Please edit your question and add relevant existing code.
    – TomazicM
    Commented Apr 19, 2023 at 16:26
  • you might want to look at the WPS service GeoServer provides to allow clients to carry out this sort of calculation on the server
    – Ian Turton
    Commented Apr 20, 2023 at 7:41

1 Answer 1


Currently the only way to access pixel values in bulk is in a layer's postrender event where you could use event.context.getImageData(), or via an ol/source/Raster (which would need threads: 0 to share the results with the main thread).

The ol-ext cropping example is very similar internally to this OpenLayers example https://openlayers.org/en/latest/examples/layer-clipping-vector.html which could be extended to access the pixel data as in https://codesandbox.io/s/wms-image-forked-rtm7o8?file=/main.js

The same result could be achieved with a Raster source https://codesandbox.io/s/wms-image-forked-clb8xr?file=/main.js

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