Exemplo n.º 1
0
  @Override
  protected void processParameters(final OperationParams params)
      throws Exception { // Ensure we have all the required
    // arguments
    super.processParameters(params);

    final DataStore vectorStore;
    final PrimaryIndex[] vectorIndices;
    // Config file
    final File configFile = (File) params.getContext().get(ConfigOptions.PROPERTIES_FILE_CONTEXT);
    if ((vectorOverrideOptions.getVectorStore() != null)
        && !vectorOverrideOptions.getVectorStore().trim().isEmpty()) {
      String vectorStoreName = vectorOverrideOptions.getVectorStore();
      final StoreLoader vectorStoreLoader = new StoreLoader(vectorStoreName);
      if (!vectorStoreLoader.loadFromConfig(configFile)) {
        throw new ParameterException(
            "Cannot find vector store name: " + vectorStoreLoader.getStoreName());
      }
      final DataStorePluginOptions vectorStoreOptions = vectorStoreLoader.getDataStorePlugin();
      vectorStore = vectorStoreOptions.createDataStore();
    } else {
      vectorStore = store;
    }
    if ((vectorOverrideOptions.getVectorIndex() != null)
        && !vectorOverrideOptions.getVectorIndex().trim().isEmpty()) {
      String vectorIndexList = vectorOverrideOptions.getVectorIndex();

      // Load the Indices
      final IndexLoader indexLoader = new IndexLoader(vectorIndexList);
      if (!indexLoader.loadFromConfig(configFile)) {
        throw new ParameterException("Cannot find index(s) by name: " + vectorIndexList);
      }
      final List<IndexPluginOptions> indexOptions = indexLoader.getLoadedIndexes();

      vectorIndices = new PrimaryIndex[indexOptions.size()];
      int i = 0;
      for (final IndexPluginOptions dimensionType : indexOptions) {
        final PrimaryIndex primaryIndex = dimensionType.createPrimaryIndex();
        if (primaryIndex == null) {
          LOGGER.error("Could not get index instance, getIndex() returned null;");
          throw new IOException("Could not get index instance, getIndex() returned null");
        }
        vectorIndices[i++] = primaryIndex;
      }
    } else {
      vectorIndices = indices;
    }
    sceneType = SceneFeatureIterator.createFeatureType();
    final FeatureDataAdapter sceneAdapter = new FeatureDataAdapter(sceneType);
    sceneWriter = vectorStore.createWriter(sceneAdapter, vectorIndices);
    final SimpleFeatureType bandType = BandFeatureIterator.createFeatureType(sceneType);
    final FeatureDataAdapter bandAdapter = new FeatureDataAdapter(bandType);
    bandWriter = vectorStore.createWriter(bandAdapter, vectorIndices);
  }
Exemplo n.º 2
0
  private void queryNoDataMergeStrategy(final String coverageName, final int tileSize)
      throws AccumuloException, AccumuloSecurityException, IOException {
    final DataStore dataStore = dataStoreOptions.createDataStore();

    try (CloseableIterator<?> it =
        dataStore.query(
            new QueryOptions(new ByteArrayId(coverageName), null), new EverythingQuery())) {

      // 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 = 1; b < 7; b++) {
            Assert.assertEquals(
                "x=" + x + ",y=" + y + ",b=" + b,
                getValue(x, y, b, tileSize),
                raster.getSampleDouble(x, y, b));
          }
          if ((y % 2) == 0) {
            Assert.assertEquals(
                "x=" + x + ",y=" + y + ",b=0",
                getValue(x, y, 0, tileSize),
                raster.getSampleDouble(x, y, 0));
          } else {
            Assert.assertEquals(
                "x=" + x + ",y=" + y + ",b=0", Double.NaN, raster.getSampleDouble(x, y, 0));
          }
          if ((x > ((tileSize * 3) / 4)) && (y > ((tileSize * 3) / 4))) {
            Assert.assertEquals(
                "x=" + x + ",y=" + y + ",b=7", Double.NaN, raster.getSampleDouble(x, y, 7));
          } else {
            Assert.assertEquals(
                "x=" + x + ",y=" + y + ",b=7",
                getValue(x, y, 7, tileSize),
                raster.getSampleDouble(x, y, 7));
          }
        }
      }

      // there should be exactly one
      Assert.assertFalse(it.hasNext());
    }
  }
