Search in sources :

Example 1 with SpatialIndexBuilder

use of org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder in project geowave by locationtech.

the class SpatialQueryExample method ingestPolygonFeature.

private void ingestPolygonFeature() throws ParseException {
    log.info("Ingesting polygon data");
    // First, we'll build our third kind of SimpleFeature, which we'll call
    // "polygon-feature"
    // We need the type builder to build the feature type
    final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder();
    // AttributeTypeBuilder for the attributes of the SimpleFeature
    final AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder();
    // Here we're setting the SimpleFeature name. Later on, we'll be able to
    // query GW just by this particular feature.
    sftBuilder.setName("polygon-feature");
    // Add the attributes to the feature
    // Add the geometry attribute, which is mandatory for GeoWave to be able
    // to construct an index out of the SimpleFeature
    // Will be any arbitrary geometry; in this case, a polygon.
    sftBuilder.add(attrBuilder.binding(Geometry.class).nillable(false).buildDescriptor("geometry"));
    // Add another attribute just to be able to filter by it in CQL
    sftBuilder.add(attrBuilder.binding(String.class).nillable(false).buildDescriptor("filter"));
    // Create the SimpleFeatureType
    final SimpleFeatureType sfType = sftBuilder.buildFeatureType();
    // We need the adapter for all our operations with GeoWave
    final FeatureDataAdapter sfAdapter = new FeatureDataAdapter(sfType);
    // Now we build the actual features. We'll create one polygon.
    // First point
    final SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sfType);
    // For ease of use, we'll create the polygon geometry with WKT format.
    final String polygonDefinition = "POLYGON (( " + "-80.3045654296875 25.852426562716428, " + "-80.123291015625 25.808545671771615, " + "-80.19195556640625 25.7244467526159, " + "-80.34233093261719 25.772068899816585, " + "-80.3045654296875 25.852426562716428" + "))";
    final Geometry geom = new WKTReader(JTSFactoryFinder.getGeometryFactory()).read(polygonDefinition);
    sfBuilder.set("geometry", geom);
    sfBuilder.set("filter", "Polygon");
    // When calling buildFeature, we need to pass an unique id for that
    // feature, or it will be overwritten.
    final SimpleFeature polygon = sfBuilder.buildFeature("1");
    final ArrayList<SimpleFeature> features = new ArrayList<>();
    features.add(polygon);
    // Ingest the data. For that purpose, we need the feature adapter,
    // the index type (the default spatial index is used here),
    // and an iterator of SimpleFeature
    ingest(sfAdapter, new SpatialIndexBuilder().createIndex(), features);
    log.info("Polygon data ingested");
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) AttributeTypeBuilder(org.geotools.feature.AttributeTypeBuilder) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) ArrayList(java.util.ArrayList) WKTReader(org.locationtech.jts.io.WKTReader) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 2 with SpatialIndexBuilder

use of org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder in project geowave by locationtech.

the class SpatialQueryExample method ingestPointBasicFeature.

private void ingestPointBasicFeature() {
    // First, we'll build our first kind of SimpleFeature, which we'll call
    // "basic-feature"
    // We need the type builder to build the feature type
    final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder();
    // AttributeTypeBuilder for the attributes of the SimpleFeature
    final AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder();
    // Here we're setting the SimpleFeature name. Later on, we'll be able to
    // query GW just by this particular feature.
    sftBuilder.setName("basic-feature");
    // Add the attributes to the feature
    // Add the geometry attribute, which is mandatory for GeoWave to be able
    // to construct an index out of the SimpleFeature
    sftBuilder.add(attrBuilder.binding(Point.class).nillable(false).buildDescriptor("geometry"));
    // Add another attribute just to be able to filter by it in CQL
    sftBuilder.add(attrBuilder.binding(String.class).nillable(false).buildDescriptor("filter"));
    // Create the SimpleFeatureType
    final SimpleFeatureType sfType = sftBuilder.buildFeatureType();
    // We need the adapter for all our operations with GeoWave
    final FeatureDataAdapter sfAdapter = new FeatureDataAdapter(sfType);
    // Now we build the actual features. We'll create two points.
    // First point
    final SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sfType);
    sfBuilder.set("geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(-80.211181640625, 25.848101000701597)));
    sfBuilder.set("filter", "Basic-Stadium");
    // When calling buildFeature, we need to pass an unique id for that
    // feature, or it will be overwritten.
    final SimpleFeature basicPoint1 = sfBuilder.buildFeature("1");
    // Construct the second feature.
    sfBuilder.set("geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(-80.191360, 25.777804)));
    sfBuilder.set("filter", "Basic-College");
    final SimpleFeature basicPoint2 = sfBuilder.buildFeature("2");
    final ArrayList<SimpleFeature> features = new ArrayList<>();
    features.add(basicPoint1);
    features.add(basicPoint2);
    // Ingest the data. For that purpose, we need the feature adapter,
    // the index type (the default spatial index is used here),
    // and an iterator of SimpleFeature
    ingest(sfAdapter, new SpatialIndexBuilder().createIndex(), features);
}
Also used : AttributeTypeBuilder(org.geotools.feature.AttributeTypeBuilder) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) ArrayList(java.util.ArrayList) Point(org.locationtech.jts.geom.Point) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 3 with SpatialIndexBuilder

