Search in sources :

Example 1 with StoreFactoryOptions

use of org.locationtech.geowave.core.store.StoreFactoryOptions in project geowave by locationtech.

the class StoreTestEnvironment method getDataStoreOptions.

public DataStorePluginOptions getDataStoreOptions(final GeoWaveTestStore store, final String[] profileOptions) {
    final DataStorePluginOptions pluginOptions = new TestDataStoreOptions(getStoreType());
    final GenericStoreFactory<DataStore> factory = getDataStoreFactory();
    StoreFactoryOptions opts = factory.createOptionsInstance();
    initOptions(opts);
    opts.setGeoWaveNamespace(store.namespace());
    final Map<String, String> optionOverrides = new HashMap<>();
    // now allow for overrides to take precedence
    for (final String optionOverride : store.options()) {
        if (optionOverride.contains("=")) {
            final String[] kv = optionOverride.split("=");
            optionOverrides.put(kv[0], kv[1]);
        }
    }
    // and finally, apply maven profile options
    if (profileOptions != null) {
        for (final String optionOverride : profileOptions) {
            if (optionOverride.contains("=")) {
                final String[] kv = optionOverride.split("=");
                optionOverrides.put(kv[0], kv[1]);
            }
        }
    }
    if (!optionOverrides.isEmpty()) {
        opts = ConfigUtils.populateOptionsFromList(opts, optionOverrides);
    }
    pluginOptions.selectPlugin(factory.getType());
    pluginOptions.setFactoryOptions(opts);
    return pluginOptions;
}
Also used : DataStorePluginOptions(org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions) HashMap(java.util.HashMap) DataStore(org.locationtech.geowave.core.store.api.DataStore) StoreFactoryOptions(org.locationtech.geowave.core.store.StoreFactoryOptions)

Example 2 with StoreFactoryOptions

use of org.locationtech.geowave.core.store.StoreFactoryOptions in project geowave by locationtech.

the class NestedGroupCentroidAssignmentTest method test.

