// Selection of the input file
final File inputFile = TestData.file(this, "sampleGrib.grb2");
// Get format
final AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(
inputFile.toURI().toURL(), null);
final NetCDFReader reader = new NetCDFReader(inputFile, null);
Assert.assertNotNull(format);
Assert.assertNotNull(reader);
try {
// Selection of all the Coverage names
String[] names = reader.getGridCoverageNames();
Assert.assertNotNull(names);
// Name of the first coverage
String coverageName = names[0];
// Parsing metadata values
assertEquals("true", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN"));
// Expanding the envelope
final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D
.createValue();
final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
final GeneralEnvelope newEnvelope = new GeneralEnvelope(originalEnvelope);
newEnvelope.setCoordinateReferenceSystem(reader
.getCoordinateReferenceSystem(coverageName));
newEnvelope.add(new DirectPosition2D(newEnvelope.getMinimum(0) - 10, newEnvelope
.getMinimum(1) - 10));
// Selecting the same gridRange
GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
gg.setValue(new GridGeometry2D(gridRange, newEnvelope));
GeneralParameterValue[] values = new GeneralParameterValue[] { gg };
// Read with the larger BBOX
GridCoverage2D grid = reader.read(coverageName, values);
// Check if the result is not null
assertNotNull(grid);
} finally {
if (reader != null) {
try {
reader.dispose();
} catch (Throwable t) {
// Does nothing
}
}
}