Search in sources :

Example 1 with AssociationNotification

use of org.locationtech.geowave.analytic.kmeans.AssociationNotification 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)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)1 SimpleFeatureItemWrapperFactory (org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory)1 FeatureCentroidDistanceFn (org.locationtech.geowave.analytic.distance.FeatureCentroidDistanceFn)1 AssociationNotification (org.locationtech.geowave.analytic.kmeans.AssociationNotification)1 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)1 StoreFactoryFamilySpi (org.locationtech.geowave.core.store.StoreFactoryFamilySpi)1 StoreFactoryOptions (org.locationtech.geowave.core.store.StoreFactoryOptions)1 PersistentAdapterStore (org.locationtech.geowave.core.store.adapter.PersistentAdapterStore)1 DataStore (org.locationtech.geowave.core.store.api.DataStore)1 Index (org.locationtech.geowave.core.store.api.Index)1 DataStorePluginOptions (org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions)1 IndexStore (org.locationtech.geowave.core.store.index.IndexStore)1 MemoryStoreFactoryFamily (org.locationtech.geowave.core.store.memory.MemoryStoreFactoryFamily)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1