@Test
public void test() throws IOException {
    final SimpleFeatureType ftype = AnalyticFeature.createGeometryFeatureAdapter("centroid", new String[] { "extra1" }, BasicFeatureTypes.DEFAULT_NAMESPACE, ClusteringUtils.CLUSTERING_CRS).getFeatureType();
    final GeometryFactory factory = new GeometryFactory();
    final String grp1 = "g1";
    final String grp2 = "g2";
    final SimpleFeature level1b1G1Feature = AnalyticFeature.createGeometryFeature(ftype, "b1", "level1b1G1Feature", "fred", grp1, 20.30203, factory.createPoint(new Coordinate(02.5, 0.25)), new String[] { "extra1" }, new double[] { 0.022 }, 1, 1, 0);
    final Index index = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
    final FeatureDataAdapter adapter = new FeatureDataAdapter(ftype);
    final String namespace = "test_" + getClass().getName() + "_" + name.getMethodName();
    final StoreFactoryFamilySpi storeFamily = new MemoryStoreFactoryFamily();
    final StoreFactoryOptions opts = storeFamily.getDataStoreFactory().createOptionsInstance();
    opts.setGeoWaveNamespace(namespace);
    final DataStorePluginOptions storePluginOptions = new DataStorePluginOptions(opts);
    final DataStore dataStore = storeFamily.getDataStoreFactory().createStore(opts);
    final IndexStore indexStore = storeFamily.getIndexStoreFactory().createStore(opts);
    final PersistentAdapterStore adapterStore = storeFamily.getAdapterStoreFactory().createStore(opts);
    ingest(dataStore, adapter, index, level1b1G1Feature);
    final SimpleFeature level1b1G2Feature = AnalyticFeature.createGeometryFeature(ftype, "b1", "level1b1G2Feature", "flood", grp2, 20.30203, factory.createPoint(new Coordinate(02.03, 0.2)), new String[] { "extra1" }, new double[] { 0.022 }, 1, 1, 0);
    ingest(dataStore, adapter, index, level1b1G2Feature);
    final SimpleFeature level2b1G1Feature = AnalyticFeature.createGeometryFeature(ftype, "b1", "level2b1G1Feature", "flou", level1b1G1Feature.getID(), 20.30203, factory.createPoint(new Coordinate(02.5, 0.25)), new String[] { "extra1" }, new double[] { 0.022 }, 2, 1, 0);
    ingest(dataStore, adapter, index, level2b1G1Feature);
    final SimpleFeature level2b1G2Feature = AnalyticFeature.createGeometryFeature(ftype, "b1", "level2b1G2Feature", "flapper", level1b1G2Feature.getID(), 20.30203, factory.createPoint(new Coordinate(02.03, 0.2)), new String[] { "extra1" }, new double[] { 0.022 }, 2, 1, 0);
    ingest(dataStore, adapter, index, level2b1G2Feature);
    // different batch
    final SimpleFeature level2B2G1Feature = AnalyticFeature.createGeometryFeature(ftype, "b2", "level2B2G1Feature", "flapper", level1b1G1Feature.getID(), 20.30203, factory.createPoint(new Coordinate(02.63, 0.25)), new String[] { "extra1" }, new double[] { 0.022 }, 2, 1, 0);
    ingest(dataStore, adapter, index, level2B2G1Feature);
    final SimpleFeatureItemWrapperFactory wrapperFactory = new SimpleFeatureItemWrapperFactory();
    final CentroidManagerGeoWave<SimpleFeature> mananger = new CentroidManagerGeoWave<>(dataStore, indexStore, adapterStore, new SimpleFeatureItemWrapperFactory(), adapter.getTypeName(), storePluginOptions.createInternalAdapterStore().getAdapterId(adapter.getTypeName()), index.getName(), "b1", 1);
    final List<CentroidPairing<SimpleFeature>> capturedPairing = new ArrayList<>();
    final AssociationNotification<SimpleFeature> assoc = new AssociationNotification<SimpleFeature>() {

        @Override
        public void notify(final CentroidPairing<SimpleFeature> pairing) {
            capturedPairing.add(pairing);
        }
    };
    final FeatureCentroidDistanceFn distanceFn = new FeatureCentroidDistanceFn();
    final NestedGroupCentroidAssignment<SimpleFeature> assigmentB1 = new NestedGroupCentroidAssignment<>(mananger, 1, "b1", distanceFn);
    assigmentB1.findCentroidForLevel(wrapperFactory.create(level1b1G1Feature), assoc);
    assertEquals(1, capturedPairing.size());
    assertEquals(level1b1G1Feature.getID(), capturedPairing.get(0).getCentroid().getID());
    capturedPairing.clear();
    final NestedGroupCentroidAssignment<SimpleFeature> assigmentB1L2G1 = new NestedGroupCentroidAssignment<>(mananger, 2, "b1", distanceFn);
    assigmentB1L2G1.findCentroidForLevel(wrapperFactory.create(level1b1G1Feature), assoc);
    assertEquals(1, capturedPairing.size());
    assertEquals(level2b1G1Feature.getID(), capturedPairing.get(0).getCentroid().getID());
    capturedPairing.clear();
    // level 2 and different parent grouping
    final NestedGroupCentroidAssignment<SimpleFeature> assigmentB1L2G2 = new NestedGroupCentroidAssignment<>(mananger, 2, "b1", distanceFn);
    assigmentB1L2G2.findCentroidForLevel(wrapperFactory.create(level1b1G2Feature), assoc);
    assertEquals(1, capturedPairing.size());
    assertEquals(level2b1G2Feature.getID(), capturedPairing.get(0).getCentroid().getID());
    capturedPairing.clear();
    // level two with different batch than parent
    final CentroidManagerGeoWave<SimpleFeature> mananger2 = new CentroidManagerGeoWave<>(dataStore, indexStore, adapterStore, new SimpleFeatureItemWrapperFactory(), adapter.getTypeName(), storePluginOptions.createInternalAdapterStore().getAdapterId(adapter.getTypeName()), index.getName(), "b2", 2);
    final NestedGroupCentroidAssignment<SimpleFeature> assigmentB2L2 = new NestedGroupCentroidAssignment<>(mananger2, 2, "b1", distanceFn);
    assigmentB2L2.findCentroidForLevel(wrapperFactory.create(level1b1G1Feature), assoc);
    assertEquals(1, capturedPairing.size());
    assertEquals(level2B2G1Feature.getID(), capturedPairing.get(0).getCentroid().getID());
    capturedPairing.clear();
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) SimpleFeatureItemWrapperFactory(org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory) ArrayList(java.util.ArrayList) Index(org.locationtech.geowave.core.store.api.Index) MemoryStoreFactoryFamily(org.locationtech.geowave.core.store.memory.MemoryStoreFactoryFamily) DataStorePluginOptions(org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions) DataStore(org.locationtech.geowave.core.store.api.DataStore) AssociationNotification(org.locationtech.geowave.analytic.kmeans.AssociationNotification) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) SimpleFeature(org.opengis.feature.simple.SimpleFeature) StoreFactoryFamilySpi(org.locationtech.geowave.core.store.StoreFactoryFamilySpi) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) StoreFactoryOptions(org.locationtech.geowave.core.store.StoreFactoryOptions) FeatureCentroidDistanceFn(org.locationtech.geowave.analytic.distance.FeatureCentroidDistanceFn) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) Test(org.junit.Test)

Example 3 with StoreFactoryOptions

