* @see org.opengis.coverage.grid.GridCoverageWriter#write(org.geotools.gc.GridCoverage,
* org.opengis.parameter.GeneralParameterValue[])
*/
public void write(GridCoverage coverage, GeneralParameterValue[] parameters)
throws IllegalArgumentException, IOException {
final GridCoverage2D gc = (GridCoverage2D) coverage;
// checking parameters
// if provided we have to use them
// specifically this is one of the way we can provide an output format
if (parameters != null) {
this.extension = ((Parameter) parameters[0]).stringValue();
}
// /////////////////////////////////////////////////////////////////////
//
// WorldFile and projection file.
//
// ////////////////////////////////////////////////////////////////////
if (destination instanceof File) {
// files destinations
File imageFile = (File) destination;
final String path = imageFile.getAbsolutePath();
final int index = path.lastIndexOf(".");
final String baseFile = index >= 0 ? path.substring(0, index)
: path;
// envelope and image
final RenderedImage image = gc.getRenderedImage();
// world file
try {
createWorldFile(coverage, image, baseFile,extension);
} catch (TransformException e) {
final IOException ex = new IOException();
ex.initCause(e);
throw ex;
}
// projection file
createProjectionFile(baseFile, coverage
.getCoordinateReferenceSystem());
}
// /////////////////////////////////////////////////////////////////////
//
// Encoding of the original coverage
//
// ////////////////////////////////////////////////////////////////////
outStream = ImageIOExt.createImageOutputStream(gc.getRenderedImage(), destination);
if (outStream == null)
throw new IOException(
"WorldImageWriter::write:No image output stream avalaible for the provided destination");
this.encode(gc, outStream,extension);