Extractor { public void extract(ProgressMonitor pm) throws IOException, InterruptedException { Point[] tileIndices = maskImage.getTileIndices(null); LOG.info(String.format("Start extracting data from %d tiles for %d regions", tileIndices.length, regionFilters.size())); pm.beginTask("extraction", tileIndices.length * regionFilters.size()); for (Point maskTileIndex : tileIndices) { final Extractor.RasterStack rasterStack = getRasters(maskTileIndex); Rectangle tr = rasterStack.tileRect; LOG.info(String.format("Tile [x=%d,y=%d,width=%d,height=%d]", tr.x, tr.y, tr.width, tr.height)); for (GeometryFilter region : regionFilters) { Rectangle rect = rasterStack.tileRect.intersection(region.pixelRect); if (!rect.isEmpty()) { LOG.info(String.format(" Region '%s' [x=%d,y=%d,width=%d,height=%d]", region.name, rect.x, rect.y, rect.width, rect.height)); Extract extract = handleSingleTile(rasterStack, rect, region); if (extract != null) { LOG.info(String.format(" numObs %8d numSamples %8d", extract.numObs, extract.numValid)); extractedData(region.geoId, region.name, extract.time, extract.numObs, extract.samples); } } pm.worked(1); } } pm.done(); } Extractor(Product product, String validExpression, String[] bandNames, RARegions.RegionIterator regionIterator); abstract void extractedData(int regionIndex, String regionName, long time, int numObs, float[][] samples); void extract(ProgressMonitor pm);  }
@Test public void testExtract() throws Exception { Product product = new Product("t", "d", 360, 180); product.setPreferredTileSize(20, 10); product.addBand("x", "X"); product.addBand("l", "LAT"); product.addBand("c", "3.14"); GeoCoding geoCoding = new CrsGeoCoding(DefaultGeographicCRS.WGS84, 360, 180, -180.0, 90.0, 1, 1, 0.0, 0.0); product.setSceneGeoCoding(geoCoding); product.setStartTime(ProductData.UTC.parse("01-JAN-2011 10:20:30")); product.setEndTime(ProductData.UTC.parse("01-JAN-2011 12:20:30")); RAConfig config = new RAConfig(); RAConfig.BandConfig x = new RAConfig.BandConfig("x"); RAConfig.BandConfig l = new RAConfig.BandConfig("l"); RAConfig.BandConfig c = new RAConfig.BandConfig("c"); config.setBandConfigs(x, l, c); config.setGoodPixelExpression("LAT > 50"); config.setRegions(new RAConfig.Region("northsea", NORTH_SEA_WKT)); List<Result> results = new ArrayList<>(); RARegions.RegionIterator namedRegions = config.createNamedRegionIterator(null); Extractor extractor = new Extractor(product, config.getGoodPixelExpression(), config.getBandNames(), namedRegions) { @Override public void extractedData(int regionIndex, String regionName, long time, int numObs, float[][] samples) throws IOException, InterruptedException { results.add(new Result(regionIndex, regionName, time, numObs, samples)); } }; extractor.extract(ProgressMonitor.NULL); assertEquals(5, results.size()); testResultRecord(results.get(0), 65, 65); testResultRecord(results.get(1), 200, 200); testResultRecord(results.get(2), 108, 108); testResultRecord(results.get(3), 200, 0); testResultRecord(results.get(4), 1, 0); }