} else {
destinationEnvelopeInSourceCRS = reader.getOriginalEnvelope();
destinationEnvelope = destinationEnvelopeInSourceCRS;
}
final GridCrsType gridCRS = request.getOutput().getGridCRS();
// TODO: handle time domain subset...
// Compute the target crs, the crs that the final coverage will be
// served into
final CoordinateReferenceSystem targetCRS;
if (gridCRS == null)
targetCRS = reader.getOriginalEnvelope().getCoordinateReferenceSystem();
else
targetCRS = CRS.decode(gridCRS.getGridBaseCRS());
// grab the grid to world transformation
MathTransform gridToCRS = reader.getOriginalGridToWorld(PixelInCell.CELL_CORNER);
if (gridCRS != null) {
Double[] origin = (Double[]) gridCRS.getGridOrigin();
Double[] offsets = (Double[]) gridCRS.getGridOffsets();
// from the specification if grid origin is omitted and the crs
// is 2d the default it's 0,0
if (origin == null) {
origin = new Double[] { 0.0, 0.0 };
}
// if no offsets has been specified we try to default on the
// native ones
if (offsets == null) {
if (!(gridToCRS instanceof AffineTransform2D)
&& !(gridToCRS instanceof IdentityTransform))
throw new WcsException(
"Internal error, the coverage we're playing with does not have an affine transform...");
if (gridToCRS instanceof IdentityTransform) {
if (gridCRS.getGridType().equals(GridType.GT2dSimpleGrid))
offsets = new Double[] { 1.0, 1.0 };
else
offsets = new Double[] { 1.0, 0.0, 0.0, 1.0 };
} else {
AffineTransform2D affine = (AffineTransform2D) gridToCRS;
if (gridCRS.getGridType().equals(GridType.GT2dSimpleGrid))
offsets = new Double[] { affine.getScaleX(), affine.getScaleY() };
else
offsets = new Double[] { affine.getScaleX(), affine.getShearX(),
affine.getShearY(), affine.getScaleY() };
}
}
// building the actual transform for the resulting grid geometry
AffineTransform tx;
if (gridCRS.getGridType().equals(GridType.GT2dSimpleGrid.getXmlConstant())) {
tx = new AffineTransform(offsets[0], 0, 0, offsets[1], origin[0], origin[1]);
} else {
tx = new AffineTransform(offsets[0], offsets[2], offsets[1], offsets[3],
origin[0], origin[1]);
}