Search in sources :

Example 1 with RasterDataAdapter

use of org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter in project geowave by locationtech.

the class RasterTileResizeSparkRunner method run.

public void run() throws IOException {
    initContext();
    // Validate inputs
    if (inputStoreOptions == null) {
        LOGGER.error("You must supply an input datastore!");
        throw new IOException("You must supply an input datastore!");
    }
    final InternalAdapterStore internalAdapterStore = inputStoreOptions.createInternalAdapterStore();
    final short internalAdapterId = internalAdapterStore.getAdapterId(rasterResizeOptions.getInputCoverageName());
    final DataTypeAdapter adapter = inputStoreOptions.createAdapterStore().getAdapter(internalAdapterId).getAdapter();
    if (adapter == null) {
        throw new IllegalArgumentException("Adapter for coverage '" + rasterResizeOptions.getInputCoverageName() + "' does not exist in namespace '" + inputStoreOptions.getGeoWaveNamespace() + "'");
    }
    Index index = null;
    final IndexStore indexStore = inputStoreOptions.createIndexStore();
    if (rasterResizeOptions.getIndexName() != null) {
        index = indexStore.getIndex(rasterResizeOptions.getIndexName());
    }
    if (index == null) {
        try (CloseableIterator<Index> indices = indexStore.getIndices()) {
            index = indices.next();
        }
        if (index == null) {
            throw new IllegalArgumentException("Index does not exist in namespace '" + inputStoreOptions.getGeoWaveNamespace() + "'");
        }
    }
    final RasterDataAdapter newAdapter = new RasterDataAdapter((RasterDataAdapter) adapter, rasterResizeOptions.getOutputCoverageName(), rasterResizeOptions.getOutputTileSize());
    final DataStore store = outputStoreOptions.createDataStore();
    store.addType(newAdapter, index);
    final short newInternalAdapterId = outputStoreOptions.createInternalAdapterStore().addTypeName(newAdapter.getTypeName());
    final RDDOptions options = new RDDOptions();
    if (rasterResizeOptions.getMinSplits() != null) {
        options.setMinSplits(rasterResizeOptions.getMinSplits());
    }
    if (rasterResizeOptions.getMaxSplits() != null) {
        options.setMaxSplits(rasterResizeOptions.getMaxSplits());
    }
    final JavaPairRDD<GeoWaveInputKey, GridCoverage> inputRDD = GeoWaveRDDLoader.loadRawRasterRDD(jsc.sc(), inputStoreOptions, index.getName(), rasterResizeOptions.getMinSplits(), rasterResizeOptions.getMaxSplits());
    LOGGER.debug("Writing results to output store...");
    RDDUtils.writeRasterToGeoWave(jsc.sc(), index, outputStoreOptions, newAdapter, inputRDD.flatMapToPair(new RasterResizeMappingFunction(internalAdapterId, newInternalAdapterId, newAdapter, index)).groupByKey().map(new MergeRasterFunction(internalAdapterId, newInternalAdapterId, newAdapter, index)));
    LOGGER.debug("Results successfully written!");
}
Also used : InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) Index(org.locationtech.geowave.core.store.api.Index) IOException(java.io.IOException) GeoWaveInputKey(org.locationtech.geowave.mapreduce.input.GeoWaveInputKey) RDDOptions(org.locationtech.geowave.analytic.spark.RDDOptions) RasterDataAdapter(org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter) FitToIndexGridCoverage(org.locationtech.geowave.adapter.raster.FitToIndexGridCoverage) GridCoverage(org.opengis.coverage.grid.GridCoverage) DataStore(org.locationtech.geowave.core.store.api.DataStore) IndexStore(org.locationtech.geowave.core.store.index.IndexStore)

Example 2 with RasterDataAdapter

use of org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter in project geowave by locationtech.

the class KDERunner method run.

