Spatio-temporal objects are created after a collection is created. Then, you can call the writer to write data to Lindorm Ganos.
Write a single SimpleFeature object
Lindorm Ganos uses the SimpleFeatureWriter class in the GeoTools API to insert a single SimpleFeature object. SimpleFeatureWriter supports transactions. You can call the getFeatureWriterAppend method of DataStore to build a SimpleFeatureWriter.
For more information about how to build a SimpleFeatureType and a SimpleFeature object, see the "Quick start" topic.
/**
* write a single SimpleFeature object.
* @param sft SimpleFeatureType
* @param feature: the SimpleFeature object to be written.
* @return the return value. The return value is 1. If the return value is not 1, an error is thrown.
* @throws Exception
*/
public int upsert(SimpleFeatureType sft, SimpleFeature feature) throws Exception {
try{
SimpleFeatureWriter writer=(SimpleFeatureWriter)ds.getFeatureWriterAppend(sft.getTypeName(), Transaction.AUTO_COMMIT);
SimpleFeature toWrite=writer.next();
toWrite.setAttributes(feature.getAttributes());
toWrite.getUserData().putAll(feature.getUserData());
writer.write();
writer.close();
return 1;
} catch (Exception e){
throw new Exception("Data write error" + e.getMessage());
}
}
Write multiple SimpleFeature objects at a time
Lindorm Ganos allows you to insert multiple SimpleFeature objects at a time. You can use the SimpleFeatureStore class in the GeoTools API to implement this operation:
For more information about how to build a SimpleFeatureType and a SimpleFeature object, see the "Quick start" topic.
/**
* Write multiple SimpleFeature objects at a time.
*
* @param sft SimpleFeatureType
* @param features: the collection of SimpleFeature objects to be written.
* @return: the returned actual number of SimpleFeature objects that are written.
* @throws Exception
*/
public int upsert(SimpleFeatureType sft, List<SimpleFeature> features) throws Exception {
try{
SimpleFeatureStore featureStore = (SimpleFeatureStore) ds.getFeatureSource(sft.getTypeName());
List<FeatureId> featureIds = featureStore.addFeatures(new ListFeatureCollection(sft,features));
return featureIds.size();
} catch (Exception e){
throw new Exception("Data write error" + e.getMessage());
}
}