//= check that raster size is the expected one
GeoTiffReader reader;
try {
reader = new GeoTiffReader(dataFile);
} catch (Exception e) {
throw new ActionException(this, "Error reading tiff file " + dataFile, e);
}
GridEnvelope ge = reader.getOriginalGridRange();
// GridCoverage2D gc2d = reader.read(null);
// GridGeometry2D gg2d = gc2d.getGridGeometry();
// GridEnvelope ge = gg2d.getGridRange();
try {
int expectedW = Float.valueOf(layer.getAttribute(Attributes.RASTERPIXELWIDTH)).intValue();
int expectedH = Float.valueOf(layer.getAttribute(Attributes.RASTERPIXELHEIGHT)).intValue();
int foundW = ge.getSpan(0);
int foundH = ge.getSpan(1);
if ( expectedW != foundW || expectedH != foundH ) {
throw new ActionException(this, "Bad raster size " + foundW + "x" + foundH + ", expected " + expectedW + "x" + expectedH);
}
//= check that extent is the expected one
// checkCoord(layer, Attributes.RASTERX0)
double expectedX0 = Double.valueOf(layer.getAttribute(Attributes.RASTERX0));
double expectedX1 = Double.valueOf(layer.getAttribute(Attributes.RASTERX1));
double expectedY0 = Double.valueOf(layer.getAttribute(Attributes.RASTERY0));
double expectedY1 = Double.valueOf(layer.getAttribute(Attributes.RASTERY1));
Envelope env = reader.getOriginalEnvelope();
// Envelope env = gc2d.getEnvelope();
double foundX0 = env.getMinimum(0);
double foundX1 = env.getMaximum(0);
double foundY0 = env.getMinimum(1);
double foundY1 = env.getMaximum(1);
if ( ! nearEnough(expectedX0, foundX0) || !nearEnough(expectedX1, foundX1) ||
! nearEnough(expectedY0, foundY0) || ! nearEnough(expectedY1, foundY1) ) {
throw new ActionException(this, "Bad raster extent X[" + foundX0 + "," + foundX1 + "] Y[" + foundY0 + "," + foundY1 + "]"
+ " expected X[" + expectedX0 + "," + expectedX1 + "] Y[" + expectedY0 + "," + expectedY1 + "]");
}
} catch (ActionException e) {
throw e;
} catch (Exception e) {
throw new ActionException(this,"Error while checking raster dimensions, Check if the Layer definition on GeoStore defines the attributes [RASTERX0, RASTERX1, RASTERY0, RASTERY1] and [RASTERPIXELWIDTH, RASTERPIXELHEIGHT]", e);
}
}