In most cases, SimpleFeatures are continuously "appended" to a database. For example, vehicle trajectory data is written into a database every few seconds. You may want to delete a SimpleFeature in some scenarios. Example:

  • In an Extract-Transform-Load (ETL) processing system, the system may need to mask and aggregate data by deleting sensitive or unused data before it imports the data into databases.
  • The system may also need to delete the data that contains errors.

HBase Ganos allows you to delete a SimpleFeature by specifying the FID of the SimpleFeature. Note: An FID is a unique identifier of a SimpleFeature.

Example

The following example shows how to use the GeoTools interface to delete a SimpleFeature with a specified FID. For more information, see the sample code in the Quick start topic.

  • The input parameter simpleFeatureId specifies the ID of the SimpleFeature to which the data is written. We recommend that you use a user-readable and unique ID, for example, objectId+timeStamp. This makes it easy for you to construct an FID when you want to delete a SimpleFeature.
  • Build a FeatureWriter, and specify the FID of the target SimpleFeature. You can set the transaction type to AUTO_COMMIT.
  • Use the remove function of the FeatureWriter to delete the SimpleFeature.
  • Close the FeatureWriter
public void removeById(String schema,String simpleFeatureId) throws Exception{
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
    FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
        ds.getFeatureWriter(schema, ff.id(ff.featureId(simpleFeatureId)), Transaction.AUTO_COMMIT);
    while (writer.hasNext()) {
        writer.next();
        writer.remove();
    }
    writer.close();
}
			

Considerations

  • Currently, you can only delete SimpleFeatures by FID.
  • You must enable the ID index before you perform this operation. If you fail to delete the SimpleFeature, check whether the ID index is disabled. For more information, see Create an index table.

    • If the code snippet contains the following line, delete it: > sft.getUserData().put("geomesa.disable.id.index", true);

    • You can also choose to create the specified ID index as follows:

sft.getUserData().put("geomesa.indices.enabled", "id:object_id");