use of org.opengis.coverage.grid.GridCoverage in project geowave by locationtech.
the class GeoWaveVisibilityIT method ingestAndQueryComplexVisibilityRasters.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void ingestAndQueryComplexVisibilityRasters(final String coverageName, final int tileSize, final double westLon, final double eastLon, final double southLat, final double northLat) throws IOException {
// Create two test rasters
final int numBands = 8;
final DataStore dataStore = dataStoreOptions.createDataStore();
final RasterDataAdapter adapter = RasterUtils.createDataAdapterTypeDouble(coverageName, numBands, tileSize, new NoDataMergeStrategy());
final WritableRaster raster1 = RasterUtils.createRasterTypeDouble(numBands, tileSize);
final WritableRaster raster2 = RasterUtils.createRasterTypeDouble(numBands, tileSize);
TestUtils.fillTestRasters(raster1, raster2, tileSize);
dataStore.addType(adapter, TestUtils.DEFAULT_SPATIAL_INDEX);
try (Writer writer = dataStore.createWriter(adapter.getTypeName())) {
// Write the first raster w/ vis info
writer.write(RasterUtils.createCoverageTypeDouble(coverageName, westLon, eastLon, southLat, northLat, raster1), getRasterVisWriter("(a&b)|c"));
// Write the second raster w/ no vis info
writer.write(RasterUtils.createCoverageTypeDouble(coverageName, westLon, eastLon, southLat, northLat, raster2));
}
try (CloseableIterator<?> it = dataStore.query(QueryBuilder.newBuilder().addTypeName(coverageName).build())) {
final GridCoverage coverage = (GridCoverage) it.next();
final Raster raster = coverage.getRenderedImage().getData();
Assert.assertEquals(tileSize, raster.getWidth());
Assert.assertEquals(tileSize, raster.getHeight());
for (int x = 0; x < tileSize; x++) {
for (int y = 0; y < tileSize; y++) {
for (int b = 0; b < numBands; b++) {
final double p0 = raster.getSampleDouble(x, y, b);
final double p1 = raster2.getSampleDouble(x, y, b);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=" + b, p0, p1, 0.0);
}
}
}
// there should be exactly one
Assert.assertFalse(it.hasNext());
}
// just the second raster back
try (CloseableIterator<?> it = dataStore.query(QueryBuilder.newBuilder().addTypeName(coverageName).addAuthorization("a").build())) {
final GridCoverage coverage = (GridCoverage) it.next();
final Raster raster = coverage.getRenderedImage().getData();
Assert.assertEquals(tileSize, raster.getWidth());
Assert.assertEquals(tileSize, raster.getHeight());
for (int x = 0; x < tileSize; x++) {
for (int y = 0; y < tileSize; y++) {
for (int b = 0; b < numBands; b++) {
final double p0 = raster.getSampleDouble(x, y, b);
final double p1 = raster2.getSampleDouble(x, y, b);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=" + b, p0, p1, 0.0);
}
}
}
// there should be exactly one
Assert.assertFalse(it.hasNext());
}
// just the second raster back
try (CloseableIterator<?> it = dataStore.query(QueryBuilder.newBuilder().addTypeName(coverageName).addAuthorization("b").build())) {
final GridCoverage coverage = (GridCoverage) it.next();
final Raster raster = coverage.getRenderedImage().getData();
Assert.assertEquals(tileSize, raster.getWidth());
Assert.assertEquals(tileSize, raster.getHeight());
for (int x = 0; x < tileSize; x++) {
for (int y = 0; y < tileSize; y++) {
for (int b = 0; b < numBands; b++) {
final double p0 = raster.getSampleDouble(x, y, b);
final double p1 = raster2.getSampleDouble(x, y, b);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=" + b, p0, p1, 0.0);
}
}
}
// there should be exactly one
Assert.assertFalse(it.hasNext());
}
try (CloseableIterator<?> it = dataStore.query(QueryBuilder.newBuilder().addTypeName(coverageName).addAuthorization("c").build())) {
final GridCoverage coverage = (GridCoverage) it.next();
final Raster raster = coverage.getRenderedImage().getData();
Assert.assertEquals(tileSize, raster.getWidth());
Assert.assertEquals(tileSize, raster.getHeight());
// 7 has the upper quadrant as NaN and the rest set
for (int x = 0; x < tileSize; x++) {
for (int y = 0; y < tileSize; y++) {
for (int b = 1; b < 7; b++) {
final double pExp = TestUtils.getTileValue(x, y, b, tileSize);
final double pAct = raster.getSampleDouble(x, y, b);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=" + b, pExp, pAct, 0.0);
}
if ((y % 2) == 0) {
final double pExp = TestUtils.getTileValue(x, y, 0, tileSize);
final double pAct = raster.getSampleDouble(x, y, 0);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=0", pExp, pAct, 0.0);
} else {
final double pAct = raster.getSampleDouble(x, y, 0);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=0", Double.NaN, pAct, 0.0);
}
if ((x > ((tileSize * 3) / 4)) && (y > ((tileSize * 3) / 4))) {
final double pAct = raster.getSampleDouble(x, y, 7);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=7", Double.NaN, pAct, 0.0);
} else {
final double pExp = TestUtils.getTileValue(x, y, 7, tileSize);
final double pAct = raster.getSampleDouble(x, y, 7);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=7", pExp, pAct, 0.0);
}
}
}
// there should be exactly one
Assert.assertFalse(it.hasNext());
}
try (CloseableIterator<?> it = dataStore.query(QueryBuilder.newBuilder().addTypeName(coverageName).addAuthorization("a").addAuthorization("b").build())) {
final GridCoverage coverage = (GridCoverage) it.next();
final Raster raster = coverage.getRenderedImage().getData();
Assert.assertEquals(tileSize, raster.getWidth());
Assert.assertEquals(tileSize, raster.getHeight());
// 7 has the upper quadrant as NaN and the rest set
for (int x = 0; x < tileSize; x++) {
for (int y = 0; y < tileSize; y++) {
for (int b = 1; b < 7; b++) {
final double pExp = TestUtils.getTileValue(x, y, b, tileSize);
final double pAct = raster.getSampleDouble(x, y, b);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=" + b, pExp, pAct, 0.0);
}
if ((y % 2) == 0) {
final double pExp = TestUtils.getTileValue(x, y, 0, tileSize);
final double pAct = raster.getSampleDouble(x, y, 0);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=0", pExp, pAct, 0.0);
} else {
final double pAct = raster.getSampleDouble(x, y, 0);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=0", Double.NaN, pAct, 0.0);
}
if ((x > ((tileSize * 3) / 4)) && (y > ((tileSize * 3) / 4))) {
final double pAct = raster.getSampleDouble(x, y, 7);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=7", Double.NaN, pAct, 0.0);
} else {
final double pExp = TestUtils.getTileValue(x, y, 7, tileSize);
final double pAct = raster.getSampleDouble(x, y, 7);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=7", pExp, pAct, 0.0);
}
}
}
// there should be exactly one
Assert.assertFalse(it.hasNext());
}
}
use of org.opengis.coverage.grid.GridCoverage in project geowave by locationtech.
the class GeoWaveVisibilityIT method ingestAndQueryMixedVisibilityRasters.
private void ingestAndQueryMixedVisibilityRasters(final String coverageName, final int tileSize, final double westLon, final double eastLon, final double southLat, final double northLat) throws IOException {
// Create two test rasters
final int numBands = 8;
final DataStore dataStore = dataStoreOptions.createDataStore();
final RasterDataAdapter adapter = RasterUtils.createDataAdapterTypeDouble(coverageName, numBands, tileSize, new NoDataMergeStrategy());
final WritableRaster raster1 = RasterUtils.createRasterTypeDouble(numBands, tileSize);
final WritableRaster raster2 = RasterUtils.createRasterTypeDouble(numBands, tileSize);
TestUtils.fillTestRasters(raster1, raster2, tileSize);
dataStore.addType(adapter, TestUtils.DEFAULT_SPATIAL_INDEX);
try (Writer writer = dataStore.createWriter(adapter.getTypeName())) {
// Write the first raster w/ vis info
writer.write(RasterUtils.createCoverageTypeDouble(coverageName, westLon, eastLon, southLat, northLat, raster1), getRasterVisWriter("a"));
// Write the second raster w/ no vis info
writer.write(RasterUtils.createCoverageTypeDouble(coverageName, westLon, eastLon, southLat, northLat, raster2));
}
try (CloseableIterator<?> it = dataStore.query(QueryBuilder.newBuilder().addTypeName(coverageName).build())) {
final GridCoverage coverage = (GridCoverage) it.next();
final Raster raster = coverage.getRenderedImage().getData();
Assert.assertEquals(tileSize, raster.getWidth());
Assert.assertEquals(tileSize, raster.getHeight());
for (int x = 0; x < tileSize; x++) {
for (int y = 0; y < tileSize; y++) {
for (int b = 0; b < numBands; b++) {
final double p0 = raster.getSampleDouble(x, y, b);
final double p1 = raster2.getSampleDouble(x, y, b);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=" + b, p0, p1, 0.0);
}
}
}
// there should be exactly one
Assert.assertFalse(it.hasNext());
}
try (CloseableIterator<?> it = dataStore.query(QueryBuilder.newBuilder().addTypeName(coverageName).addAuthorization("a").build())) {
final GridCoverage coverage = (GridCoverage) it.next();
final Raster raster = coverage.getRenderedImage().getData();
Assert.assertEquals(tileSize, raster.getWidth());
Assert.assertEquals(tileSize, raster.getHeight());
// 7 has the upper quadrant as NaN and the rest set
for (int x = 0; x < tileSize; x++) {
for (int y = 0; y < tileSize; y++) {
for (int b = 1; b < 7; b++) {
final double pExp = TestUtils.getTileValue(x, y, b, tileSize);
final double pAct = raster.getSampleDouble(x, y, b);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=" + b, pExp, pAct, 0.0);
}
if ((y % 2) == 0) {
final double pExp = TestUtils.getTileValue(x, y, 0, tileSize);
final double pAct = raster.getSampleDouble(x, y, 0);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=0", pExp, pAct, 0.0);
} else {
final double pAct = raster.getSampleDouble(x, y, 0);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=0", Double.NaN, pAct, 0.0);
}
if ((x > ((tileSize * 3) / 4)) && (y > ((tileSize * 3) / 4))) {
final double pAct = raster.getSampleDouble(x, y, 7);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=7", Double.NaN, pAct, 0.0);
} else {
final double pExp = TestUtils.getTileValue(x, y, 7, tileSize);
final double pAct = raster.getSampleDouble(x, y, 7);
Assert.assertEquals("x=" + x + ",y=" + y + ",b=7", pExp, pAct, 0.0);
}
}
}
// there should be exactly one
Assert.assertFalse(it.hasNext());
}
}
use of org.opengis.coverage.grid.GridCoverage in project geowave by locationtech.
the class CustomCRSKDERasterResizeIT method testSamplesMatch.
private double[][][] testSamplesMatch(final String coverageNamePrefix, final int numCoverages, final GeneralEnvelope queryEnvelope, final Rectangle pixelDimensions, double[][][] expectedResults) throws Exception {
final StringBuilder str = new StringBuilder(StoreFactoryOptions.GEOWAVE_NAMESPACE_OPTION).append("=").append(TEST_COVERAGE_NAMESPACE).append(";equalizeHistogramOverride=false;scaleTo8Bit=false;interpolationOverride=").append(Interpolation.INTERP_NEAREST);
str.append(";").append(GeoWaveStoreFinder.STORE_HINT_KEY).append("=").append(outputDataStorePluginOptions.getType());
final Map<String, String> options = outputDataStorePluginOptions.getOptionsAsMap();
for (final Entry<String, String> entry : options.entrySet()) {
if (!entry.getKey().equals(StoreFactoryOptions.GEOWAVE_NAMESPACE_OPTION)) {
str.append(";").append(entry.getKey()).append("=").append(entry.getValue());
}
}
final GeoWaveRasterReader reader = new GeoWaveRasterReader(GeoWaveRasterConfig.readFromConfigParams(str.toString()));
queryEnvelope.setCoordinateReferenceSystem(CRS.decode("EPSG:4166", true));
final Raster[] rasters = new Raster[numCoverages];
int coverageCount = 0;
for (int i = MIN_TILE_SIZE_POWER_OF_2; i <= MAX_TILE_SIZE_POWER_OF_2; i += INCREMENT) {
final String tileSizeCoverageName = coverageNamePrefix + i;
final GridCoverage gridCoverage = reader.renderGridCoverage(tileSizeCoverageName, pixelDimensions, queryEnvelope, Color.BLACK, null, null);
final RenderedImage image = gridCoverage.getRenderedImage();
final Raster raster = image.getData();
rasters[coverageCount++] = raster;
}
boolean atLeastOneResult = expectedResults != null;
for (int i = 0; i < numCoverages; i++) {
final boolean initialResults = expectedResults == null;
if (initialResults) {
expectedResults = new double[rasters[i].getWidth()][rasters[i].getHeight()][rasters[i].getNumBands()];
} else {
Assert.assertEquals("The expected width does not match the expected width for the coverage " + i, expectedResults.length, rasters[i].getWidth());
Assert.assertEquals("The expected height does not match the expected height for the coverage " + i, expectedResults[0].length, rasters[i].getHeight());
Assert.assertEquals("The expected number of bands does not match the expected bands for the coverage " + i, expectedResults[0][0].length, rasters[i].getNumBands());
}
long mismatchedSamples = 0;
for (int y = 0; y < rasters[i].getHeight(); y++) {
for (int x = 0; x < rasters[i].getWidth(); x++) {
for (int b = 0; b < rasters[i].getNumBands(); b++) {
final double sample = rasters[i].getSampleDouble(x, y, b);
if (initialResults) {
expectedResults[x][y][b] = sample;
if (!atLeastOneResult && (sample != 0)) {
atLeastOneResult = true;
}
} else {
if ((Double.isNaN(sample) && !Double.isNaN(expectedResults[x][y][b])) || (!Double.isNaN(sample) && Double.isNaN(expectedResults[x][y][b])) || (Math.abs(expectedResults[x][y][b] - sample) > TestUtils.DOUBLE_EPSILON)) {
mismatchedSamples++;
}
}
}
}
}
final double percentMismatch = mismatchedSamples / (double) (rasters[i].getWidth() * rasters[i].getHeight() * rasters[i].getNumBands());
Assert.assertTrue((percentMismatch * 100) + "% mismatch is less than 1%", percentMismatch < 0.01);
}
Assert.assertTrue("There should be at least one value that is not black", atLeastOneResult);
return expectedResults;
}
use of org.opengis.coverage.grid.GridCoverage in project geowave by locationtech.
the class GeoWaveBasicCustomCRSRasterIT method queryGeneralPurpose.
private void queryGeneralPurpose(final String coverageName, final int tileSize, final double westLon, final double eastLon, final double southLat, final double northLat, final int numBands, final int numRasters, final GeoWaveBasicRasterIT.ExpectedValue expectedValue) throws IOException {
final DataStore dataStore = dataStoreOptions.createDataStore();
try (CloseableIterator<?> it = dataStore.query(QueryBuilder.newBuilder().addTypeName(coverageName).constraints(new IndexOnlySpatialQuery(new GeometryFactory().toGeometry(new Envelope(westLon, eastLon, southLat, northLat)), TestUtils.CUSTOM_CRSCODE)).build())) {
// the expected outcome is:
// band 1,2,3,4,5,6 has every value set correctly, band 0 has every
// even row set correctly and every odd row should be NaN, and band
// 7 has the upper quadrant as NaN and the rest set
final GridCoverage coverage = (GridCoverage) it.next();
final Raster raster = coverage.getRenderedImage().getData();
Assert.assertEquals(tileSize, raster.getWidth());
Assert.assertEquals(tileSize, raster.getHeight());
for (int x = 0; x < tileSize; x++) {
for (int y = 0; y < tileSize; y++) {
for (int b = 0; b < numBands; b++) {
Assert.assertEquals("x=" + x + ",y=" + y + ",b=" + b, expectedValue.getExpectedValue(x, y, b, numRasters, tileSize), raster.getSampleDouble(x, y, b), DOUBLE_TOLERANCE);
}
}
}
// there should be exactly one
Assert.assertFalse(it.hasNext());
}
}
use of org.opengis.coverage.grid.GridCoverage in project geowave by locationtech.
the class GeoWaveBasicRasterIT method queryNoDataMergeStrategy.
private void queryNoDataMergeStrategy(final String coverageName, final int tileSize) throws IOException {
final DataStore dataStore = dataStoreOptions.createDataStore();
try (CloseableIterator<?> it = dataStore.query(QueryBuilder.newBuilder().addTypeName(coverageName).build())) {
// the expected outcome is:
// band 1,2,3,4,5,6 has every value set correctly, band 0 has every
// even row set correctly and every odd row should be NaN, and band
// 7 has the upper quadrant as NaN and the rest set
final GridCoverage coverage = (GridCoverage) it.next();
final Raster raster = coverage.getRenderedImage().getData();
Assert.assertEquals(tileSize, raster.getWidth(), DELTA);
Assert.assertEquals(tileSize, raster.getHeight(), DELTA);
for (int x = 0; x < tileSize; x++) {
for (int y = 0; y < tileSize; y++) {
for (int b = 1; b < 7; b++) {
Assert.assertEquals("x=" + x + ",y=" + y + ",b=" + b, TestUtils.getTileValue(x, y, b, tileSize), raster.getSampleDouble(x, y, b), DELTA);
}
if ((y % 2) == 0) {
Assert.assertEquals("x=" + x + ",y=" + y + ",b=0", TestUtils.getTileValue(x, y, 0, tileSize), raster.getSampleDouble(x, y, 0), DELTA);
} else {
Assert.assertEquals("x=" + x + ",y=" + y + ",b=0", Double.NaN, raster.getSampleDouble(x, y, 0), DELTA);
}
if ((x > ((tileSize * 3) / 4)) && (y > ((tileSize * 3) / 4))) {
Assert.assertEquals("x=" + x + ",y=" + y + ",b=7", Double.NaN, raster.getSampleDouble(x, y, 7), DELTA);
} else {
Assert.assertEquals("x=" + x + ",y=" + y + ",b=7", TestUtils.getTileValue(x, y, 7, tileSize), raster.getSampleDouble(x, y, 7), DELTA);
}
}
}
// there should be exactly one
Assert.assertFalse(it.hasNext());
}
}
Aggregations