static final Logger LOGGER = Logging.getLogger(WMSLayerIdentifier.class);
public List<FeatureCollection> identify(FeatureInfoRequestParameters params, int maxFeatures) throws IOException {
final int x = params.getX();
final int y = params.getY();
WMSLayerInfo info = (WMSLayerInfo) params.getLayer().getResource();
WebMapServer wms = info.getStore().getWebMapServer(null);
Layer layer = info.getWMSLayer(null);
CoordinateReferenceSystem crs = params.getRequestedCRS();
if (crs == null) {
// use the native one
crs = info.getCRS();
}
ReferencedEnvelope bbox = params.getRequestedBounds();
int width = params.getWidth();
int height = params.getHeight();
// we can cascade GetFeatureInfo on queryable layers and if the GML mime type is supported
if (!layer.isQueryable()) {
return null;
}
List<String> infoFormats;
infoFormats = wms.getCapabilities().getRequest().getGetFeatureInfo().getFormats();
if (!infoFormats.contains("application/vnd.ogc.gml")) {
return null;
}
// the wms layer does request in a CRS that's compatible with the WMS server srs
// list,
// we may need to transform
WMSLayer ml = new WMSLayer(wms, layer);
// delegate to the web map layer as there's quite a bit of reprojection magic
// code
// that we want to be consistently reproduced for GetFeatureInfo as well
final InputStream is = ml.getFeatureInfo(bbox, width, height, x, y,
"application/vnd.ogc.gml", maxFeatures);
List<FeatureCollection> results = new ArrayList<FeatureCollection>();
try {
Parser parser = new Parser(new WFSConfiguration());
parser.setStrict(false);
Object result = parser.parse(is);
if (result instanceof FeatureCollectionType) {
FeatureCollectionType fcList = (FeatureCollectionType) result;
List<SimpleFeatureCollection> rawResults = fcList.getFeature();
// retyping feature collections to replace name and namespace
// from cascading server with our local WMSLayerInfo
for (SimpleFeatureCollection fc : rawResults) {
SimpleFeatureType ft = fc.getSchema();
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.init(ft);
builder.setName(info.getName());
builder.setNamespaceURI(info.getNamespace().getURI());
SimpleFeatureType targetFeatureType = builder.buildFeatureType();
FeatureCollection rfc = new ReTypingFeatureCollection(fc, targetFeatureType);
results.add(rfc);