}
Point upperLeft = currentContext.worldToPixel( new Coordinate( envelope.getMinX(), envelope.getMinY()) );
Point bottomRight = currentContext.worldToPixel( new Coordinate( envelope.getMaxX(), envelope.getMaxY()) );
Rectangle screenSize = new Rectangle( upperLeft );
screenSize.add( bottomRight );
IMapDisplay mapDisplay = currentContext.getMapDisplay();
AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) geoResource.resolve( AbstractGridCoverage2DReader.class, monitor);
if( reader == null ){
return; // unable to connect!
}
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();