In most scenarios, trajectory data is appended to a database. If you need to delete spatio-temporal objects, you can use ApsaraDB for HBase Ganos (HBase Ganos) to delete the spatio-temporal objects based on the specified time period, time range, or spatio-temporal object ID.

Delete spatio-temporal objects based on the specified time period

HBase Ganos allows you to use the Time to Live (TTL) feature of ApsaraDB for HBase to delete expired data. You can use HBase Shell to modify the TTL attribute of the spatio-temporal index table to delete expired data. If you have created multiple index tables, you must perform this operation on each index table.

For example, you have created the spatio-temporal index table xxx_z3 and the attribute index table xxx_attr. You want to delete the data that was generated 5 minutes ago in the d column, you can execute the following statement:
Alter 'xxx_z3',{NAME=>'d',TTL=>300}
Alter 'xxx_attr',{NAME=>'d',TTL=>300}

Delete spatio-temporal objects based on the specified spatio-temporal range

If you delete spatio-temporal objects based on a spatio-temporal range, only the objects that correspond to the spatio-temporal index tables of the z2, xz2, z3, xz3 types can be deleted. If an attribute index table exists, the data in the spatio-temporal index tables may be inconsistent with the data in the attribute index table. We recommend that you use this method to delete spatio-temporal objects when only spatio-temporal index tables are available. Perform the following steps to delete objects based on the specified spatio-temporal range:
  1. Configure a filter. You can use a filter to filter the objects that you want to delete. This filter is configured in the same way as the filter that is used to query spatio-temporal objects.
  2. Use the SimpleFeatureStore.removerFeatures method of GeoTools to delete the objects that trigger the filter.
/**
 * Delete the data that triggers the filter.
 * @param schema: the schema name.
 * @param filterString: the filter string. The string must comply with the Extended Common Query Language (ECQL) syntax.
 * @throws Exception
 */
public void removeByFilter(String schema, String filterString) throws Exception {
    SimpleFeatureStore fs = (SimpleFeatureStore) ds.getFeatureSource(schema);
    // If filterString is left empty, all the spatio-temporal objects are deleted.
    if (StringUtils.isEmpty(filterString)){
        fs.removeFeatures(Filter.INCLUDE);
        return;
    }
    Filter filterToDelete = ECQL.toFilter(filterString);
    fs.removeFeatures(filterToDelete);
}

Delete spatio-temporal objects based on the specified spatial object ID

You can use this method to delete only spatio-temporal objects for which you have created ID index tables. If you have created only one ID index table, you can use this method to delete spatio-temporal objects. Use the SimpleFeatureStore.removerFeatures method of GeoTools to delete the objects that match the specified IDs.
public void removeById(String schema,String simpleFeatureId) throws Exception{
    // The filter in this example is configured by using FilterFactory2.
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2
    Filter filterToDelete = ff.id(ff.featureId(simpleFeatureId))
    SimpleFeatureStore fs = ds.getFeatureSource(schema);
    fs.removeFeatures(filterToDelete);
}