3

I have tried to send manual Wms GetFeatureInfo request to geoserver with the parameter values X and Y (pixel values) taken from the map object of OpenLayers.

I have got the response with the wrong values which is not matched with the values I have seen in the geoserver preview with the same long/lat.

The requested url was:

geoserverUrl/wms?REQUEST=GetFeatureInfo&EXCEPTIONS=application/vnd.ogc.se_xml&BBOX=getextentValue&SERVICE=WMS&INFO_FORMAT=text/html&QUERY_LAYERS=xxxxx:atm&Layers=xxxxx:atm&WIDTH=mapwidth&HEIGHT=mapheight&format=image/jpeg&styles=&srs=EPSG:4326&version=1.1.1&x=eventxvalue&y=eventyvalue";

I have referred with these posts also: Can Geoserver return the raster value of a lat/lon point.

Is there any possible ways to give the clicked long/lat values given instead of X and Y pixel values in the geoserver wms getfeatureinfo request??

or

what are the factors which is to be clear when making this request manually. More particular width,height and the bbox values.

In client side I have made an ajax call:

map.events.register("click",this, function(e){

    var clickedLatLong =map.getLonLatFromViewPortPx(e.xy);
    var clickedPixel =  map.getPixelFromLonLat(clickedLatLong);
    //alert(clickedLatLong);
    //alert(map.size);
    if(!map.getMaxExtent().containsLonLat(clickedLatLong)) {
        return;
    }else{

        alert(clickedPixel);
        var bbox = map.getExtent();
        alert(bbox);
        $.ajax({
            type: 'GET',
            url: 'getMultiLayersValue.html',    
            dataType: 'html',
            data:{long:clickedPixel.e.x,lat:clickedPixel.e.y},

            success : function(result){
                alert(result);
                $("#DisplayResponse").html(result);
                $("#DisplayResponse").dialog( "open" );

            },
            complete:function(xhr, txtStatus){

            },
            error: function(xhr, error){
                showLoadingMaskDialog(false,loadingText);
                alert("Taking More Time to Respond\n Please Try Later or Contact System Administrator");
            }
        });//ajax
}

In Server side I have made this URL request

"localhost:8080/geoserver/wms?REQUEST=GetFeatureInfo&EXCEPTIONS=application/vnd.ogc.se_xml&BBOX=getextentValue&SERVICE=WMS&INFO_FORMAT=text/html&QUERY_LAYERS=xxxxx:atm&Layers=xxxxx:atm&WIDTH=mapwidth&HEIGHT=mapheight&format=image/jpeg&styles=&srs=EPSG:4326&version=1.1.1&x=eventxvalue&y=eventyvalue";

Eventually no error messages were found only i got the wrong values for my clicked long/lat. May be the values of pixel getting wrong but i unable to find the solutions.

  • post some code and error messages – Gery Dec 2 '13 at 15:02
  • @grey I have added some code were i used to get the pixel or long/lat in clientside programming.And also the url at server side coding.No error messages were found only response values from the wrong pixels. – AshokDev Dec 4 '13 at 6:30
  • How do you know they are "wrong"? Have you looked at docs.geoserver.org/stable/en/user/services/wms/… ? If you want to get features by bounding box, perhaps you really wanted to use a WFS GetFeature query? – BradHards Dec 4 '13 at 7:22
  • If you want the features at at particular Lat & Long, it would be a better idea to use the GetFeatures on the WFS service. – Devdatta Tengshe Dec 4 '13 at 9:07
  • could you post a real example with some values? I don't use geoserver, so I can't tell you if that's the problem, but it seems that these ones var clickedLatLong =map.getLonLatFromViewPortPx(e.xy); var clickedPixel = map.getPixelFromLonLat(clickedLatLong); have some responsibility – Gery Dec 4 '13 at 20:51
1

Yes, see this answer: https://gis.stackexchange.com/a/211562/3399

This is the JavaScript implementation:

var parameters = {
  service: 'WMS',
  version: '1.1.1',
  request: 'GetFeatureInfo',
  layers: currentLayer,
  query_layers: currentLayer,
  feature_count: 10,
  info_format: 'text/javascript',
  format_options: 'callback:handleJson',
  SrsName: 'EPSG:4326',
  width: 101,
  height: 101,
  x: 50,
  y: 50,
  bbox: (lng - 0.1) + ',' + (lat - 0.1) + ',' + (lng + 0.1) + ',' + (lat + 0.1)
}
var url = owsurl + L.Util.getParamString(parameters)
$.ajax({
  url: owsurl + L.Util.getParamString(parameters),
  dataType: 'jsonp',
  success: function (data) {
    handleJson(data)
  }
})

Basically, you use the lat, lon to create a bounding box, and select the values in the middle of it. You can return JSON, which you can eat up with your code.

0

Is there any possible ways to give the clicked long/lat values given instead of X and Y pixel values in the geoserver wms getfeatureinfo request??

No.

A WMS GetFeatureInfo request is, by definition, a request for the data values at an image coordinate in a GetMap request (which always returns an image). In effect, the majority of the request parameters define the GetMap request and the X,Y (WMS 1.1.1) or I,J (WMS 1.3.0) defines the image coordinate.

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.