All Products
Search
Document Center

Lindorm:Delete spatio-temporal objects

Last Updated:Oct 17, 2024

In general, trajectory data is continuously appended to databases. However, you may need to delete spatio-temporal objects in some scenarios. In this case, you can use Lindorm GanosBase to delete spatio-temporal objects by time period, spatio-temporal range, and spatio-temporal object ID.

Lindorm GanosBase allows you to delete expired data based on the Time to Live (TTL) feature of ApsaraDB for HBase. You can use HBase Shell to modify the TTL attribute of the spatio-temporal index table to delete expired data. If you create multiple index tables, you must modify the TTL attribute of each index table.

Warning

Before you delete an index table, make sure that the data in the table is backed up.

For example, if a spatio-temporal index table named xxx_z3 and an attribute index table named xxx_attr is created and you want to delete data that is generated five minutes before the current time in the d column, you must execute the following statements to modify the TTLs of the two tables:

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

The z2/xz2 and z3/xz3 spatio-temporal index tables can be deleted based on spatio-temporal ranges. Other index tables cannot be deleted by using this method. If an attribute index table exists in the database, the data in the spatio-temporal index tables may be inconsistent with the data in the attribute index table. We recommend that you delete spatio-temporal objects based on spatio-temporal ranges when the database contains only spatio-temporal index tables.

Procedure

  • Configure a filter to filter out the objects that you want to delete. This filter is configured in the same manner as the filter that is used for queries.

  • Use the SimpleFeatureStore.removerFeatures method provided by 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 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

If you delete a spatio-temporal object based on its ID, only the data in the index table with the specified ID is deleted. Data in other index tables is not deleted. If only one ID index table is created in the database, you can use this method to delete spatio-temporal objects.

Procedure

Use the SimpleFeatureStore.removerFeatures method provided by GeoTools to delete the objects that match the specified IDs.

public void removeById(String schema,String simpleFeatureId) throws Exception{
    // In this example, the filter is configured by using FilterFactory2.
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2;
    Filter filterToDelete = ff.id(ff.featureId(simpleFeatureId));
    SimpleFeatureStore fs = ds.getFeatureSource(schema);
    fs.removeFeatures(filterToDelete);
}