use of org.locationtech.geowave.core.store.StoreFactoryOptions in project geowave by locationtech.

the class CentroidManagerTest method testSampleRecall.

@Test
public void testSampleRecall() throws IOException {
    final SimpleFeatureType ftype = AnalyticFeature.createGeometryFeatureAdapter("centroid", new String[] { "extra1" }, BasicFeatureTypes.DEFAULT_NAMESPACE, ClusteringUtils.CLUSTERING_CRS).getFeatureType();
    final GeometryFactory factory = new GeometryFactory();
    final String grp1 = "g1";
    final String grp2 = "g2";
    SimpleFeature feature = AnalyticFeature.createGeometryFeature(ftype, "b1", "123", "fred", grp1, 20.30203, factory.createPoint(new Coordinate(02.33, 0.23)), new String[] { "extra1" }, new double[] { 0.022 }, 1, 1, 0);
    final Index index = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
    final FeatureDataAdapter adapter = new FeatureDataAdapter(ftype);
    final String namespace = "test_" + getClass().getName() + "_" + name.getMethodName();
    final StoreFactoryFamilySpi storeFamily = new MemoryStoreFactoryFamily();
    final StoreFactoryOptions opts = storeFamily.getDataStoreFactory().createOptionsInstance();
    opts.setGeoWaveNamespace(namespace);
    final DataStore dataStore = storeFamily.getDataStoreFactory().createStore(opts);
    final IndexStore indexStore = storeFamily.getIndexStoreFactory().createStore(opts);
    final PersistentAdapterStore adapterStore = storeFamily.getAdapterStoreFactory().createStore(opts);
    final InternalAdapterStore internalAdapterStore = storeFamily.getInternalAdapterStoreFactory().createStore(opts);
    ingest(dataStore, adapter, index, feature);
    feature = AnalyticFeature.createGeometryFeature(ftype, "b1", "231", "flood", grp1, 20.30203, factory.createPoint(new Coordinate(02.33, 0.23)), new String[] { "extra1" }, new double[] { 0.022 }, 1, 1, 0);
    ingest(dataStore, adapter, index, feature);
    feature = AnalyticFeature.createGeometryFeature(ftype, "b1", "321", "flou", grp2, 20.30203, factory.createPoint(new Coordinate(02.33, 0.23)), new String[] { "extra1" }, new double[] { 0.022 }, 1, 1, 0);
    ingest(dataStore, adapter, index, feature);
    feature = AnalyticFeature.createGeometryFeature(ftype, "b2", "312", "flapper", grp2, 20.30203, factory.createPoint(new Coordinate(02.33, 0.23)), new String[] { "extra1" }, new double[] { 0.022 }, 1, 1, 0);
    ingest(dataStore, adapter, index, feature);
    // and one feature with a different zoom level
    feature = AnalyticFeature.createGeometryFeature(ftype, "b2", "312", "flapper", grp2, 20.30203, factory.createPoint(new Coordinate(02.33, 0.23)), new String[] { "extra1" }, new double[] { 0.022 }, 2, 1, 0);
    ingest(dataStore, adapter, index, feature);
    CentroidManagerGeoWave<SimpleFeature> manager = new CentroidManagerGeoWave<>(dataStore, indexStore, adapterStore, new SimpleFeatureItemWrapperFactory(), adapter.getTypeName(), internalAdapterStore.getAdapterId(adapter.getTypeName()), index.getName(), "b1", 1);
    List<AnalyticItemWrapper<SimpleFeature>> centroids = manager.getCentroidsForGroup(null);
    assertEquals(3, centroids.size());
    feature = centroids.get(0).getWrappedItem();
    assertEquals(0.022, (Double) feature.getAttribute("extra1"), 0.001);
    centroids = manager.getCentroidsForGroup(grp1);
    assertEquals(2, centroids.size());
    centroids = manager.getCentroidsForGroup(grp2);
    assertEquals(1, centroids.size());
    feature = centroids.get(0).getWrappedItem();
    assertEquals(0.022, (Double) feature.getAttribute("extra1"), 0.001);
    manager = new CentroidManagerGeoWave<>(dataStore, indexStore, adapterStore, new SimpleFeatureItemWrapperFactory(), adapter.getTypeName(), internalAdapterStore.getAdapterId(adapter.getTypeName()), index.getName(), "b1", 1);
    manager.processForAllGroups(new CentroidProcessingFn<SimpleFeature>() {

        @Override
        public int processGroup(final String groupID, final List<AnalyticItemWrapper<SimpleFeature>> centroids) {
            if (groupID.equals(grp1)) {
                assertEquals(2, centroids.size());
            } else if (groupID.equals(grp2)) {
                assertEquals(1, centroids.size());
            } else {
                assertTrue("what group is this : " + groupID, false);
            }
            return 0;
        }
    });
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) SimpleFeatureItemWrapperFactory(org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory) Index(org.locationtech.geowave.core.store.api.Index) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) SimpleFeature(org.opengis.feature.simple.SimpleFeature) StoreFactoryFamilySpi(org.locationtech.geowave.core.store.StoreFactoryFamilySpi) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) MemoryStoreFactoryFamily(org.locationtech.geowave.core.store.memory.MemoryStoreFactoryFamily) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) StoreFactoryOptions(org.locationtech.geowave.core.store.StoreFactoryOptions) DataStore(org.locationtech.geowave.core.store.api.DataStore) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) AnalyticItemWrapper(org.locationtech.geowave.analytic.AnalyticItemWrapper) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) Test(org.junit.Test)

