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();
final Rectangle originalArea=
(gridEnvelope instanceof GridEnvelope2D)?
(GridEnvelope2D)gridEnvelope: