radius = maxRadius;
Polygon pixelRect = getEnvelopeFilter(x, y, width, height, bbox, radius);
if ((requestedCRS != null) && !CRS.equalsIgnoreMetadata(dataCRS, requestedCRS)) {
try {
MathTransform transform = CRS.findMathTransform(requestedCRS, dataCRS, true);
pixelRect = (Polygon) JTS.transform(pixelRect, transform); // reprojected
} catch (MismatchedDimensionException e) {
LOGGER.severe(e.getLocalizedMessage());
} catch (TransformException e) {
LOGGER.severe(e.getLocalizedMessage());
} catch (FactoryException e) {
LOGGER.severe(e.getLocalizedMessage());
}
}
final FeatureSource<? extends FeatureType, ? extends Feature> featureSource;
featureSource = layerInfo.getFeatureSource(false);
FeatureType schema = featureSource.getSchema();
Filter getFInfoFilter = null;
try {
GeometryDescriptor geometryDescriptor = schema.getGeometryDescriptor();
String localName = geometryDescriptor.getLocalName();
getFInfoFilter = ff.intersects(ff.property(localName), ff.literal(pixelRect));
} catch (IllegalFilterException e) {
e.printStackTrace();
throw new WmsException(null, "Internal error : " + e.getMessage());
}
// include the eventual layer definition filter
if (filters[i] != null) {
getFInfoFilter = ff.and(getFInfoFilter, filters[i]);
}
// see if we can include the rule filters as well, if too many we'll do them in memory
Filter postFilter = Filter.INCLUDE;
Filter rulesFilters = buildRulesFilter(ff, rules);
if(!(rulesFilters instanceof Or) ||
(rulesFilters instanceof Or && ((Or) rulesFilters).getChildren().size() <= 20)) {
getFInfoFilter = ff.and(getFInfoFilter, rulesFilters);
} else {
postFilter = rulesFilters;
}
String typeName = schema.getName().getLocalPart();
Query q = new DefaultQuery(typeName, null, getFInfoFilter, request.getFeatureCount(), Query.ALL_NAMES, null);
FeatureCollection<? extends FeatureType, ? extends Feature> match;
match = featureSource.getFeatures(q);
// if we could not include the rules filter into the query, post process in memory
if(!Filter.INCLUDE.equals(postFilter))
match = new FilteringFeatureCollection(match, postFilter);
//this was crashing Gml2FeatureResponseDelegate due to not setting
//the featureresults, thus not being able of querying the SRS
//if (match.getCount() > 0) {
results.add(match);
metas.add(layerInfo);
//}
} else {
final CoverageInfo cinfo = requestedLayers[i].getCoverage();
final AbstractGridCoverage2DReader reader=(AbstractGridCoverage2DReader) cinfo.getGridCoverageReader(new NullProgressListener(),GeoTools.getDefaultHints());
final ParameterValueGroup params = reader.getFormat().getReadParameters();
final GeneralParameterValue[] parameters = CoverageUtils.getParameters(params, requestedLayers[i].getCoverage().getParameters(),true);
//get the original grid geometry
final GridGeometry2D coverageGeometry=(GridGeometry2D) cinfo.getGrid();
// set the requested position in model space for this request
final Coordinate middle = pixelToWorld(x, y, bbox, width, height);
DirectPosition position = new DirectPosition2D(requestedCRS, middle.x, middle.y);
//change from request crs to coverage crs in order to compute a minimal request area,
// TODO this code need to be made much more robust
if (requestedCRS != null) {
final CoordinateReferenceSystem targetCRS = coverageGeometry.getCoordinateReferenceSystem();
final TransformedDirectPosition arbitraryToInternal = new
TransformedDirectPosition(requestedCRS, targetCRS, new Hints(Hints.LENIENT_DATUM_SHIFT,Boolean.TRUE));
try {
arbitraryToInternal.transform(position);
} catch (TransformException exception) {
throw new CannotEvaluateException("Unable to answer the geatfeatureinfo",exception);
}
position=arbitraryToInternal;
}
//check that the provided point is inside the bbox for this coverage
if(!reader.getOriginalEnvelope().contains(position)) {
continue;
}
//now get the position in raster space using the world to grid related to corner
final MathTransform worldToGrid=reader.getOriginalGridToWorld(PixelInCell.CELL_CORNER).inverse();
final DirectPosition rasterMid = worldToGrid.transform(position,null);
// create a 20X20 rectangle aruond the mid point and then intersect with the original range
final Rectangle2D.Double rasterArea= new Rectangle2D.Double();
rasterArea.setFrameFromCenter(rasterMid.getOrdinate(0), rasterMid.getOrdinate(1), rasterMid.getOrdinate(0)+10, rasterMid.getOrdinate(1)+10);
final Rectangle integerRasterArea=rasterArea.getBounds();
final GridEnvelope gridEnvelope=reader.getOriginalGridRange();