Saturday, 20 August 2016

OpenLayers GetFeatureInfo for GeoServer Layer Groups


I've created a GeoServer layer group. I'm using OpenLayers.Layer.WMS to retrieve the layer group, and this works fine. In addition, I'd like to pull feature info for the layer. For this, I'm using OpenLayer's GetFeatureInfo. But the GetFeatureInfo only returns feature info for only one of the layers in the layer group. Is there a way I can retrieve feature info for both layers in the group? And, is this an optimal way of dealing with layer groups?


A section of my code is shown below:


    var layer_group = new OpenLayers.Layer.WMS(
"Sample Layer Group",

"http://localhost:8081/geoserver/wms",
{layers: "layer_group_name", transparent: true},
{isBaseLayer: false, visibility: false}
);
map.addLayers([layer_group]);

to retrieve the layer group.


And:


    map.events.register('click', map, function (e) {
var url = layer_group.getFullRequestString({

REQUEST: "GetFeatureInfo",
EXCEPTIONS: "application/vnd.ogc.se_xml",
BBOX: layer_group.map.getExtent().toBBOX(),
X: e.xy.x,
Y: e.xy.y,
INFO_FORMAT: 'text/html',
QUERY_LAYERS: layer_group.params.LAYERS,
WIDTH: layer_group.map.size.w,
HEIGHT: layer_group.map.size.h});


window.open(url,
"getfeatureinfo",
"location=0,status=0,scrollbars=1,width=600,height=150"
);
});

To retrieve the feature info.


My environment setup: GeoServer 2.1.3, PostGIS 1.5, OpenLayers 2.11.


EDIT: The features shown are only for one layer enter image description here


Increasing FEATURE_COUNT only increases the number of instances(rows) returned. The instances are over 1M. What I'd like to achieve is have one row having feature info for all the layers in the layer group.




Answer



There is no way to achieve what you want with a single request, a new custom behavior would need to be added that only gets only record for each layer. This would require coding, changing the GeoServer GetFeatureInfo code paths to handle a new vendor option (we cannot have such behavior by default, it's probably against the WMS spec).


The only thing I can think of is to know what layers are in the group and issue a separate GetFeatureInfo for each of the layers separately


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...