leaffan ha scritto:
> 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.
FeatureStore stor = (FeatureStore) src.getFeatureSource(typeName);
stor.removeFeatures(Filter.INCLUDE);
(that's on gt2 2.4.x, on previous versions that Filter.INCLUDE should
be Filter.NONE).
Cheers
Andrea
> 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();
> }
>
>
-------------------------------------------------------------------------
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