从GetFeature / getGetFeatureInfoUrl获取准确的I和J值以用于WMS平铺图像

时间:2018-10-10 18:28:55

标签: openlayers geoserver

我所拥有的: 带有netcdf扩展的Geoserver 2.13.2

Openlayers Webmap

我可以将netcdf文件作为WMS上的图像提供给地图

https://i.imgur.com/UtnNU8V.png

我使用以下方法创建WMS图层

function CreateWMSLayer(name, url) {
varname = name.split(":")[1];
window[varname] = new ol.layer.Tile({
    name: varname,
    visible: true,
    source: new ol.source.TileWMS({
        url: url,
        params: {'FORMAT': format,
               'VERSION': '1.3.0',
               tiled: true,
            LAYERS: name,
            crossOrigin: 'anonymous'
                }
    })
});
}
CreateWMSLayer('clmnc:CCLM5km_ERA_FF_10M_1991_2000_lonlat_ymonmean', https://url/geoserver/wms)

我收到了点击事件

function getValueMouseClick(evt) {
   document.getElementById('info').innerHTML = '';
   var viewResolution =  (view.getResolution());
   var lala =  eval(document.getElementById("LAYERS").value);
   //lala = 'CCLM5km_ERA_FF_10M_1991_2000_lonlat_ymonmean' 

   var url = lala.getSource().getGetFeatureInfoUrl(
      evt.coordinate, viewResolution, 'EPSG:3857',
                {'INFO_FORMAT': 'application/json'   });

wmspagedata = [];
$.getJSON(url, function (data) {
   for (var key in data.features[0].properties) {
   wmspagedata = data.features[0].properties[key]
   };
if (url) {
      document.getElementById('info').innerHTML =
          '<span>' + wmspagedata.toFixed(2) + '</span>';
        }
});
}

当我单击图像中的地图时,获取getJSON的网址如下:

https://url/geoserver/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=clmnc%3ACCLM5km_ERA_FF_10M_1991_2000_lonlat_ymonmean&tiled=true&LAYERS=clmnc%3ACCLM5km_ERA_FF_10M_1991_2000_lonlat_ymonmean&crossOrigin=anonymous&INFO_FORMAT=application%2Fjson&BBOX=0%2C0%2C20037508.342789244%2C20037508.342789244&I=9&J=174&WIDTH=256&HEIGHT=256&CRS=EPSG%3A3857&STYLES=

问题与解答: 据我了解:

bbox适用于整个世界(0,0,20037508.342789244,20037508.34278924)。 Openlayers用256x256创建了整个世界的图像,我单击了该图像的i = 9 j = 174像素。但是我的照片只在西欧洲看到了

https://i.imgur.com/UtnNU8V.png

如何定义返回的i和j对应于图像中的像素。因为现在我只得到一堆像素的一个值,该像素恰好位于256x256瓦片之一内。

如果我将url手册设置为类似(在WGS84中,但可​​以使用)

https://url/geoserver/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=clmnc%3ACCLM5km_ERA_FF_10M_1991_2000_lonlat_ymonmean&tiled=true&LAYERS=clmnc%3ACCLM5km_ERA_FF_10M_1991_2000_lonlat_ymonmean&crossOrigin=anonymous&INFO_FORMAT=application%2Fjson&WIDTH=450&HEIGHT=300&I=9&J=174&CRS=EPSG:4326&STYLES=&BBOX=44.22000167999778,-2.3199999520932644,56.22000076140847,15.67999984718909

在其中定义netcdf之后的Width和Height并根据GetCapabilties制作边界框的情况下,我可以手动更改i和j并获得每个像素期望的不同值。 我尝试过类似的

var url = lala.getSource().getGetFeatureInfoUrl(
      evt.coordinate, viewResolution, 'EPSG:3857',
        {'INFO_FORMAT': 'application/json',
        'BBOX' : '4922548.0699,-258331.815256,6258381.85716,1767694.40537' , 
        'WIDTH' : '450' ,
        'HEIGHT': '300',
             } ….

但是它不会覆盖url参数。如果我键入BBOX2,它将正确附加参数,但仍附加默认的BBOX(这是正确的行为,因为未定义bbox2)

Tl; dr:如何获取Click坐标以适合我的450x300图片以获取准确的返回值

0 个答案:

没有答案