public void run() throws IOException {
    initContext();
    // Validate inputs
    if (inputDataStore == null) {
        LOGGER.error("You must supply an input datastore!");
        throw new IOException("You must supply an input datastore!");
    }
    // Retrieve the feature adapters
    final VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder();
    List<String> featureTypeNames;
    // If provided, just use the one
    if (typeName != null) {
        featureTypeNames = new ArrayList<>();
        featureTypeNames.add(typeName);
    } else {
        // otherwise, grab all the feature adapters
        featureTypeNames = FeatureDataUtils.getFeatureTypeNames(inputDataStore);
    }
    bldr.setTypeNames(featureTypeNames.toArray(new String[0]));
    if (indexName != null) {
        bldr.indexName(indexName);
    }
    Index inputPrimaryIndex = null;
    final Index[] idxArray = inputDataStore.createDataStore().getIndices();
    for (final Index idx : idxArray) {
        if ((idx != null) && ((indexName == null) || indexName.equals(idx.getName()))) {
            inputPrimaryIndex = idx;
            break;
        }
    }
    final CoordinateReferenceSystem inputIndexCrs = GeometryUtils.getIndexCrs(inputPrimaryIndex);
    final String inputCrsCode = GeometryUtils.getCrsCode(inputIndexCrs);
    Index outputPrimaryIndex = outputIndex;
    CoordinateReferenceSystem outputIndexCrs = null;
    final String outputCrsCode;
    if (outputPrimaryIndex != null) {
        outputIndexCrs = GeometryUtils.getIndexCrs(outputPrimaryIndex);
        outputCrsCode = GeometryUtils.getCrsCode(outputIndexCrs);
    } else {
        final SpatialDimensionalityTypeProvider sdp = new SpatialDimensionalityTypeProvider();
        final SpatialOptions so = sdp.createOptions();
        so.setCrs(inputCrsCode);
        outputPrimaryIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(so);
        outputIndexCrs = inputIndexCrs;
        outputCrsCode = inputCrsCode;
    }
    final CoordinateSystem cs = outputIndexCrs.getCoordinateSystem();
    final CoordinateSystemAxis csx = cs.getAxis(0);
    final CoordinateSystemAxis csy = cs.getAxis(1);
    final double xMax = csx.getMaximumValue();
    final double xMin = csx.getMinimumValue();
    final double yMax = csy.getMaximumValue();
    final double yMin = csy.getMinimumValue();
    if ((xMax == Double.POSITIVE_INFINITY) || (xMin == Double.NEGATIVE_INFINITY) || (yMax == Double.POSITIVE_INFINITY) || (yMin == Double.NEGATIVE_INFINITY)) {
        LOGGER.error("Raster KDE resize with raster primary index CRS dimensions min/max equal to positive infinity or negative infinity is not supported");
        throw new RuntimeException("Raster KDE resize with raster primary index CRS dimensions min/max equal to positive infinity or negative infinity is not supported");
    }
    if (cqlFilter != null) {
        bldr.constraints(bldr.constraintsFactory().cqlConstraints(cqlFilter));
    }
    // Load RDD from datastore
    final RDDOptions kdeOpts = new RDDOptions();
    kdeOpts.setMinSplits(minSplits);
    kdeOpts.setMaxSplits(maxSplits);
    kdeOpts.setQuery(bldr.build());
    final Function<Double, Double> identity = x -> x;
    final Function2<Double, Double, Double> sum = (final Double x, final Double y) -> {
        return x + y;
    };
    final RasterDataAdapter adapter = RasterUtils.createDataAdapterTypeDouble(coverageName, KDEReducer.NUM_BANDS, tileSize, MINS_PER_BAND, MAXES_PER_BAND, NAME_PER_BAND, new NoDataMergeStrategy());
    outputDataStore.createDataStore().addType(adapter, outputPrimaryIndex);
    // The following "inner" variables are created to give access to member
    // variables within lambda
    // expressions
    // tileSize;
    final int innerTileSize = 1;
    final String innerCoverageName = coverageName;
    for (int level = minLevel; level <= maxLevel; level++) {
        final int numXTiles = (int) Math.pow(2, level + 1);
        final int numYTiles = (int) Math.pow(2, level);
        // * tileSize;
        final int numXPosts = numXTiles;
        // * tileSize;
        final int numYPosts = numYTiles;
        final GeoWaveRDD kdeRDD = GeoWaveRDDLoader.loadRDD(session.sparkContext(), inputDataStore, kdeOpts);
        JavaPairRDD<Double, Long> cells = kdeRDD.getRawRDD().flatMapToPair(new GeoWaveCellMapper(numXPosts, numYPosts, xMin, xMax, yMin, yMax, inputCrsCode, outputCrsCode)).combineByKey(identity, sum, sum).mapToPair(item -> item.swap());
        cells = cells.partitionBy(new RangePartitioner(cells.getNumPartitions(), cells.rdd(), true, scala.math.Ordering.Double$.MODULE$, scala.reflect.ClassTag$.MODULE$.apply(Double.class))).sortByKey(false).cache();
        final long count = cells.count();
        if (count == 0) {
            LOGGER.warn("No cells produced by KDE");
            continue;
        }
        final double max = cells.first()._1;
        JavaRDD<GridCoverage> rdd = cells.zipWithIndex().map(t -> {
            final TileInfo tileInfo = fromCellIndexToTileInfo(t._1._2, numXPosts, numYPosts, numXTiles, numYTiles, xMin, xMax, yMin, yMax, innerTileSize);
            final WritableRaster raster = RasterUtils.createRasterTypeDouble(NUM_BANDS, innerTileSize);
            final double normalizedValue = t._1._1 / max;
            // because we are using a Double as the key, the ordering
            // isn't always completely reproducible as Double equals does not
            // take into account an epsilon
            final double percentile = (count - t._2) / ((double) count);
            raster.setSample(tileInfo.x, tileInfo.y, 0, t._1._1);
            raster.setSample(tileInfo.x, tileInfo.y, 1, normalizedValue);
            raster.setSample(tileInfo.x, tileInfo.y, 2, percentile);
            return RasterUtils.createCoverageTypeDouble(innerCoverageName, tileInfo.tileWestLon, tileInfo.tileEastLon, tileInfo.tileSouthLat, tileInfo.tileNorthLat, MINS_PER_BAND, MAXES_PER_BAND, NAME_PER_BAND, raster, GeometryUtils.DEFAULT_CRS_STR);
        });
        LOGGER.debug("Writing results to output store...");
        if (tileSize > 1) {
            // byte[] adapterBytes = PersistenceUtils.toBinary(adapter);
            // byte[] indexBytes = PersistenceUtils.toBinary(outputPrimaryIndex);
            rdd = rdd.flatMapToPair(new TransformTileSize(adapter, outputPrimaryIndex)).groupByKey().map(new MergeOverlappingTiles(adapter, outputPrimaryIndex));
        }
        RDDUtils.writeRasterToGeoWave(jsc.sc(), outputPrimaryIndex, outputDataStore, adapter, rdd);
        LOGGER.debug("Results successfully written!");
    }
}
Also used : FactoryException(org.opengis.referencing.FactoryException) Arrays(java.util.Arrays) CRS(org.geotools.referencing.CRS) Function2(org.apache.spark.api.java.function.Function2) GeoWaveRDD(org.locationtech.geowave.analytic.spark.GeoWaveRDD) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) PairFlatMapFunction(org.apache.spark.api.java.function.PairFlatMapFunction) PersistenceUtils(org.locationtech.geowave.core.index.persist.PersistenceUtils) URISyntaxException(java.net.URISyntaxException) GaussianFilter(org.locationtech.geowave.analytic.mapreduce.kde.GaussianFilter) ObjectInputStream(java.io.ObjectInputStream) LoggerFactory(org.slf4j.LoggerFactory) FitToIndexGridCoverage(org.locationtech.geowave.adapter.raster.FitToIndexGridCoverage) SimpleFeature(org.opengis.feature.simple.SimpleFeature) KDEReducer(org.locationtech.geowave.analytic.mapreduce.kde.KDEReducer) JTS(org.geotools.geometry.jts.JTS) TransformException(org.opengis.referencing.operation.TransformException) GeoWaveSparkConf(org.locationtech.geowave.analytic.spark.GeoWaveSparkConf) NoDataMergeStrategy(org.locationtech.geowave.adapter.raster.adapter.merge.nodata.NoDataMergeStrategy) Point(org.locationtech.jts.geom.Point) HadoopWritableSerializer(org.locationtech.geowave.mapreduce.HadoopWritableSerializer) GeometryUtils(org.locationtech.geowave.core.geotime.util.GeometryUtils) Tuple2(scala.Tuple2) Serializable(java.io.Serializable) List(java.util.List) Geometry(org.locationtech.jts.geom.Geometry) Function(org.apache.spark.api.java.function.Function) FilenameUtils(org.apache.commons.io.FilenameUtils) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) GridCoverageWritable(org.locationtech.geowave.adapter.raster.adapter.GridCoverageWritable) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) RasterDataAdapter(org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter) GeoWaveInputKey(org.locationtech.geowave.mapreduce.input.GeoWaveInputKey) VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) FeatureDataUtils(org.locationtech.geowave.adapter.vector.util.FeatureDataUtils) SpatialDimensionalityTypeProvider(org.locationtech.geowave.core.geotime.index.SpatialDimensionalityTypeProvider) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) GeoWaveRDDLoader(org.locationtech.geowave.analytic.spark.GeoWaveRDDLoader) ObjectOutputStream(java.io.ObjectOutputStream) RasterUtils(org.locationtech.geowave.adapter.raster.RasterUtils) Index(org.locationtech.geowave.core.store.api.Index) JavaRDD(org.apache.spark.api.java.JavaRDD) SparkSession(org.apache.spark.sql.SparkSession) RDDUtils(org.locationtech.geowave.analytic.spark.RDDUtils) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) GridCoverage(org.opengis.coverage.grid.GridCoverage) RangePartitioner(org.apache.spark.RangePartitioner) IOException(java.io.IOException) JavaPairRDD(org.apache.spark.api.java.JavaPairRDD) RDDOptions(org.locationtech.geowave.analytic.spark.RDDOptions) CellCounter(org.locationtech.geowave.analytic.mapreduce.kde.CellCounter) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) DataStorePluginOptions(org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions) MathTransform(org.opengis.referencing.operation.MathTransform) ClientMergeableRasterTile(org.locationtech.geowave.adapter.raster.adapter.ClientMergeableRasterTile) WritableRaster(java.awt.image.WritableRaster) VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) Index(org.locationtech.geowave.core.store.api.Index) SpatialDimensionalityTypeProvider(org.locationtech.geowave.core.geotime.index.SpatialDimensionalityTypeProvider) WritableRaster(java.awt.image.WritableRaster) RangePartitioner(org.apache.spark.RangePartitioner) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) IOException(java.io.IOException) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) RDDOptions(org.locationtech.geowave.analytic.spark.RDDOptions) Point(org.locationtech.jts.geom.Point) RasterDataAdapter(org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter) NoDataMergeStrategy(org.locationtech.geowave.adapter.raster.adapter.merge.nodata.NoDataMergeStrategy) FitToIndexGridCoverage(org.locationtech.geowave.adapter.raster.FitToIndexGridCoverage) GridCoverage(org.opengis.coverage.grid.GridCoverage) GeoWaveRDD(org.locationtech.geowave.analytic.spark.GeoWaveRDD)

