Hi Agossa, It might be easiest for you to get the backing image from grid coverage and use JAI methods for the masking and calculation. In JAI parlance, masking is referred to as defining a "region of interest", ROI, which may be a shape or pixel-based (e.g. ROI based on coverage cells with a particular value). http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/ROI.html http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/ROIShape.html
Then you can either use a JAI iterator to count value occurrences within the ROI... http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/iterator/RectIterFactory.html ...or the JAI histogram operation to count occurrences of all values within the ROI. Both can deal with multiple bands. An example using an iterator and an ROI based on a second grid coverage. It assumes that the two coverages have the same bounds... RenderedImage dataImg = cov1.getRenderedImage(); RenderedImage maskImg = cov2.getRenderedImage(); // create an ROI based on all pixels in maskImg with value // >= threshold ROI roi = new ROI(maskImg, threshold); RectIter iter = RectIterFactory.create(dataImg, null); int numBands = dataImg.getSampleModel().getNumBands(); int[] values = new int[numBands]; int[] count = new int[numBands]; for (int i = 0; i < numBands; i++) count[i] = 0; int y = roi.getBounds().y; do { iter.startPixels(); int x = roi.getBounds().x; do { if (roi.contains(x, y)) { iter.getPixel(values); for (int i = 0; i < numBands; i++) { if (values[i] == searchValue) { count[i]++; } } } x++ ; } while (!iter.nextPixelDone()); y++ ; } while (!iter.nextLineDone()); Michael ------------------------------------------------------------------------------ This SF.net email is sponsored by: SourcForge Community SourceForge wants to tell your story. http://p.sf.net/sfu/sf-spreadtheword _______________________________________________ Geotools-gt2-users mailing list Geotools-gt2-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users