use of org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder in project geowave by locationtech.

the class CustomStatisticExample method run.

public void run() {
    // Create an in-memory data store to use with this example
    dataStore = DataStoreFactory.createDataStore(new MemoryRequiredOptions());
    // Create the simple feature type for our data
    simpleFeatureType = getSimpleFeatureType();
    // Create an adapter for our features
    adapter = new FeatureDataAdapter(simpleFeatureType);
    // Create the spatial index
    spatialIndex = new SpatialIndexBuilder().createIndex();
    // Add the type to the data store with the spatial and custom indices
    dataStore.addType(adapter, spatialIndex);
    // Create a word count statistic on the `str` field of our type for all words
    final WordCountStatistic allWords = new WordCountStatistic();
    allWords.setTypeName(adapter.getTypeName());
    allWords.setFieldName("str");
    allWords.setMinWordLength(0);
    allWords.setTag("ALL_WORDS");
    // Create a word count statistic on the `str` field of our type for long words
    final WordCountStatistic longWords = new WordCountStatistic();
    longWords.setTypeName(adapter.getTypeName());
    longWords.setFieldName("str");
    longWords.setMinWordLength(5);
    longWords.setTag("LONG_WORDS");
    // Add the statistics
    dataStore.addStatistic(allWords, longWords);
    // Ingest the data into a spatial index
    ingestData();
    // Get the statistics
    System.out.println("Total number of words: " + dataStore.getStatisticValue(allWords));
    System.out.println("Total number of long words: " + dataStore.getStatisticValue(longWords));
    // You can also get the actual statistics from the data store at a later time
    final WordCountStatistic stat = (WordCountStatistic) dataStore.getFieldStatistic(WordCountStatistic.STATS_TYPE, adapter.getTypeName(), "str", "ALL_WORDS");
    System.out.println("ALL_WORDS Statistic: " + stat.toString());
}
Also used : SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) MemoryRequiredOptions(org.locationtech.geowave.core.store.memory.MemoryRequiredOptions) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter)

Example 4 with SpatialIndexBuilder

use of org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder in project geowave by locationtech.

the class GeoWaveCustomIndexIT method testQueries.

private void testQueries(boolean spatialTemporal) {
    final DataStore dataStore = dataStoreOptions.createDataStore();
    final VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder();
    final Calendar cal = Calendar.getInstance();
    cal.set(1996, Calendar.JUNE, 15, 1, 1, 1);
    final Date startQueryTime = cal.getTime();
    cal.set(1996, Calendar.JUNE, 16, 1, 1, 1);
    Assert.assertEquals(513L, (long) dataStore.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).build()).getValue());
    final Date endQueryTime = cal.getTime();
    if (spatialTemporal) {
        // if spatial/temporal indexing exists explicitly set the appropriate one
        bldr.indexName(new SpatialIndexBuilder().createIndex().getName());
    }
    try (CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 2, 0, 2))).build()).build())) {
        Assert.assertEquals(27, Iterators.size(it));
    }
    if (spatialTemporal) {
        // if spatial/temporal indexing exists explicitly set the appropriate one
        bldr.indexName(new SpatialTemporalIndexBuilder().createIndex().getName());
    }
    try (CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 2, 0, 2))).addTimeRange(startQueryTime, endQueryTime).build()).build())) {
        Assert.assertEquals(9, Iterators.size(it));
    }
    try (CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().customConstraints(new TestEnumConstraints(TestEnum.A))).indexName(TEST_ENUM_INDEX_NAME).build())) {
        Assert.assertEquals(513 / 2, Iterators.size(it));
    }
    try (CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().customConstraints(new TestEnumConstraints(TestEnum.B))).indexName(TEST_ENUM_INDEX_NAME).build())) {
        Assert.assertEquals(513 / 3, Iterators.size(it));
    }
    try (CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().customConstraints(new TestEnumConstraints(TestEnum.C))).indexName(TEST_ENUM_INDEX_NAME).build())) {
        Assert.assertEquals(513 / 5, Iterators.size(it));
    }
}
Also used : VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) DataStore(org.locationtech.geowave.core.store.api.DataStore) Calendar(java.util.Calendar) SpatialTemporalIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder) Envelope(org.locationtech.jts.geom.Envelope) Date(java.util.Date) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 5 with SpatialIndexBuilder

