if (gridSource == null)
throw new IOException("");
// create a request
// reading the coverage
CoverageResponse response = gridSource.read(
new DefaultCoverageReadRequest(), null);
if (response == null
|| response.getStatus() != Status.SUCCESS
|| !response.getExceptions().isEmpty())
throw new IOException("");
Collection<? extends Coverage> results = response
.getResults(null);
for (Coverage c : results) {
GridCoverage2D coverage = (GridCoverage2D) c;
// Crs and envelope
if (TestData.isInteractiveTest()) {
buffer.append("CRS: ").append(
coverage.getCoordinateReferenceSystem2D()
.toWKT()).append("\n");
buffer.append("GG: ").append(
coverage.getGridGeometry().toString())
.append("\n");
}
// create an update request
final DefaultCoverageUpdateRequest request = new DefaultCoverageUpdateRequest();
request.setData(Collections.singletonList(coverage));
// create access
final File writeFile = new File(writedir, coverage
.getName().toString()
+ ".tiff");
final GeoTiffAccess storeAccess =
(GeoTiffAccess) factory.process(
DriverOperation.CREATE,
writeFile.toURI().toURL(),
null,
null,
null);
final CoverageStore gridStore = (CoverageStore) storeAccess
.create(name, null, null, null);
// write it down
gridStore.update(request, null);
// getting access to the file
access = factory.process(DriverOperation.CONNECT,writeFile.toURI().toURL(),null, null, null);
if (access == null)
throw new IOException("");
//get the names
names = access.getNames(null);
gridSource = access.access(names.iterator().next(),
null, AccessType.READ_ONLY, null, null);
if (gridSource == null)
throw new IOException("");
//create a request
// reading the coverage
response = gridSource.read(
new DefaultCoverageReadRequest(), null);
if (response == null
|| response.getStatus() != Status.SUCCESS
|| !response.getExceptions().isEmpty())
throw new IOException("");