1

I have layer (ImageWMS that has GeoTIFF format) and also OSM or another for my baselayer. According to https://openlayers.org/en/latest/examples/disable-image-smoothing.html I should get pixel[0] and pixel[1] and pixel[2] to calculate height . But I have an image layer and when clicked on image layer I received pixel values of base layer not image layer. So I added filter to my codes for showing just image layer's pixel value but console show me (NON). How can I find the pixel value of image layer or better way for calculate height from image layer (raster layer .tiff)?

Here is my code :

const UnTiled = new ol.layer.Image({
        opacity:0.9,
        title:'UnTiled',
        source: new ol.source.ImageWMS({
            ratio: 1,
            url: 'http://localhost:8080/geoserver/world/wms',
            params: {
                     'VERSION': '1.1.1',  
                  "STYLES": '',
                  "LAYERS": 'world:world',
                  "exceptions": 'application/vnd.ogc.se_inimage',
            }
        
          })
          
        });map.addLayer(UnTiled);

map.on('singleclick', function(evt) {
map.forEachLayerAtPixel(
    evt.pixel,
    function (layer, pixel) {
      var height =
        -10000 + (pixel[0] * 256 * 256 + pixel[1] * 256 + pixel[2]) * 0.1;
        console.log(height)
    },
    {
      layerFilter: function (layer) {
        return layer === UnTiled;
      },
    }
  );
})
4
  • It's not clear to me how this differs from your last (duplicate) question, if you want to query a WMS you need to use GetFeatureInfo requests. Please edit this question to explain what you are trying to do in more detail. Note currently your request will be returning a PNG not a TIFF as you don't set the output format.
    – Ian Turton
    Commented Feb 28, 2021 at 10:07
  • You are getting values from the base layer because (as in the linked example) you need to specify a unique className in the overlay layer options to ensure it is rendered on separate canvas. You are need the imageSmoothing: false option otherwise the browser will smooth the output and the pixel values will be meaningless. PNG is correct to display the WMS as most browsers cannot display TIFF.
    – Mike
    Commented Feb 28, 2021 at 10:51
  • @IanTurton I think it's clear enough from title "Get pixel value of ImageWMS" and from body of the question "I should get pixel[0] and pixel[1] and pixel[2] to calculate height" what the question is about. There is no need for GetFeatureInfo request.
    – TomazicM
    Commented Feb 28, 2021 at 17:07
  • I'm not quite sure how you get a pixel value of wms layer with out a getfeatureinfo call, otherwise you are just looking at a picture of the data. But feel free to edit the question to make it clearer or vote to reopen as is.
    – Ian Turton
    Commented Feb 28, 2021 at 17:57

0