// render via grid coverage renderer, that will apply the advanced projection
// handling
final Object params = feature.getProperty("params").getValue();
GeneralParameterValue[] readParameters = getReadParameters(params, null, null,
interpolation, readerBgColor);
final GridCoverageRenderer gcr = new GridCoverageRenderer(mapEnvelope.getCoordinateReferenceSystem(), mapEnvelope,
mapRasterArea, worldToScreen, interpolationHints);
gcr.setAdvancedProjectionHandlingEnabled(true);
gcr.setWrapEnabled(DefaultWebMapService.isContinuousMapWrappingEnabled());
image = gcr.renderImage(reader, readParameters, symbolizer, interpolation,
mapContent.getBgColor(), tileSizeX, tileSizeY);
if (image == null) {
// we're outside of the coverage definition area, return an empty space
image = createBkgImage(mapWidth, mapHeight, bgColor, null);
}
} else {
//
// Prepare the reading parameters (for the RT case)
//
final CoordinateReferenceSystem coverageCRS = layer.getFeatureSource().getSchema()
.getCoordinateReferenceSystem();
final GridGeometry2D readGG;
final boolean equalsMetadata = CRS.equalsIgnoreMetadata(mapCRS, coverageCRS);
boolean sameCRS;
try {
sameCRS = equalsMetadata ? true : CRS.findMathTransform(mapCRS, coverageCRS,
true).isIdentity();
} catch (FactoryException e1) {
final IOException ioe = new IOException();
ioe.initCause(e1);
throw ioe;
}
final boolean needsGutter = !sameCRS
|| !(interpolation instanceof InterpolationNearest);
if (!needsGutter) {
readGG = new GridGeometry2D(new GridEnvelope2D(mapRasterArea), mapEnvelope);
} else {
//
// SG added gutter to the drawing. We need to investigate much more and also we
// need to do this only when needed
//
// enlarge raster area
Rectangle bufferedTargetArea = (Rectangle) mapRasterArea.clone();
bufferedTargetArea.add(mapRasterArea.x + mapRasterArea.width + 10,
mapRasterArea.y + mapRasterArea.height + 10);
bufferedTargetArea.add(mapRasterArea.x - 10, mapRasterArea.y - 10);
// now create the final envelope accordingly
try {
readGG = new GridGeometry2D(new GridEnvelope2D(bufferedTargetArea),
PixelInCell.CELL_CORNER, new AffineTransform2D(
worldToScreen.createInverse()), mapCRS, null);
} catch (Exception e) {
final IOException ioe = new IOException();
ioe.initCause(e);
throw ioe;
}
}
RenderingTransformationHelper helper = new RenderingTransformationHelper() {
protected GridCoverage2D readCoverage(GridCoverage2DReader reader, Object params, GridGeometry2D readGG)
throws IOException {
return readBestCoverage(
reader,
params,
ReferencedEnvelope.reference(readGG.getEnvelope()),
readGG.getGridRange2D(),
interpolation,
readerBgColor);
}
};
Object result = helper.applyRenderingTransformation(transformation, layer.getFeatureSource(),
layer.getQuery(), Query.ALL, readGG, coverageCRS, interpolationHints);
if(result == null) {
coverage = null;
} else if(result instanceof GridCoverage2D) {
coverage = (GridCoverage2D) result;
} else {
// we don't know how to handle this case, we'll let streaming renderer fall back on this one
return null;
}
// apply the grid coverage renderer
final GridCoverageRenderer gcr = new GridCoverageRenderer(mapCRS,
ReferencedEnvelope.reference(readGG.getEnvelope()),
readGG.getGridRange2D(), worldToScreen, interpolationHints);
// create a solid color empty image
image = gcr.renderImage(coverage, symbolizer, interpolation,
mapContent.getBgColor(), tileSizeX, tileSizeY);
}
} catch (Throwable e) {
throw new ServiceException(e);
}