4

I'm trying to retrieve a list of all values from a raster layer (GeoTIFF) in GeoServer (2.5.x).

I tried to modify the code from http://trac.osgeo.org/openlayers/wiki/GetFeatureInfo but I can't seem to find a way to do this. I create a custom control that uses the OpenLayers.Handler.Box as input. This gives me back the right bounds (selected rectangle coordinates) but how do I send the bounds to GeoServer WMS?

I can code a Python module to send the bounds to and extract the values from the raster and send it back to my web application but I thought this must be possible from within OpenLayers?

Does anyone have an example of how do extract a range of values from a raster using GeoServer and OpenLayers?

My code so far:

function findLayerClick(event) {
    mouseLoc = map.getLonLatFromPixel(event.xy);
    layerlist = 'mylayer';
    //GetCoverage
    var url = sec.getFullRequestString({
                                        REQUEST: "GetFeatureInfo",
                                        EXCEPTIONS: "application/vnd.ogc.se_xml",
                                        BBOX: map.getExtent().toBBOX(),
                                        X: event.xy.x,
                                        Y: event.xy.y,
                                        INFO_FORMAT: 'text/plain',
                                        QUERY_LAYERS: layerlist,
                                        FEATURE_COUNT: 50,
                                        WIDTH: map.size.w,
                                        HEIGHT: map.size.h},
                                        "http://localhost:8080/geoserver/wms");

    var request = OpenLayers.Request.GET({
      url: url,
      callback: extractFeatures
    });
  }

  function extractFeatures(e) {
    console.log(e);
  }

My map, layers, and the control handling the box select:

function init() {
    wgs84 = new OpenLayers.Projection('EPSG:4326');
    googleProjection = new OpenLayers.Projection('EPSG:900913');

var options = {
      controls: [
                  new OpenLayers.Control.LayerSwitcher(),
                  new OpenLayers.Control.Navigation({zoomWheelEnabled: true, handleRightClicks: true}),
                  new OpenLayers.Control.PanZoom(),
                  new OpenLayers.Control.DragPan(),
                  new OpenLayers.Control.ScaleLine({maxWidth:200})
                ],

      div: 'map-canvas',
      theme: null,
      units: 'm',
      projection: googleProjection,
      displayProjection: wgs84,
      maxResolution: 'auto',

      eventListeners: {
          'movestart': function(e) {
          },
          'zoomend': function(e) {
              zoomBoxControl.deactivate();
          }
      }
    };

    map = new OpenLayers.Map(options);

    var ghyb = new OpenLayers.Layer.Google(
        "Google Physical",
        {
          type: google.maps.MapTypeId.TERRAIN,
          minZoomLevel: 1,
          numZoomLevels: 11,
          sphericalMercator: true,
          projection: 'EPSG:900913'
        }
    );

    //this is the raster layer
    sec = new OpenLayers.Layer.WMS(
      "mylayer",
      "http://localhost:8080/geoserver/wms",
      {layers: 'mylayer', format:'image/png', transparent:'true'},
      {opacity: 1.0, visibility: true, displayInLayerSwitcher: true, isBaseLayer: false}
    );

     OpenLayers.Util.extend(control, {
      draw: function () {
          this.drag = new OpenLayers.Handler.Box( control,
              {"done": this.notice},
              {keyMask: OpenLayers.Handler.MOD_CTRL});
          this.drag.activate();
      },

      notice: function (bounds) {
        mybounds = bounds;


        console.log(mybounds);

        var lowerLeft = map.getLonLatFromPixel(new OpenLayers.Pixel(mybounds.left, mybounds.bottom));
        var upperRight = map.getLonLatFromPixel(new OpenLayers.Pixel(mybounds.right, mybounds.top));

        mybounds = new OpenLayers.Bounds();
        mybounds.extend(lowerLeft);
        mybounds.extend(upperRight);

        //findLayerClick(mybounds);
        return(true);
      }
    });
  }

The findLayerClick function returns back a valid value of a clicked pixel but i need the list (table, array or whatever) of values in the selected range. Hope someone can help me.

  • any luck here @Loki ? – jotamon Oct 27 '17 at 21:14
  • Is there only WMS enabled on GeoServer? Could it also have a WCS – nmtoken Dec 14 '17 at 15:59
1

I tried to modify the code from http://trac.osgeo.org/openlayers/wiki/GetFeatureInfo but I can't seem to find a way to do this.

You can't use a WMS GetFeatureInfo request to retrieve a range of values, because it only works on a point location (in a GetMap image.) This is a limitation of the WMS specification.

Furthermore a WMS doesn't give you the actual values from your input data (even if it's a raster dataset) it gives a representation of the data. If you want to get at the data values in a GeoTIFF sitting on GeoServer you will need to configure a WCS service.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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