Exemplo n.º 3
0
  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 ExpectedValue expectedValue)
      throws AccumuloException, AccumuloSecurityException, IOException {
    final DataStore dataStore = dataStoreOptions.createDataStore();

    try (CloseableIterator<?> it =
        dataStore.query(
            new QueryOptions(new ByteArrayId(coverageName), null),
            new IndexOnlySpatialQuery(
                new GeometryFactory()
                    .toGeometry(new Envelope(westLon, eastLon, southLat, northLat))))) {
      // 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());
    }
  }
Exemplo n.º 4
0
  private void ingestGeneralPurpose(
      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 RasterTileMergeStrategy<?> mergeStrategy)
      throws IOException {

    // just ingest a number of rasters
    final DataStore dataStore = dataStoreOptions.createDataStore();
    final RasterDataAdapter basicAdapter =
        RasterUtils.createDataAdapterTypeDouble(
            coverageName, numBands, tileSize, new NoDataMergeStrategy());
    final RasterDataAdapter mergeStrategyOverriddenAdapter =
        new RasterDataAdapter(basicAdapter, coverageName, mergeStrategy);
    basicAdapter.getMetadata().put("test-key", "test-value");
    try (IndexWriter writer =
        dataStore.createWriter(mergeStrategyOverriddenAdapter, TestUtils.DEFAULT_SPATIAL_INDEX)) {
      for (int r = 0; r < numRasters; r++) {
        final WritableRaster raster = RasterUtils.createRasterTypeDouble(numBands, tileSize);
        for (int x = 0; x < tileSize; x++) {
          for (int y = 0; y < tileSize; y++) {
            for (int b = 0; b < numBands; b++) {
              raster.setSample(x, y, b, getValue(x, y, b, r, tileSize));
            }
          }
        }
        writer.write(
            RasterUtils.createCoverageTypeDouble(
                coverageName, westLon, eastLon, southLat, northLat, raster));
      }
    }
  }
  private static void executeBoundingBoxQuery() throws IOException {

    System.out.println(
        "Constructing bounding box for the area contained by [Baltimore, MD and Richmond, VA.");

    final Geometry boundingBox =
        GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(baltimore, richmond));

    System.out.println("Executing query, expecting to match ALL points...");

    try (final CloseableIterator<SimpleFeature> iterator =
        dataStore.query(new QueryOptions(index), new SpatialQuery(boundingBox))) {

      while (iterator.hasNext()) {
        System.out.println("Query match: " + iterator.next().getID());
      }
    }
  }
  private static void executePolygonQuery() throws IOException {

    System.out.println(
        "Constructing polygon for the area contained by [Baltimore, MD; Richmond, VA; Harrisonburg, VA].");

    final Polygon polygon =
        GeometryUtils.GEOMETRY_FACTORY.createPolygon(
            new Coordinate[] {baltimore, richmond, harrisonburg, baltimore});

    System.out.println("Executing query, expecting to match ALL points...");

    /**
     * NOTICE: In this query, the adapter is added to the query options. If an index has data from
     * more than one adapter, the data associated with a specific adapter can be selected.
     */
    try (final CloseableIterator<SimpleFeature> closableIterator =
        dataStore.query(new QueryOptions(ADAPTER, index), new SpatialQuery(polygon))) {

      while (closableIterator.hasNext()) {
        System.out.println("Query match: " + closableIterator.next().getID());
      }
    }
  }
  private static void ingestCannedData() throws IOException {

    final List<SimpleFeature> points = new ArrayList<>();

    System.out.println("Building SimpleFeatures from canned data set...");

    for (final Entry<String, Coordinate> entry : cannedData.entrySet()) {
      System.out.println("Added point: " + entry.getKey());
      points.add(buildSimpleFeature(entry.getKey(), entry.getValue()));
    }

    System.out.println("Ingesting canned data...");

    try (IndexWriter indexWriter =
        dataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      for (final SimpleFeature sf : points) {
        //
        indexWriter.write(ADAPTER, sf);
      }
    }

    System.out.println("Ingest complete.");
  }
