double[] valuesToIgnore,
GridCoverageReader layer,
Long sampleSize,
IProgressMonitor monitor) throws Exception{
this.errorMessage = null;
GridCoverage gcRaw = layer.read(null);
if (sampleSize != null){
int rSize = (int) Math.ceil(Math.sqrt(sampleSize.doubleValue()));
GridEnvelope2D gridRange = new GridEnvelope2D(new Rectangle(0,0, rSize, rSize));
GridGeometry2D world = new GridGeometry2D(gridRange, new ReferencedEnvelope(gcRaw.getEnvelope()));
DefaultParameterDescriptor<GridGeometry> gridGeometryDescriptor = new DefaultParameterDescriptor<GridGeometry>(
AbstractGridFormat.READ_GRIDGEOMETRY2D.getName()
.toString(), GridGeometry.class, null, world);
ParameterGroup readParams = new ParameterGroup(
new DefaultParameterDescriptorGroup(
"Test", //$NON-NLS-1$
new GeneralParameterDescriptor[] { gridGeometryDescriptor }));
List<GeneralParameterValue> list = readParams.values();
GeneralParameterValue[] values = list
.toArray(new GeneralParameterValue[0]);
gcRaw = layer.read(values);
}
if (monitor.isCanceled()){
return null;
}
GridCoordinates high = gcRaw.getGridGeometry().getGridRange().getHigh();
GridCoordinates low = gcRaw.getGridGeometry().getGridRange().getLow();
int width = high.getCoordinateValue(0) - low.getCoordinateValue(0);
int height = high.getCoordinateValue(1) - low.getCoordinateValue(1);
if (width * height > WARN_VALUE){
if (!warnLargeSize()){
return null;
}
}
int recSize = 1000;
HashSet<Double> ignoreset = new HashSet<Double>();
if (valuesToIgnore != null){
for (Double d : valuesToIgnore){
ignoreset.add(d);
}
}
List<Double> data = new ArrayList<Double>(width * height);
for (int x = 0; x < width; x+=recSize){
for (int y = 0; y < height; y += recSize){
int w = recSize;
int h = recSize;
if (x + recSize > width){
w = width - x;
}
if (y + recSize > height){
h = height - y;
}
Rectangle r = new Rectangle(x, y, w, h);
Raster rs = gcRaw.getRenderedImage().getData(r);
DataBuffer df = rs.getDataBuffer();
for (int i = 0; i < df.getSize(); i ++){
Double v = df.getElemDouble(i);
if (!ignoreset.contains(v)){
data.add(v);