Delete spatiotemporal objects

Updated at:

Lindorm GanosBase supports three methods for deleting spatio-temporal objects: TTL-based expiration, deletion by spatio-temporal range, and deletion by object ID. Each method applies to different index configurations.

Choose a deletion method

MethodSupported index typesAffects other indexesUse when
TTL-based expirationAll index tablesYes (set TTL per table)Automatically purge data older than a fixed time threshold
Delete by spatio-temporal rangez2/xz2 and z3/xz3 onlyRisk of inconsistency with attribute indexesOnly spatio-temporal index tables exist in the database
Delete by object IDID index table onlyDoes not delete data from other index tablesOnly one ID index table exists in the database
Warning

Back up your index table data before deleting.

Delete by TTL

Lindorm GanosBase uses the Time to Live (TTL) feature of ApsaraDB for HBase to automatically expire data. You can use HBase Shell to modify the TTL attribute of the spatio-temporal index table to delete expired data.

If multiple index tables exist, set TTL on each table separately. The TTL value is in seconds.

Example: Delete data older than 5 minutes (300 seconds) from a spatio-temporal index table xxx_z3 and an attribute index table xxx_attr:

Alter 'xxx_z3',{NAME=>'d',TTL=>300}
Alter 'xxx_attr',{NAME=>'d',TTL=>300}

Delete by spatio-temporal range

This method applies only to z2/xz2 and z3/xz3 spatio-temporal index tables.

Warning

If the database contains an attribute index table, deleting by spatio-temporal range leaves the attribute index table unchanged. This causes inconsistency between the spatio-temporal index tables and the attribute index table. Only use this method when the database contains spatio-temporal index tables only.

Procedure:

  1. Configure a filter to identify the objects to delete. Use the same filter syntax as for queries — the filter string must comply with Extended Common Query Language (ECQL) syntax.

  2. Call SimpleFeatureStore.removeFeatures() from GeoTools to delete matching objects.

/**
 * Delete spatio-temporal objects that match the specified filter.
 * @param schema       the schema name
 * @param filterString the ECQL filter string; if blank, all objects are deleted
 */
public void removeByFilter(String schema, String filterString) throws Exception {
    SimpleFeatureStore fs = (SimpleFeatureStore) ds.getFeatureSource(schema);
    // If filterString is blank, all spatio-temporal objects are deleted.
    if (StringUtils.isEmpty(filterString)) {
        fs.removeFeatures(Filter.INCLUDE);
        return;
    }
    Filter filterToDelete = ECQL.toFilter(filterString);
    fs.removeFeatures(filterToDelete);
}

Delete by object ID

This method deletes data only from the index table associated with the specified ID. Data in other index tables is not affected.

Note

Only use this method when the database contains a single ID index table. If multiple index tables exist, other indexes retain the data for the deleted object.

Call SimpleFeatureStore.removeFeatures() with an ID filter built using FilterFactory2:

public void removeById(String schema, String simpleFeatureId) throws Exception {
    // Build an ID filter using FilterFactory2.
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
    Filter filterToDelete = ff.id(ff.featureId(simpleFeatureId));
    SimpleFeatureStore fs = (SimpleFeatureStore) ds.getFeatureSource(schema);
    fs.removeFeatures(filterToDelete);
}