Example 4 with StoreFactoryOptions

use of org.locationtech.geowave.core.store.StoreFactoryOptions in project geowave by locationtech.

the class KDEJobRunner method runJob.

/**
 * Main method to execute the MapReduce analytic.
 */
@SuppressWarnings("deprecation")
public int runJob() throws Exception {
    Configuration conf = super.getConf();
    if (conf == null) {
        conf = new Configuration();
        setConf(conf);
    }
    Index inputPrimaryIndex = null;
    final Index[] idxArray = inputDataStoreOptions.createDataStore().getIndices();
    for (final Index idx : idxArray) {
        if ((idx != null) && ((kdeCommandLineOptions.getIndexName() == null) || kdeCommandLineOptions.getIndexName().equals(idx.getName()))) {
            inputPrimaryIndex = idx;
            break;
        }
    }
    final CoordinateReferenceSystem inputIndexCrs = GeometryUtils.getIndexCrs(inputPrimaryIndex);
    final String inputCrsCode = GeometryUtils.getCrsCode(inputIndexCrs);
    Index outputPrimaryIndex = outputIndex;
    CoordinateReferenceSystem outputIndexCrs = null;
    String outputCrsCode = null;
    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");
    }
    DataStorePluginOptions rasterResizeOutputDataStoreOptions;
    String kdeCoverageName;
    // the KDE output and then run a resize operation
    if ((kdeCommandLineOptions.getTileSize() > 1)) {
        // this is the ending data store options after resize, the KDE will
        // need to output to a temporary namespace, a resize operation
        // will use the outputDataStoreOptions
        rasterResizeOutputDataStoreOptions = outputDataStoreOptions;
        // first clone the outputDataStoreOptions, then set it to a tmp
        // namespace
        final Map<String, String> configOptions = outputDataStoreOptions.getOptionsAsMap();
        final StoreFactoryOptions options = ConfigUtils.populateOptionsFromList(outputDataStoreOptions.getFactoryFamily().getDataStoreFactory().createOptionsInstance(), configOptions);
        options.setGeoWaveNamespace(outputDataStoreOptions.getGeoWaveNamespace() + "_tmp");
        outputDataStoreOptions = new DataStorePluginOptions(options);
        kdeCoverageName = kdeCommandLineOptions.getCoverageName() + TMP_COVERAGE_SUFFIX;
    } else {
        rasterResizeOutputDataStoreOptions = null;
        kdeCoverageName = kdeCommandLineOptions.getCoverageName();
    }
    if (kdeCommandLineOptions.getHdfsHostPort() == null) {
        final Properties configProperties = ConfigOptions.loadProperties(configFile);
        final String hdfsFSUrl = ConfigHDFSCommand.getHdfsUrl(configProperties);
        kdeCommandLineOptions.setHdfsHostPort(hdfsFSUrl);
    }
    GeoWaveConfiguratorBase.setRemoteInvocationParams(kdeCommandLineOptions.getHdfsHostPort(), kdeCommandLineOptions.getJobTrackerOrResourceManHostPort(), conf);
    conf.setInt(MAX_LEVEL_KEY, kdeCommandLineOptions.getMaxLevel());
    conf.setInt(MIN_LEVEL_KEY, kdeCommandLineOptions.getMinLevel());
    conf.set(COVERAGE_NAME_KEY, kdeCoverageName);
    if (kdeCommandLineOptions.getCqlFilter() != null) {
        conf.set(GaussianCellMapper.CQL_FILTER_KEY, kdeCommandLineOptions.getCqlFilter());
    }
    conf.setDouble(X_MIN_KEY, xMin);
    conf.setDouble(X_MAX_KEY, xMax);
    conf.setDouble(Y_MIN_KEY, yMin);
    conf.setDouble(Y_MAX_KEY, yMax);
    conf.set(INPUT_CRSCODE_KEY, inputCrsCode);
    conf.set(OUTPUT_CRSCODE_KEY, outputCrsCode);
    preJob1Setup(conf);
    final Job job = new Job(conf);
    job.setJarByClass(this.getClass());
    addJobClasspathDependencies(job, conf);
    job.setJobName(getJob1Name());
    job.setMapperClass(getJob1Mapper());
    job.setCombinerClass(CellSummationCombiner.class);
    job.setReducerClass(getJob1Reducer());
    job.setMapOutputKeyClass(LongWritable.class);
    job.setMapOutputValueClass(DoubleWritable.class);
    job.setOutputKeyClass(DoubleWritable.class);
    job.setOutputValueClass(LongWritable.class);
    job.setInputFormatClass(GeoWaveInputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);
    job.setNumReduceTasks(8);
    job.setSpeculativeExecution(false);
    final PersistentAdapterStore adapterStore = inputDataStoreOptions.createAdapterStore();
    final IndexStore indexStore = inputDataStoreOptions.createIndexStore();
    final InternalAdapterStore internalAdapterStore = inputDataStoreOptions.createInternalAdapterStore();
    final short internalAdapterId = internalAdapterStore.getAdapterId(kdeCommandLineOptions.getFeatureType());
    final DataTypeAdapter<?> adapter = adapterStore.getAdapter(internalAdapterId).getAdapter();
    VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder().addTypeName(adapter.getTypeName());
    if (kdeCommandLineOptions.getIndexName() != null) {
        bldr = bldr.indexName(kdeCommandLineOptions.getIndexName());
    }
    GeoWaveInputFormat.setMinimumSplitCount(job.getConfiguration(), kdeCommandLineOptions.getMinSplits());
    GeoWaveInputFormat.setMaximumSplitCount(job.getConfiguration(), kdeCommandLineOptions.getMaxSplits());
    GeoWaveInputFormat.setStoreOptions(job.getConfiguration(), inputDataStoreOptions);
    if (kdeCommandLineOptions.getCqlFilter() != null) {
        Geometry bbox = null;
        if (adapter instanceof GeotoolsFeatureDataAdapter) {
            final String geometryAttribute = ((GeotoolsFeatureDataAdapter) adapter).getFeatureType().getGeometryDescriptor().getLocalName();
            final Filter filter = ECQL.toFilter(kdeCommandLineOptions.getCqlFilter());
            final ExtractGeometryFilterVisitorResult geoAndCompareOpData = (ExtractGeometryFilterVisitorResult) filter.accept(new ExtractGeometryFilterVisitor(GeometryUtils.getDefaultCRS(), geometryAttribute), null);
            bbox = geoAndCompareOpData.getGeometry();
        }
        if ((bbox != null) && !bbox.equals(GeometryUtils.infinity())) {
            bldr = bldr.constraints(bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(bbox).build());
        }
    }
    GeoWaveInputFormat.setQuery(conf, bldr.build(), adapterStore, internalAdapterStore, indexStore);
    FileSystem fs = null;
    try {
        fs = FileSystem.get(conf);
        fs.delete(new Path("/tmp/" + inputDataStoreOptions.getGeoWaveNamespace() + "_stats_" + kdeCommandLineOptions.getMinLevel() + "_" + kdeCommandLineOptions.getMaxLevel() + "_" + kdeCommandLineOptions.getCoverageName()), true);
        FileOutputFormat.setOutputPath(job, new Path("/tmp/" + inputDataStoreOptions.getGeoWaveNamespace() + "_stats_" + kdeCommandLineOptions.getMinLevel() + "_" + kdeCommandLineOptions.getMaxLevel() + "_" + kdeCommandLineOptions.getCoverageName() + "/basic"));
        final boolean job1Success = job.waitForCompletion(true);
        boolean job2Success = false;
        boolean postJob2Success = false;
        // Linear MapReduce job chaining
        if (job1Success) {
            setupEntriesPerLevel(job, conf);
            // Stats Reducer Job configuration parameters
            final Job statsReducer = new Job(conf);
            statsReducer.setJarByClass(this.getClass());
            addJobClasspathDependencies(statsReducer, conf);
            statsReducer.setJobName(getJob2Name());
            statsReducer.setMapperClass(IdentityMapper.class);
            statsReducer.setPartitionerClass(getJob2Partitioner());
            statsReducer.setReducerClass(getJob2Reducer());
            statsReducer.setNumReduceTasks(getJob2NumReducers((kdeCommandLineOptions.getMaxLevel() - kdeCommandLineOptions.getMinLevel()) + 1));
            statsReducer.setMapOutputKeyClass(DoubleWritable.class);
            statsReducer.setMapOutputValueClass(LongWritable.class);
            statsReducer.setOutputKeyClass(getJob2OutputKeyClass());
            statsReducer.setOutputValueClass(getJob2OutputValueClass());
            statsReducer.setInputFormatClass(SequenceFileInputFormat.class);
            statsReducer.setOutputFormatClass(getJob2OutputFormatClass());
            FileInputFormat.setInputPaths(statsReducer, new Path("/tmp/" + inputDataStoreOptions.getGeoWaveNamespace() + "_stats_" + kdeCommandLineOptions.getMinLevel() + "_" + kdeCommandLineOptions.getMaxLevel() + "_" + kdeCommandLineOptions.getCoverageName() + "/basic"));
            setupJob2Output(conf, statsReducer, outputDataStoreOptions.getGeoWaveNamespace(), kdeCoverageName, outputPrimaryIndex);
            job2Success = statsReducer.waitForCompletion(true);
            if (job2Success) {
                postJob2Success = postJob2Actions(conf, outputDataStoreOptions.getGeoWaveNamespace(), kdeCoverageName);
            }
        } else {
            job2Success = false;
        }
        if (rasterResizeOutputDataStoreOptions != null) {
            // delegate to resize command to wrap it up with the correctly
            // requested tile size
            final ResizeMRCommand resizeCommand = new ResizeMRCommand();
            final File configFile = File.createTempFile("temp-config", null);
            final ManualOperationParams params = new ManualOperationParams();
            params.getContext().put(ConfigOptions.PROPERTIES_FILE_CONTEXT, configFile);
            final AddStoreCommand addStore = new AddStoreCommand();
            addStore.setParameters("temp-out");
            addStore.setPluginOptions(outputDataStoreOptions);
            addStore.execute(params);
            addStore.setParameters("temp-raster-out");
            addStore.setPluginOptions(rasterResizeOutputDataStoreOptions);
            addStore.execute(params);
            // We're going to override these anyway.
            resizeCommand.setParameters("temp-out", "temp-raster-out");
            resizeCommand.getOptions().setInputCoverageName(kdeCoverageName);
            resizeCommand.getOptions().setMinSplits(kdeCommandLineOptions.getMinSplits());
            resizeCommand.getOptions().setMaxSplits(kdeCommandLineOptions.getMaxSplits());
            resizeCommand.setHdfsHostPort(kdeCommandLineOptions.getHdfsHostPort());
            resizeCommand.setJobTrackerOrResourceManHostPort(kdeCommandLineOptions.getJobTrackerOrResourceManHostPort());
            resizeCommand.getOptions().setOutputCoverageName(kdeCommandLineOptions.getCoverageName());
            resizeCommand.getOptions().setOutputTileSize(kdeCommandLineOptions.getTileSize());
            final int resizeStatus = ToolRunner.run(resizeCommand.createRunner(params), new String[] {});
            if (resizeStatus == 0) {
                // delegate to clear command to clean up with tmp namespace
                // after successful resize
                final ClearStoreCommand clearCommand = new ClearStoreCommand();
                clearCommand.setParameters("temp-out");
                clearCommand.execute(params);
            } else {
                LOGGER.warn("Resize command error code '" + resizeStatus + "'.  Retaining temporary namespace '" + outputDataStoreOptions.getGeoWaveNamespace() + "' with tile size of 1.");
            }
        }
        fs.delete(new Path("/tmp/" + inputDataStoreOptions.getGeoWaveNamespace() + "_stats_" + kdeCommandLineOptions.getMinLevel() + "_" + kdeCommandLineOptions.getMaxLevel() + "_" + kdeCommandLineOptions.getCoverageName()), true);
        return (job1Success && job2Success && postJob2Success) ? 0 : 1;
    } finally {
        if (fs != null) {
            try {
                fs.close();
            } catch (final IOException e) {
                LOGGER.info(e.getMessage());
            // Attempt to close, but don't throw an error if it is
            // already closed.
            // Log message, so find bugs does not complain.
            }
        }
    }
}
Also used : VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) Configuration(org.apache.hadoop.conf.Configuration) ClearStoreCommand(org.locationtech.geowave.core.store.cli.store.ClearStoreCommand) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) Index(org.locationtech.geowave.core.store.api.Index) Properties(java.util.Properties) AddStoreCommand(org.locationtech.geowave.core.store.cli.store.AddStoreCommand) SpatialDimensionalityTypeProvider(org.locationtech.geowave.core.geotime.index.SpatialDimensionalityTypeProvider) ManualOperationParams(org.locationtech.geowave.core.cli.parser.ManualOperationParams) DataStorePluginOptions(org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions) GeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter) FileSystem(org.apache.hadoop.fs.FileSystem) ExtractGeometryFilterVisitorResult(org.locationtech.geowave.core.geotime.util.ExtractGeometryFilterVisitorResult) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Job(org.apache.hadoop.mapreduce.Job) ResizeMRCommand(org.locationtech.geowave.adapter.raster.operations.ResizeMRCommand) Path(org.apache.hadoop.fs.Path) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) IOException(java.io.IOException) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) Geometry(org.locationtech.jts.geom.Geometry) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) Filter(org.opengis.filter.Filter) StoreFactoryOptions(org.locationtech.geowave.core.store.StoreFactoryOptions) ExtractGeometryFilterVisitor(org.locationtech.geowave.core.geotime.util.ExtractGeometryFilterVisitor) File(java.io.File) IndexStore(org.locationtech.geowave.core.store.index.IndexStore)