use of org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder in project geowave by locationtech.

the class GeoWaveFeatureReaderTest method setup.

@Before
public void setup() throws SchemaException, CQLException, Exception {
    dataStore = createDataStore();
    type = DataUtilities.createType("GeoWaveFeatureReaderTest", "geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String");
    ((GeoWaveGTDataStore) dataStore).getDataStore().addIndex(new SpatialIndexBuilder().createIndex());
    ((GeoWaveGTDataStore) dataStore).getDataStore().addIndex(new SpatialTemporalIndexBuilder().createIndex());
    dataStore.createSchema(type);
    ((GeoWaveGTDataStore) dataStore).getDataStore().addIndex(type.getTypeName(), AttributeDimensionalityTypeProvider.createIndexFromOptions(((GeoWaveGTDataStore) dataStore).getDataStore(), new AttributeIndexOptions(type.getTypeName(), "pop")));
    stime = DateUtilities.parseISO("2005-05-15T20:32:56Z");
    mtime = DateUtilities.parseISO("2005-05-20T20:32:56Z");
    etime = DateUtilities.parseISO("2005-05-25T20:32:56Z");
    final Transaction transaction1 = new DefaultTransaction();
    final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1);
    assertFalse(writer.hasNext());
    SimpleFeature newFeature = writer.next();
    newFeature.setAttribute("pop", Long.valueOf(100));
    newFeature.setAttribute("pid", "a" + UUID.randomUUID().toString());
    newFeature.setAttribute("start", stime);
    newFeature.setAttribute("end", mtime);
    newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));
    fids.add(newFeature.getID());
    pids.add(newFeature.getAttribute("pid").toString());
    writer.write();
    newFeature = writer.next();
    newFeature.setAttribute("pop", Long.valueOf(101));
    newFeature.setAttribute("pid", "b" + UUID.randomUUID().toString());
    newFeature.setAttribute("start", mtime);
    newFeature.setAttribute("end", etime);
    newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(28.25, 41.25)));
    fids.add(newFeature.getID());
    pids.add(newFeature.getAttribute("pid").toString());
    writer.write();
    writer.close();
    transaction1.commit();
    transaction1.close();
    query = new Query("GeoWaveFeatureReaderTest", ECQL.toFilter("IN ('" + fids.get(0) + "')"), new String[] { "geometry", "pid" });
}
Also used : AttributeIndexOptions(org.locationtech.geowave.core.store.index.AttributeIndexOptions) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Query(org.geotools.data.Query) Coordinate(org.locationtech.jts.geom.Coordinate) SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) SpatialTemporalIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Before(org.junit.Before)

Aggregations

SpatialIndexBuilder (org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder)21 DataStore (org.locationtech.geowave.core.store.api.DataStore)10 SpatialTemporalIndexBuilder (org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder)8 SimpleFeature (org.opengis.feature.simple.SimpleFeature)8 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)6 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)6 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)5 Index (org.locationtech.geowave.core.store.api.Index)5 AttributeTypeBuilder (org.geotools.feature.AttributeTypeBuilder)4 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)4 Coordinate (org.locationtech.jts.geom.Coordinate)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 MemoryRequiredOptions (org.locationtech.geowave.core.store.memory.MemoryRequiredOptions)3 Point (org.locationtech.jts.geom.Point)3 WritableRaster (java.awt.image.WritableRaster)2 Date (java.util.Date)2 VectorQueryBuilder (org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder)2 Rectangle (java.awt.Rectangle)1 Raster (java.awt.image.Raster)1