javacassandrageomesa

Geomesa: how to get last geopoint and how to get unique attributes within bbox?


I have cassandra with geomesa, in there I have next schema

 ~  bin/geomesa-cassandra_2.11-3.3.0/bin/geomesa-cassandra describe-schema -P localhost:9042 -u cassandra -p cassandra -k geomesa -c gsm_events -f SignalBuilder 
INFO  Describing attributes of feature 'SignalBuilder'
geo           | Point   (Spatio-temporally indexed)
time          | Date    (Spatio-temporally indexed) (Attribute indexed)
cam           | String  (Attribute indexed) (Attribute indexed)
imei          | String  (Attribute indexed)
dir           | Double  
alt           | Double  
vlc           | Double  
sl            | Integer 
ds            | Integer 
dir_y         | Double  
poi_azimuth_x | Double  
poi_azimuth_y | Double  

User data:
  geomesa.attr.splits     | 4
  geomesa.feature.expiry  | time(30 days)
  geomesa.index.dtg       | time
  geomesa.indices         | z3:7:3:geo:time,attr:8:3:time,attr:8:3:cam,attr:8:3:cam:time,attr:8:3:imei
  geomesa.stats.enable    | true
  geomesa.table.partition | time
  geomesa.z.splits        | 4
  geomesa.z3.interval     | week

Is there any way to get last coordinate by cam within bbox? And how to get all unique cams (I use String UUID for camId) within bbox?

Now I'm reading everithing within bbox, and then calculate programmatically the last coordinate and unique cams,

for last event I put GeoEvents in map<String Cam, Point point> with TimeComparator

for unique cam I do next:

Set<String> result = new HashSet<>(10);
for (Query query: qs) {
  try (FeatureReader<SimpleFeatureType, SimpleFeature> reader = 
dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT)) {
    while (reader.hasNext()) {
      result.add((String)reader.next().getAttribute("cam"));
    }
  }
}

Solution

  • You can use the GeoMesa stats API for some of this. You can use the enumeration stat to get all unique values, and you can use the min/max stat to get the "last" value.

    The stats API does not bring back the entire feature, so if you want that you would need to do a secondary lookup or simply iterate over results as you are doing.

    However, since Cassandra does not have any server-side processing, using the stats API will not provide much advantage over your current client-side processing.