Exemplo n.º 8
0
  @Override
  protected long runQuery(
      final GeotoolsFeatureDataAdapter adapter,
      final ByteArrayId adapterId,
      final ByteArrayId indexId,
      final DataStore dataStore,
      final boolean debug) {
    long count = 0;
    try (final CloseableIterator<Object> it =
        dataStore.query(new QueryOptions(adapterId, indexId), null)) {
      while (it.hasNext()) {
        if (debug) {
          System.out.println(it.next());
        } else {
          it.next();
        }
        count++;
      }

    } catch (final IOException e) {
      e.printStackTrace();
    }
    return count;
  }
Exemplo n.º 9
0
  private void ingestNoDataMergeStrategy(
      final String coverageName,
      final int tileSize,
      final double westLon,
      final double eastLon,
      final double southLat,
      final double northLat)
      throws IOException {
    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);
    // for raster1 do the following:
    // set every even row in bands 0 and 1
    // set every value incorrectly in band 2
    // set no values in band 3 and set every value in 4

    // for raster2 do the following:
    // set no value in band 0 and 4
    // set every odd row in band 1
    // set every value in bands 2 and 3

    // for band 5, set the lower 2x2 samples for raster 1 and the rest for
    // raster 2
    // for band 6, set the upper quadrant samples for raster 1 and the rest
    // for raster 2
    // for band 7, set the lower 2x2 samples to the wrong value for raster 1
    // and the expected value for raster 2 and set everything but the upper
    // quadrant for raster 2
    for (int x = 0; x < tileSize; x++) {
      for (int y = 0; y < tileSize; y++) {

        // just use x and y to arbitrarily end up with some wrong value
        // that can be ingested
        final double wrongValue = (getValue(y, x, y, tileSize) * 3) + 1;
        if ((x < 2) && (y < 2)) {
          raster1.setSample(x, y, 5, getValue(x, y, 5, tileSize));
          raster1.setSample(x, y, 7, wrongValue);
          raster2.setSample(x, y, 7, getValue(x, y, 7, tileSize));
        } else {
          raster2.setSample(x, y, 5, getValue(x, y, 5, tileSize));
        }
        if ((x > ((tileSize * 3) / 4)) && (y > ((tileSize * 3) / 4))) {
          raster1.setSample(x, y, 6, getValue(x, y, 6, tileSize));
        } else {
          raster2.setSample(x, y, 6, getValue(x, y, 6, tileSize));
          raster2.setSample(x, y, 7, getValue(x, y, 7, tileSize));
        }
        if ((y % 2) == 0) {
          raster1.setSample(x, y, 0, getValue(x, y, 0, tileSize));
          raster1.setSample(x, y, 1, getValue(x, y, 1, tileSize));
        }
        raster1.setSample(x, y, 2, wrongValue);

        raster1.setSample(x, y, 4, getValue(x, y, 4, tileSize));
        if ((y % 2) == 1) {
          raster2.setSample(x, y, 1, getValue(x, y, 1, tileSize));
        }
        raster2.setSample(x, y, 2, getValue(x, y, 2, tileSize));

        raster2.setSample(x, y, 3, getValue(x, y, 3, tileSize));
      }
    }

    try (IndexWriter writer = dataStore.createWriter(adapter, TestUtils.DEFAULT_SPATIAL_INDEX)) {
      writer.write(
          RasterUtils.createCoverageTypeDouble(
              coverageName, westLon, eastLon, southLat, northLat, raster1));
      writer.write(
          RasterUtils.createCoverageTypeDouble(
              coverageName, westLon, eastLon, southLat, northLat, raster2));
    }
  }