} else {
evaluateCoord = envelopeCenterOrig;
targetCrs = sourceCRS;
}
p = new Point2D.Double(evaluateCoord.x, evaluateCoord.y);
if (originalEnvelope.contains(new DirectPosition2D(p))) {
double delta = 0.0000001;
GeneralParameterValue[] parameterValues = createGridGeometryGeneralParameter(1, 1, evaluateCoord.y + delta,
evaluateCoord.y - delta, evaluateCoord.x + delta, evaluateCoord.x - delta, targetCrs);
coverage = reader.read(parameterValues);
/*
* the following is done since the reader might read a singlwe pixel
* region and the gridcoordinate would be 0, 0 in that case. Later
* we want to supply the gridcoordinate of the position in the whole
* coverage.
*/
gridGeometry = new GridGeometry2D(reader.getOriginalGridRange(), reader.getOriginalEnvelope());
isOnGrid = true;
}
}
// else try with coverage
else if (geoResource.canResolve(GridCoverage.class)) {
coverage = (GridCoverage2D) geoResource.resolve(GridCoverage.class, monitor);
CoordinateReferenceSystem targetCrs = coverage.getCoordinateReferenceSystem();
gridGeometry = coverage.getGridGeometry();
evaluateCoord = transform(sourceCRS, targetCrs, envelopeCenterOrig);
p = new Point2D.Double(evaluateCoord.x, evaluateCoord.y);
Envelope2D envelope2d = coverage.getEnvelope2D();
if (envelope2d.contains(p)) {
isOnGrid = true;
}
} else {
hasProblem = true;
}
final StringBuilder sb = new StringBuilder();
if (hasProblem) {
sb.append("The coverage information could not be read.");
} else if (isOnGrid) {
int bands = coverage.getSampleDimensions().length;
final double[] evaluated = new double[bands];
try {
coverage.evaluate(p, evaluated);
} catch (Exception e) {
e.printStackTrace();
}
final GridCoordinates2D gridCoord = gridGeometry.worldToGrid(new DirectPosition2D(p));
sb.append("Coverage info:\n\n");
int length = evaluated.length;
if (length > 1) {
for( int i = 0; i < evaluated.length; i++ ) {
sb.append("Band ").append(i);