Delete spatiotemporal objects
HBase Ganos allows you to delete spatiotemporal objects by time range, spatiotemporal range, or spatiotemporal object ID.
Delete by time range
HBase Ganos uses the HBase Time to Live (TTL) feature to delete expired data. Modify the TTL property of the spatiotemporal index table in HBase Shell. If you have multiple index tables, repeat this operation for each table.
For example, assume you have a spatiotemporal index table named xxx_z3 and a property index table named xxx_attr. To delete data older than 5 minutes, execute the following statements:
Alter 'xxx_z3',{NAME=>'d',TTL=>300}
Alter 'xxx_attr',{NAME=>'d',TTL=>300}
Delete by spatiotemporal range
This method removes data from z2/xz2 and z3/xz3 spatiotemporal index tables but does not affect other types of index tables. If a property index table also exists, data inconsistency may occur between the spatiotemporal and property index tables. Use this method only when you have spatiotemporal index tables. Follow these steps:
-
Construct a filter to select the objects to delete. This filtering mechanism is the same as the one used for queries.
-
Use the SimpleFeatureStore.removeFeatures interface of GeoTools to delete the objects that match the filter.
/**
* Deletes data that matches the filter range.
* @param schema The schema name.
* @param filterString The filter described as a string. It must conform to ECQL syntax.
* @throws Exception
*/
public void removeByFilter(String schema, String filterString) throws Exception {
SimpleFeatureStore fs = (SimpleFeatureStore) ds.getFeatureSource(schema);
// If filterString is empty, delete all data.
if (StringUtils.isEmpty(filterString)){
fs.removeFeatures(Filter.INCLUDE);
return;
}
Filter filterToDelete = ECQL.toFilter(filterString);
fs.removeFeatures(filterToDelete);
}
Delete by spatial object ID
This method removes data from the ID index table but does not affect other index tables. Use this method only if you have an ID index table. Call the SimpleFeatureStore.removeFeatures interface in GeoTools to delete an object by its ID.
public void removeById(String schema,String simpleFeatureId) throws Exception{
// This example shows how to construct a filter using FilterFactory2.
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Filter filterToDelete = ff.id(ff.featureId(simpleFeatureId));
SimpleFeatureStore fs = ds.getFeatureSource(schema);
fs.removeFeatures(filterToDelete);
}