AggregatingPixExMeasurementFactory extends AbstractMeasurementFactory { @Override public Measurement[] createMeasurements(int pixelX, int pixelY, int coordinateID, String coordinateName, Product product, Raster validData) throws IOException { final long productId = productRegistry.getProductId(product); final int numPixels = windowSize * windowSize; final Measurement[] measurements = new Measurement[1]; final String[] rasterNames = rasterNamesFactory.getUniqueRasterNames(product); final Float[][] values = new Float[rasterNames.length][numPixels]; for (int i = 0; i < rasterNames.length; i++) { String rasterName = rasterNames[i]; Float[] bandValues = new Float[numPixels]; final Band band = product.getBand(rasterName); setBandValues(product, band, bandValues, windowSize, pixelX, pixelY, validData); values[i] = bandValues; } Record record = new DefaultRecord(values); final Number[] numbers = new Number[rasterNames.length * aggregatorStrategy.getValueCount()]; for (int i = 0; i < rasterNames.length; i++) { Number[] valuesForBand = aggregatorStrategy.getValues(record, i); for (int j = 0; j < aggregatorStrategy.getValueCount(); j++) { Number v = valuesForBand[j]; numbers[i * aggregatorStrategy.getValueCount() + j] = v; } } measurements[0] = createMeasurement(product, productId, coordinateID, coordinateName, numbers, true, pixelX, pixelY); return measurements; } AggregatingPixExMeasurementFactory(final RasterNamesFactory rasterNamesFactory,
                                              final int windowSize, final ProductRegistry productRegistry,
                                              AggregatorStrategy aggregatorStrategy); @Override Measurement[] createMeasurements(int pixelX, int pixelY, int coordinateID, String coordinateName,
                                            Product product, Raster validData); @Override void close();  }
