File info = new File(coverageDir, "info.xml");
info.createNewFile();
// let's grab the necessary metadata
AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(coverageFile);
AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) format.getReader(coverageFile);
// basic info
FileWriter writer = new FileWriter(info);
writer.write("<coverage format=\"" + coverage + "\">\n");
writer.write("<name>" + coverage + "</name>\n");
writer.write("<label>" + coverage + "</label>\n");
writer.write("<description>" + coverage + " description</description>\n");
writer.write("<metadataLink about = \"http://www.remotesensing.org:16080/websites/geotiff/geotiff.html\" metadataType = \"other\" />");
writer.write("<keywords>WCS," + coverage + " </keywords>\n");
if(styleName == null)
styleName = "raster";
writer.write("<styles default=\"" + styleName + "\"/>\n");
// envelope
CoordinateReferenceSystem crs = reader.getCrs();
GeneralEnvelope envelope = reader.getOriginalEnvelope();
GeneralEnvelope wgs84envelope = CoverageStoreUtils.getWGS84LonLatEnvelope(envelope);
final String nativeCrsName = CRS.lookupIdentifier(crs, false);
writer.write("<envelope crs=\"" + crs.toString().replaceAll("\"", "'") + "\" srsName=\"" + nativeCrsName + "\">\n");
writer.write("<pos>" + wgs84envelope.getMinimum(0) + " " + wgs84envelope.getMinimum(1) + "</pos>\n");
writer.write("<pos>" + wgs84envelope.getMaximum(0) + " " + wgs84envelope.getMaximum(1) + "</pos>\n");
writer.write("</envelope>\n");
/**
* Now reading a fake small GridCoverage just to retrieve meta information:
* - calculating a new envelope which is 1/20 of the original one
* - reading the GridCoverage subset
*/
final ParameterValueGroup readParams = reader.getFormat().getReadParameters();
final Map parameters = CoverageUtils.getParametersKVP(readParams);
double[] minCP = envelope.getLowerCorner().getCoordinates();
double[] maxCP = new double[] {
minCP[0] + (envelope.getLength(0) / 20.0),
minCP[1] + (envelope.getLength(1) / 20.0)
};
final GeneralEnvelope subEnvelope = new GeneralEnvelope(minCP, maxCP);
subEnvelope.setCoordinateReferenceSystem(reader.getCrs());
parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
new GridGeometry2D(reader.getOriginalGridRange(), subEnvelope));
GridCoverage2D gc = (GridCoverage2D) reader.read(CoverageUtils.getParameters(readParams, parameters,
true));
// grid geometry
final GridGeometry geometry = gc.getGridGeometry();
final int dimensions = geometry.getGridRange().getDimension();