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");
}
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);
}
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());
}
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));
}
}
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" });
}
Aggregations