@Test public void testCreateMeasurementsWithMeanMeasurementAggregator() throws Exception { final AggregatorStrategy aggregatorStrategy = new MeanAggregatorStrategy(); final MeasurementFactory factory = new AggregatingPixExMeasurementFactory(rasterNamesFactory, windowSize, productRegistry, aggregatorStrategy); final int pixelX = 1; final int pixelY = 1; final int coordinateID = 2345; final String coordsName = "coordsName"; final Measurement[] measurements = factory.createMeasurements(pixelX, pixelY, coordinateID, coordsName, product, null); assertEquals(1, measurements.length); final Measurement expectedMeasurement = new Measurement(coordinateID, coordsName, 1234L, 1.5F, 1.5F, null, new GeoPos(), new Number[]{ 17.0F, 3.5707142F, 9, 25.5F, 3.5707142F, 9 }, true); assertEquals(expectedMeasurement, measurements[0]); }
@Test public void testCreateMeasurementsWithMinMeasurementAggregator() throws Exception { final AggregatorStrategy aggregatorStrategy = new MinAggregatorStrategy(); final MeasurementFactory factory = new AggregatingPixExMeasurementFactory(rasterNamesFactory, windowSize, productRegistry, aggregatorStrategy); final int pixelX = 1; final int pixelY = 1; final int coordinateID = 2345; final String coordsName = "coordsName"; final Measurement[] measurements = factory.createMeasurements(pixelX, pixelY, coordinateID, coordsName, product, null); assertEquals(1, measurements.length); Measurement expectedMeasurement = createExpectedMeasurement(pixelX, pixelY, coordinateID, coordsName, 12f, 9, 20.5f, 9); assertEquals(expectedMeasurement, measurements[0]); }
@Test public void testCreateMeasurementsWithMaxMeasurementAggregator() throws Exception { final AggregatorStrategy aggregatorStrategy = new MaxAggregatorStrategy(); final MeasurementFactory factory = new AggregatingPixExMeasurementFactory(rasterNamesFactory, windowSize, productRegistry, aggregatorStrategy); final int pixelX = 1; final int pixelY = 1; final int coordinateID = 2345; final String coordsName = "coordsName"; final Measurement[] measurements = factory.createMeasurements(pixelX, pixelY, coordinateID, coordsName, product, null); assertEquals(1, measurements.length); Measurement expectedMeasurement = createExpectedMeasurement(pixelX, pixelY, coordinateID, coordsName, 22f, 9, 30.5f, 9); assertEquals(expectedMeasurement, measurements[0]); }
@Test public void testCreateMeasurementsWithMedianMeasurementAggregator() throws Exception { final AggregatorStrategy aggregatorStrategy = new MedianAggregatorStrategy(); final MeasurementFactory factory = new AggregatingPixExMeasurementFactory(rasterNamesFactory, windowSize, productRegistry, aggregatorStrategy); final int pixelX = 1; final int pixelY = 1; final int coordinateID = 2345; final String coordsName = "coordsName"; final Measurement[] measurements = factory.createMeasurements(pixelX, pixelY, coordinateID, coordsName, product, null); assertEquals(1, measurements.length); Measurement expectedMeasurement = createExpectedMeasurement(pixelX, pixelY, coordinateID, coordsName, 17f, 9, 25.5f, 9); assertEquals(expectedMeasurement, measurements[0]); }
@Test public void testMeanWithFillValues_float() throws Exception { final AggregatorStrategy aggregatorStrategy = new MeanAggregatorStrategy(); final MeasurementFactory factory = new AggregatingPixExMeasurementFactory(rasterNamesFactory, 5, productRegistry, aggregatorStrategy); Product fillValueContainingProduct = new Product("p0", "t0", 5, 5); Band band = fillValueContainingProduct.addBand("b0", ProductData.TYPE_FLOAT32); band.setNoDataValue(-1.0); band.setData(new ProductData.Float(new float[]{ 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, -1.0F, -1.0F, -1.0F, -1.0F, -1.0F })); final int pixelX = 2; final int pixelY = 2; final int coordinateID = 2345; final String coordsName = "coordsName"; final Measurement[] measurements = factory.createMeasurements(pixelX, pixelY, coordinateID, coordsName, fillValueContainingProduct, null); assertEquals(1, measurements.length); Number[] expectedValues = { 1.0F, 0.0F, 20 }; final Measurement expectedMeasurement = new Measurement(coordinateID, coordsName, 1234L, 2.5F, 2.5F, null, new GeoPos(), expectedValues, true); assertEquals(expectedMeasurement, measurements[0]); }
@Test public void testMeanWithFillValues_int() throws Exception { final AggregatorStrategy aggregatorStrategy = new MeanAggregatorStrategy(); final MeasurementFactory factory = new AggregatingPixExMeasurementFactory(rasterNamesFactory, 5, productRegistry, aggregatorStrategy); Product fillValueContainingProduct = new Product("p0", "t0", 5, 5); Band band = fillValueContainingProduct.addBand("b0", ProductData.TYPE_INT16); band.setNoDataValue(16); band.setData(new ProductData.Short(new short[]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 16, 16, 16, 16 })); final int pixelX = 2; final int pixelY = 2; final int coordinateID = 2345; final String coordsName = "coordsName"; final Measurement[] measurements = factory.createMeasurements(pixelX, pixelY, coordinateID, coordsName, fillValueContainingProduct, null); assertEquals(1, measurements.length); Number[] expectedValues = { 1.0F, 0.0F, 20 }; final Measurement expectedMeasurement = new Measurement(coordinateID, coordsName, 1234L, 2.5F, 2.5F, null, new GeoPos(), expectedValues, true); assertEquals(expectedMeasurement, measurements[0]); }
@Test public void testMeanWithFillValues_uint32() throws Exception { final AggregatorStrategy aggregatorStrategy = new MeanAggregatorStrategy(); final MeasurementFactory factory = new AggregatingPixExMeasurementFactory(rasterNamesFactory, 5, productRegistry, aggregatorStrategy); Product fillValueContainingProduct = new Product("p0", "t0", 5, 5); Band band = fillValueContainingProduct.addBand("b0", ProductData.TYPE_UINT32); band.setNoDataValue(16); band.setData(new ProductData.UInt(new int[]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 16, 16, 16, 16 })); final int pixelX = 2; final int pixelY = 2; final int coordinateID = 2345; final String coordsName = "coordsName"; final Measurement[] measurements = factory.createMeasurements(pixelX, pixelY, coordinateID, coordsName, fillValueContainingProduct, null); assertEquals(1, measurements.length); Number[] expectedValues = { 1.0F, 0.0F, 20 }; final Measurement expectedMeasurement = new Measurement(coordinateID, coordsName, 1234L, 2.5F, 2.5F, null, new GeoPos(), expectedValues, true); assertEquals(expectedMeasurement, measurements[0]); }