}
CoordinateReferenceSystem destinationCRS = currentContext.getCRS();
ReferencedEnvelope bounds = (ReferencedEnvelope) currentContext.getImageBounds();
bounds=bounds.transform(destinationCRS, true);
ParameterValueGroup group = geoResource.resolve( ParameterValueGroup.class, monitor);
if(group==null){
group=reader.getFormat().getReadParameters();
}
else{
// temporary fix for image-io (JG: what is the nature of this fix?)
try{
ParameterValue<?> jaiImageReaderParam = group.parameter(AbstractGridFormat.USE_JAI_IMAGEREAD.getName().toString());
if(jaiImageReaderParam!=null){
jaiImageReaderParam.setValue(false);
}
}catch (ParameterNotFoundException e) {
// do nothing
}
}
ParameterValue<?> readGridGeometry2DParam = group.parameter(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString());
// GridEnvelope range = new GridEnvelope2D(0, 0, mapDisplay.getWidth(), mapDisplay.getHeight());
// MathTransform displayToLayer = currentContext.worldToScreenMathTransform().inverse();
// ReferencingFactoryFinder.getMathTransformFactory(null).createConcatenatedTransform(displayToLayer,
// currentContext.getLayer().mapToLayerTransform());
// GridGeometry2D geom = new GridGeometry2D(range, displayToLayer, destinationCRS);
// readGridGeometry2DParam.setValue(geom);
GridEnvelope2D gridEnvelope = new GridEnvelope2D(0, 0, mapDisplay.getWidth(), mapDisplay.getHeight());
org.opengis.geometry.Envelope env;
double west= bounds.getMinX();
double east= bounds.getMaxX();
double south= bounds.getMinY();
double north= bounds.getMaxY();
if (destinationCRS != null) {
env = new ReferencedEnvelope(west, east, south, north, destinationCRS);
} else {
DirectPosition2D minDp = new DirectPosition2D(west, south);
DirectPosition2D maxDp = new DirectPosition2D(east, north);
env = new Envelope2D(minDp, maxDp);
}
readGridGeometry2DParam.setValue(new GridGeometry2D(gridEnvelope, env));
currentContext.setStatus(ILayer.WORKING);
setState( STARTING );
ParameterValue[] parameterValues = group.values().toArray(new ParameterValue[0]);
GridCoverage2D coverage = (GridCoverage2D) reader.read(parameterValues);
if(coverage!=null){
//setting rendering hints
//
RenderingHints hints = new RenderingHints(new HashMap<RenderingHints.Key,Object>());