Example 5 with StoreFactoryOptions

use of org.locationtech.geowave.core.store.StoreFactoryOptions in project geowave by locationtech.

the class GeoWaveDocumentationExamplesIT method testExamples.

@Test
public void testExamples() throws Exception {
    // !!IMPORTANT!! If this test has to be updated, update the associated programmatic API example
    // in the dev guide!
    StoreFactoryOptions options = dataStore.getFactoryOptions();
    DataStore myStore = DataStoreFactory.createDataStore(options);
    // --------------------------------------------------------------------
    // Create Indices Example !! See Note at Top of Test
    // --------------------------------------------------------------------
    // Spatial Index
    SpatialIndexBuilder spatialIndexBuilder = new SpatialIndexBuilder();
    spatialIndexBuilder.setCrs("EPSG:4326");
    Index spatialIndex = spatialIndexBuilder.createIndex();
    // Spatial-temporal Index
    SpatialTemporalIndexBuilder spatialTemporalIndexBuilder = new SpatialTemporalIndexBuilder();
    spatialTemporalIndexBuilder.setCrs("EPSG:3857");
    spatialTemporalIndexBuilder.setPeriodicity(Unit.MONTH);
    Index spatialTemporalIndex = spatialTemporalIndexBuilder.createIndex();
    // --------------------------------------------------------------------
    // --------------------------------------------------------------------
    // Add Indices Example !! See Note at Top of Test
    // --------------------------------------------------------------------
    // Add the spatial and spatial-temporal indices
    myStore.addIndex(spatialIndex);
    myStore.addIndex(spatialTemporalIndex);
    // --------------------------------------------------------------------
    // --------------------------------------------------------------------
    // Ingest Example !! See Note at Top of Test
    // --------------------------------------------------------------------
    // Create a point feature type
    SimpleFeatureTypeBuilder pointTypeBuilder = new SimpleFeatureTypeBuilder();
    AttributeTypeBuilder attributeBuilder = new AttributeTypeBuilder();
    pointTypeBuilder.setName("TestPointType");
    pointTypeBuilder.add(attributeBuilder.binding(Point.class).nillable(false).buildDescriptor("the_geom"));
    pointTypeBuilder.add(attributeBuilder.binding(Date.class).nillable(false).buildDescriptor("date"));
    SimpleFeatureType pointType = pointTypeBuilder.buildFeatureType();
    // Create a feature builder
    SimpleFeatureBuilder pointFeatureBuilder = new SimpleFeatureBuilder(pointType);
    // Create an adapter for point type
    FeatureDataAdapter pointTypeAdapter = new FeatureDataAdapter(pointType);
    // Add the point type to the data store in the spatial index
    myStore.addType(pointTypeAdapter, spatialIndex);
    // Create a writer to ingest data
    try (Writer<SimpleFeature> writer = myStore.createWriter(pointTypeAdapter.getTypeName())) {
        // Write some features to the data store
        GeometryFactory factory = new GeometryFactory();
        pointFeatureBuilder.set("the_geom", factory.createPoint(new Coordinate(1, 1)));
        pointFeatureBuilder.set("date", new Date());
        writer.write(pointFeatureBuilder.buildFeature("feature1"));
        pointFeatureBuilder.set("the_geom", factory.createPoint(new Coordinate(5, 5)));
        pointFeatureBuilder.set("date", new Date());
        writer.write(pointFeatureBuilder.buildFeature("feature2"));
        pointFeatureBuilder.set("the_geom", factory.createPoint(new Coordinate(-5, -5)));
        pointFeatureBuilder.set("date", new Date());
        writer.write(pointFeatureBuilder.buildFeature("feature3"));
    }
    // --------------------------------------------------------------------
    // --------------------------------------------------------------------
    // Query Data Example !! See Note at Top of Test
    // --------------------------------------------------------------------
    // Create the query builder and constraints factory
    VectorQueryBuilder queryBuilder = VectorQueryBuilder.newBuilder();
    VectorQueryConstraintsFactory constraintsFactory = queryBuilder.constraintsFactory();
    // Use the constraints factory to create a bounding box constraint
    queryBuilder.constraints(constraintsFactory.cqlConstraints("BBOX(the_geom, -1, -1, 6, 6)"));
    // Only query data from the point type
    queryBuilder.addTypeName(pointTypeAdapter.getTypeName());
    // Build the query
    Query<SimpleFeature> query = queryBuilder.build();
    // Execute the query
    try (CloseableIterator<SimpleFeature> features = myStore.query(query)) {
        // Iterate through the results
        while (features.hasNext()) {
            SimpleFeature feature = features.next();
        // Do something with the feature
        }
    }
    // Verify example
    try (CloseableIterator<SimpleFeature> features = myStore.query(queryBuilder.build())) {
        // Iterate through the results
        int featureCount = 0;
        while (features.hasNext()) {
            features.next();
            featureCount++;
        // Do something with the feature
        }
        Assert.assertEquals(2, featureCount);
    }
    // --------------------------------------------------------------------
    // Aggregation Example !! See Note at Top of Test
    // --------------------------------------------------------------------
    // Create the aggregation query builder
    VectorAggregationQueryBuilder<Persistable, Object> aggregationQueryBuilder = VectorAggregationQueryBuilder.newBuilder();
    // Use the constraints factory from the previous example to create a bounding box constraint
    aggregationQueryBuilder.constraints(constraintsFactory.cqlConstraints("BBOX(the_geom, -1, -1, 6, 6)"));
    // Configure the query to use a count aggregation on the desired type
    aggregationQueryBuilder.count(pointTypeAdapter.getTypeName());
    // Create the aggregation query
    AggregationQuery<Persistable, Object, SimpleFeature> aggregationQuery = aggregationQueryBuilder.build();
    // Perform the aggregation
    long count = (Long) myStore.aggregate(aggregationQuery);
    // --------------------------------------------------------------------
    // Verify example
    Assert.assertEquals(2, count);
    // --------------------------------------------------------------------
    // Statistics Example !! See Note at Top of Test
    // --------------------------------------------------------------------
    // Create the statistics query builder for the BoundingBoxStatistic
    FieldStatisticQueryBuilder<BoundingBoxValue, Envelope> builder = SpatialTemporalStatisticQueryBuilder.bbox();
    // Specify the type name
    builder.typeName(pointTypeAdapter.getTypeName());
    // Create the bounding box statistics query
    StatisticQuery<BoundingBoxValue, Envelope> bboxQuery = builder.build();
    // Aggregate the statistic into a single result
    BoundingBoxValue bboxStatValue = myStore.aggregateStatistics(bboxQuery);
    // Get the value
    Envelope bbox = bboxStatValue.getValue();
    // --------------------------------------------------------------------
    // Verify example
    Assert.assertEquals(-5.0, bbox.getMinX(), 0.0001);
    Assert.assertEquals(-5.0, bbox.getMinY(), 0.0001);
    Assert.assertEquals(5.0, bbox.getMaxX(), 0.0001);
    Assert.assertEquals(5.0, bbox.getMaxY(), 0.0001);
}
Also used : VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Persistable(org.locationtech.geowave.core.index.persist.Persistable) Index(org.locationtech.geowave.core.store.api.Index) BoundingBoxValue(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic.BoundingBoxValue) Envelope(org.locationtech.jts.geom.Envelope) AttributeTypeBuilder(org.geotools.feature.AttributeTypeBuilder) VectorQueryConstraintsFactory(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryConstraintsFactory) SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) DataStore(org.locationtech.geowave.core.store.api.DataStore) Point(org.locationtech.jts.geom.Point) Date(java.util.Date) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Point(org.locationtech.jts.geom.Point) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) StoreFactoryOptions(org.locationtech.geowave.core.store.StoreFactoryOptions) SpatialTemporalIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Test(org.junit.Test)

Aggregations

StoreFactoryOptions (org.locationtech.geowave.core.store.StoreFactoryOptions)5 DataStore (org.locationtech.geowave.core.store.api.DataStore)4 Index (org.locationtech.geowave.core.store.api.Index)4 Test (org.junit.Test)3 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)3 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)3 PersistentAdapterStore (org.locationtech.geowave.core.store.adapter.PersistentAdapterStore)3 IndexStore (org.locationtech.geowave.core.store.index.IndexStore)3 Coordinate (org.locationtech.jts.geom.Coordinate)3 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)3 SimpleFeature (org.opengis.feature.simple.SimpleFeature)3 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)3 SimpleFeatureItemWrapperFactory (org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory)2 VectorQueryBuilder (org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder)2 StoreFactoryFamilySpi (org.locationtech.geowave.core.store.StoreFactoryFamilySpi)2 InternalAdapterStore (org.locationtech.geowave.core.store.adapter.InternalAdapterStore)2 DataStorePluginOptions (org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1