Search in sources :

Example 1 with SimpleFeatureItemWrapperFactory

use of org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory in project geowave by locationtech.

the class DBScanIT method readHulls.

private int readHulls() throws Exception {
    final CentroidManager<SimpleFeature> centroidManager = new CentroidManagerGeoWave<>(dataStorePluginOptions.createDataStore(), dataStorePluginOptions.createIndexStore(), dataStorePluginOptions.createAdapterStore(), new SimpleFeatureItemWrapperFactory(), "concave_hull", dataStorePluginOptions.createInternalAdapterStore().addTypeName("concave_hull"), SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions()).getName(), "bx5", 0);
    int count = 0;
    for (final String grp : centroidManager.getAllCentroidGroups()) {
        for (final AnalyticItemWrapper<SimpleFeature> feature : centroidManager.getCentroidsForGroup(grp)) {
            ShapefileTool.writeShape(feature.getName(), new File("./target/test_final_" + feature.getName()), new Geometry[] { feature.getGeometry() });
            count++;
        }
    }
    return count;
}
Also used : SimpleFeatureItemWrapperFactory(org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory) CentroidManagerGeoWave(org.locationtech.geowave.analytic.clustering.CentroidManagerGeoWave) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) File(java.io.File) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Point(org.locationtech.jts.geom.Point)

Example 2 with SimpleFeatureItemWrapperFactory

use of org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory in project geowave by locationtech.

the class DistortionGroupManagementTest method test.

@Test
public void test() throws IOException {
    final DistortionGroupManagement distortionGroupManagement = new DistortionGroupManagement(storePluginOptions);
    distortionGroupManagement.retainBestGroups(new SimpleFeatureItemWrapperFactory(), adapter.getTypeName(), index.getName(), "b1", 1);
    final CentroidManagerGeoWave<SimpleFeature> centroidManager = new CentroidManagerGeoWave<>(storePluginOptions.createDataStore(), storePluginOptions.createIndexStore(), storePluginOptions.createAdapterStore(), new SimpleFeatureItemWrapperFactory(), adapter.getTypeName(), storePluginOptions.createInternalAdapterStore().getAdapterId(adapter.getTypeName()), index.getName(), "b1", 1);
    final List<String> groups = centroidManager.getAllCentroidGroups();
    assertEquals(2, groups.size());
    final boolean[] groupFound = new boolean[2];
    for (final String grpId : groups) {
        final List<AnalyticItemWrapper<SimpleFeature>> items = centroidManager.getCentroidsForGroup(grpId);
        assertEquals(2, items.size());
        if ("grp1".equals(grpId)) {
            groupFound[0] = true;
            assertTrue("pearl".equals(items.get(0).getName()) || "roxy".equals(items.get(0).getName()));
        } else if ("grp2".equals(grpId)) {
            groupFound[1] = true;
            assertTrue("chip".equals(items.get(0).getName()) || "bamm-bamm".equals(items.get(0).getName()));
        }
    }
    // each unique group is found?
    int c = 0;
    for (final boolean gf : groupFound) {
        c += (gf ? 1 : 0);
    }
    assertEquals(2, c);
}
Also used : SimpleFeatureItemWrapperFactory(org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory) AnalyticItemWrapper(org.locationtech.geowave.analytic.AnalyticItemWrapper) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 3 with SimpleFeatureItemWrapperFactory

use of org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory 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 4 with SimpleFeatureItemWrapperFactory

use of org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory in project geowave by locationtech.

the class KMeansParallelInitializeTest method setup.

@Before
public void setup() {
    initializer.getCentroidAssociationFn().setDistanceFunction(new FeatureCentroidDistanceFn());
    initializer.setCentroidFactory(new SimpleFeatureItemWrapperFactory());
    final Sampler<SimpleFeature> sampler = initializer.getSampler();
    sampler.setSampleProbabilityFn(new BahmanEtAlSampleProbabilityFn());
    sampler.setSampleSize(5);
}
Also used : BahmanEtAlSampleProbabilityFn(org.locationtech.geowave.analytic.sample.BahmanEtAlSampleProbabilityFn) SimpleFeatureItemWrapperFactory(org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory) FeatureCentroidDistanceFn(org.locationtech.geowave.analytic.distance.FeatureCentroidDistanceFn) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Before(org.junit.Before)

Example 5 with SimpleFeatureItemWrapperFactory

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

Aggregations

SimpleFeatureItemWrapperFactory (org.locationtech.geowave.analytic.SimpleFeatureItemWrapperFactory)6 SimpleFeature (org.opengis.feature.simple.SimpleFeature)6 Test (org.junit.Test)3 AnalyticItemWrapper (org.locationtech.geowave.analytic.AnalyticItemWrapper)3 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)3 ArrayList (java.util.ArrayList)2 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)2 CentroidManagerGeoWave (org.locationtech.geowave.analytic.clustering.CentroidManagerGeoWave)2 FeatureCentroidDistanceFn (org.locationtech.geowave.analytic.distance.FeatureCentroidDistanceFn)2 StoreFactoryFamilySpi (org.locationtech.geowave.core.store.StoreFactoryFamilySpi)2 StoreFactoryOptions (org.locationtech.geowave.core.store.StoreFactoryOptions)2 PersistentAdapterStore (org.locationtech.geowave.core.store.adapter.PersistentAdapterStore)2 DataStore (org.locationtech.geowave.core.store.api.DataStore)2 Index (org.locationtech.geowave.core.store.api.Index)2 IndexStore (org.locationtech.geowave.core.store.index.IndexStore)2 MemoryStoreFactoryFamily (org.locationtech.geowave.core.store.memory.MemoryStoreFactoryFamily)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 File (java.io.File)1