Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [geomesa-users] Query over different geometry types?

Hi Jason,

Great questions.  I'll re-paste some of the sections and respond inline.  The answer to your first question is 'yes'.:)

1. Is it okay to define multiple geometry types into a single feature type?

Yes.  The chief thing to observe is that the default geometry field is the one used for indexing in GeoMesa. 

2. Can default geometry type be changed per every feature?

No.  The default geometry field is managed per SimpleFeatureType.  (This is part of the GeoTools api.)

3. How can I properly get query results for the above case?
4. Is there anyway that I can query both point_loc and line_loc with a single query? Should I just need to OR two geometry filters? (Is there a better way?)

As an important piece of information, GeoMesa can store and index a geometry column of type 'Geometry' (meaning that there could be a mix of points, lines, etc).  Since GeoMesa optimizes for Point and non-Point geometry types differently, one does have to give a hint to let the system know that being general wasn't a mistake.  See http://www.geomesa.org/documentation/user/datastores/index_config.html#mixed-geometry-types for the hint which needs to be set during SFT creation.

From what you've said, it sounds like your data sometimes has a point or a line, and at ingest time, you could say which field should be used for general purpose querying.  I'd suggest that you can either have an additional mixed geometry field or you can replace one or both of your current geometry fields with a mixed one.

The mixed geometry column would be the default geometry field (and hence indexed).  Your query simplifies to an query on that one field.

If that solution doesn't work, do you have any real-world constraints/relationships between the point_loc and line_loc which could be leveraged?  As an example, suppose that the point_loc was always on the line_loc and that line measured less than 0.1 degrees (around 11km), then one could use an index on point_loc by buffering the bbox by the upper bound for the line length. 

I'm suggesting that one avoid using an OR across two geometry fields since that'll likely result in a full-table scan. 

Cheers,

Jim

On 11/20/2017 8:18 PM, Jason Koh wrote:
Hi,

I am using Geomesa as a database of various sensor measurements. Each sensor's geometry type may vary from Point and LineString to Polygon. Is it possible to store all of them as a feature type and query in a single way?

I currently implement each geometry type as different attributes and define default geometry per feature.

The simplified version of my implementation is:

### Adding an entry

```java
// Define Feature Type
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName("TestFeatureType");
b.add("point_loc", Point.class, 4326);
b.add("line_loc", LineString.class, 4326)
b.add("date", Date.class);
b.add("value", String.class);
b.setDefaultGeometry("point_loc");
SimpleFeatureType featType = b.buildFeatureType();

dataStore.createSchema(featType); // Assume dataStore is loaded.

// Write a feature
FeatureWriter writer = dataStore.getFeatureWriterAppend("TestFeatureType");

// Adding a sensor value with geometry type "LineString"
SimpleFeature newFeature = writer.next();
newFeature.setAttribute("value", "TestValue1");
newFeature.setAttribute("date", SomeDate);
newFeature.setAttribute("line_loc", line); // line is given.
// Not adding point ad line is included.
```

### Querying the value.
```
String cqlGeometry = "BBOX( line_loc, x1, y1, x2, y2)" // Given BBOX includes the point added above.
Filter filter = CQL.toFilter(cqlGeometry);
Query q = new Query("TestFeatureType", filter);
q.getHints().put(QueryHints.LOOSE_BBOX(), Boolean.FALSE);
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore.getFeatureSource("TestFeatureType");
FeatureIterator<SimpleFeature> featureItr = featureSource.getFeatures(query).features();

// This iterator turns out to be empty.
while (featureItr.hasNext()) {
  Feature feat = featureItr.next();
  System.out.println(feat);
}
```

My questions are
1. Is it okay to define multiple geometry types into a single feature type?
2. Can default geometry type be changed per every feature?
3. How can I properly get query results for the above case?
4. Is there anyway that I can query both point_loc and line_loc with a single query? Should I just need to OR two geometry filters? (Is there a better way?)


Thank you so much and I hope that one day I can share the entire project as an instance of using Geomesa.



With regards,
Jason Koh


_______________________________________________
geomesa-users mailing list
geomesa-users@xxxxxxxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.locationtech.org/mailman/listinfo/geomesa-users



Back to the top