Example 3 with RasterDataAdapter

use of org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter in project geowave by locationtech.

the class RasterIngestRunner method processPreviousScene.

@SuppressWarnings({ "rawtypes", "unchecked" })
protected void processPreviousScene() {
    if (!ingestOptions.isCoveragePerBand()) {
        // ingest as single image for all bands
        if (!lastSceneBands.isEmpty()) {
            // we are sorting by band name to ensure a consistent order for
            // bands
            final TreeMap<String, RasterBandData> sceneData = new TreeMap<>();
            Writer writer;
            // get coverage info, ensuring that all coverage names are the
            // same
            String coverageName = null;
            for (final SimpleFeature band : lastSceneBands) {
                RasterBandData bandData;
                try {
                    bandData = getBandData(band);
                    if (coverageName == null) {
                        coverageName = bandData.name;
                    } else if (!coverageName.equals(bandData.name)) {
                        LOGGER.warn("Unable to use band data as the band coverage name '" + bandData.name + "' is unexpectedly different from default name '" + coverageName + "'");
                    }
                    final String bandName = band.getAttribute(BandFeatureIterator.BAND_ATTRIBUTE_NAME).toString();
                    sceneData.put(bandName, bandData);
                } catch (IOException | TemplateException e) {
                    LOGGER.warn("Unable to read band data", e);
                }
            }
            if (coverageName == null) {
                LOGGER.warn("No valid bands found for scene");
                lastSceneBands.clear();
                return;
            }
            final GridCoverage2D mergedCoverage;
            if (sceneData.size() == 1) {
                mergedCoverage = sceneData.firstEntry().getValue().coverage;
            } else {
                final CoverageProcessor processor = CoverageProcessor.getInstance();
                final AbstractOperation op = (AbstractOperation) processor.getOperation("BandMerge");
                final ParameterValueGroup params = op.getParameters();
                final List<GridCoverage2D> sources = new ArrayList<>();
                for (final RasterBandData bandData : sceneData.values()) {
                    sources.add(bandData.coverage);
                }
                params.parameter("Sources").setValue(sources);
                params.parameter(BandMerge.TRANSFORM_CHOICE).setValue(TransformList.FIRST.toString());
                mergedCoverage = (GridCoverage2D) op.doOperation(params, null);
            }
            final String[] thisSceneBands = sceneData.keySet().toArray(new String[] {});
            if (bandsIngested == null) {
                // this means this is the first scene
                // setup adapter and other required info
                final Map<String, String> metadata = new HashMap<>();
                final double[][] noDataValues = new double[sceneData.size()][];
                int b = 0;
                // merge metadata from all readers
                for (final RasterBandData bandData : sceneData.values()) {
                    try {
                        final String[] metadataNames = bandData.reader.getMetadataNames();
                        if ((metadataNames != null) && (metadataNames.length > 0)) {
                            for (final String metadataName : metadataNames) {
                                metadata.put(metadataName, bandData.reader.getMetadataValue(metadataName));
                            }
                        }
                    } catch (final Exception e) {
                        LOGGER.warn("Unable to get metadata for coverage '" + coverageName + "'.", e);
                    }
                    noDataValues[b++] = new double[] { bandData.nodataValue };
                }
                final RasterDataAdapter adapter = new RasterDataAdapter(coverageName, metadata, mergedCoverage, ingestOptions.getTileSize(), ingestOptions.isCreatePyramid(), ingestOptions.isCreateHistogram(), noDataValues, new NoDataMergeStrategy());
                store.addType(adapter, indices);
                writer = store.createWriter(adapter.getTypeName());
                writerCache.put(coverageName, writer);
                bandsIngested = thisSceneBands;
            } else if (!Arrays.equals(bandsIngested, thisSceneBands)) {
                LOGGER.warn("The bands in this scene ('" + Arrays.toString(thisSceneBands) + "') differ from the previous scene ('" + Arrays.toString(bandsIngested) + "').  To merge bands all scenes must use the same bands.  Skipping scene'" + lastSceneBands.get(0).getAttribute(SceneFeatureIterator.ENTITY_ID_ATTRIBUTE_NAME) + "'.");
                lastSceneBands.clear();
                return;
            } else {
                writer = writerCache.get(coverageName);
                if (writer == null) {
                    LOGGER.warn("Unable to find writer for coverage '" + coverageName + "'.  Skipping scene'" + lastSceneBands.get(0).getAttribute(SceneFeatureIterator.ENTITY_ID_ATTRIBUTE_NAME) + "'.");
                    lastSceneBands.clear();
                    return;
                }
            }
            writer.write(mergedCoverage);
            lastSceneBands.clear();
        }
    }
}
Also used : GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) TemplateException(freemarker.template.TemplateException) CoverageProcessor(org.geotools.coverage.processing.CoverageProcessor) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TreeMap(java.util.TreeMap) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FactoryException(org.opengis.referencing.FactoryException) ParameterException(com.beust.jcommander.ParameterException) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException) TransformException(org.opengis.referencing.operation.TransformException) InvalidParameterValueException(org.opengis.parameter.InvalidParameterValueException) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) RasterDataAdapter(org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter) NoDataMergeStrategy(org.locationtech.geowave.adapter.raster.adapter.merge.nodata.NoDataMergeStrategy) AbstractOperation(org.geotools.coverage.processing.AbstractOperation) Writer(org.locationtech.geowave.core.store.api.Writer)

