* @throws IOException
* @throws IllegalArgumentException
*/
public Set<Double> computeUniqueValues(GridCoverageReader layer, Long sampleSize, IProgressMonitor monitor) throws IllegalArgumentException, IOException{
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;
boolean maxReached = false;
HashSet<Double> results = new HashSet<Double>();
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 ++){
results.add(df.getElemDouble(i));
if (results.size() >= SingleBandEditorPage.MAX_ENTRIES){
errorMessage = MessageFormat.format(Messages.UniqueValuesDialog_MaxValueError, SingleBandEditorPage.MAX_ENTRIES);