Hejhej,
I've come up with a way to remove all features of a datastore... However,
I'm quite sure that there are more efficient ways to do this, getting rid of
this awkward iteration. Maybe someone can enlighten me.
Thanks very much in advance.
Markus
Code, created for shapefiles...
ShapefileDataStore src...;
try {
String typeName = src.getTypeNames()[0];
DefaultTransaction tran = new DefaultTransaction("RemoveAll");
FeatureStore stor = (FeatureStore)
src.getFeatureSource(typeName);
stor.setTransaction(tran);
FeatureCollection coll =
src.getFeatureSource(typeName).getFeatures();
FeatureIterator iter = coll.features();
FilterFactory fact =
CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
Set<FeatureId> toRemove = new HashSet<FeatureId>();
while (iter.hasNext()) {
Feature ft = iter.next();
toRemove.add(fact.featureId(ft.getID()));
}
iter.close();
Filter filter = fact.id(toRemove);
try {
stor.removeFeatures(filter);
tran.commit();
}
catch (Exception ex) {
System.out.println("something wrong...");
tran.rollback();
}
} catch (Exception ex) {
ex.printStackTrace();
}
--
View this message in context:
http://www.nabble.com/Removing-all-features-in-a-datastore...-tp14753911p14753911.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users