Example 4 with RasterDataAdapter

use of org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter 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());
    }
}
Also used : RasterDataAdapter(org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter) NoDataMergeStrategy(org.locationtech.geowave.adapter.raster.adapter.merge.nodata.NoDataMergeStrategy) GridCoverage(org.opengis.coverage.grid.GridCoverage) WritableRaster(java.awt.image.WritableRaster) DataStore(org.locationtech.geowave.core.store.api.DataStore) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) Point(org.locationtech.jts.geom.Point) Writer(org.locationtech.geowave.core.store.api.Writer)

Example 5 with RasterDataAdapter

use of org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter 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());
    }
}
Also used : RasterDataAdapter(org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter) NoDataMergeStrategy(org.locationtech.geowave.adapter.raster.adapter.merge.nodata.NoDataMergeStrategy) GridCoverage(org.opengis.coverage.grid.GridCoverage) WritableRaster(java.awt.image.WritableRaster) DataStore(org.locationtech.geowave.core.store.api.DataStore) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) Point(org.locationtech.jts.geom.Point) Writer(org.locationtech.geowave.core.store.api.Writer)

Aggregations

RasterDataAdapter (org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter)22 NoDataMergeStrategy (org.locationtech.geowave.adapter.raster.adapter.merge.nodata.NoDataMergeStrategy)12 IOException (java.io.IOException)10 DataStore (org.locationtech.geowave.core.store.api.DataStore)10 Writer (org.locationtech.geowave.core.store.api.Writer)10 GridCoverage (org.opengis.coverage.grid.GridCoverage)9 WritableRaster (java.awt.image.WritableRaster)8 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)6 Index (org.locationtech.geowave.core.store.api.Index)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 TemplateException (freemarker.template.TemplateException)4 Raster (java.awt.image.Raster)3 FitToIndexGridCoverage (org.locationtech.geowave.adapter.raster.FitToIndexGridCoverage)3 GeoWaveInputKey (org.locationtech.geowave.mapreduce.input.GeoWaveInputKey)3 Point (org.locationtech.jts.geom.Point)3 SimpleFeature (org.opengis.feature.simple.SimpleFeature)3 ParameterException (com.beust.jcommander.ParameterException)2 TreeMap (java.util.TreeMap)2 AbstractOperation (org.geotools.coverage.processing.AbstractOperation)2