Next you need to grab a FeatureStore and called addFeatures; there is an
example of this kind of thing in the user guide. And we can add your
example here when we are done with it....
> Hello, I am wondering if there is a simple way of saving a FeatureSource to a
> shapefile. The FeatureSource is backed by an MStore. I can't quite see
> how to do this. I've gotten as far as this:
>
> FeatureSource fs = mapLayer.getFeatureSource(); //pre-existing featursource
> FileDataStoreFactorySpi factory = new IndexedShapefileDataStoreFactory();
> Map map = Collections.singletonMap( "url", file.toURL()); //file from chooser
> DataStore myData = factory.createNewDataStore( map );
> myData.createSchema(fs.getSchema());
>
String typeName = myData.getTypeNames[0];
FeatureStore featureStore = (FeatureStore) myData.getFeatureSource(
typeName );
Transaction t = new DefaultTransaction();
try {
FeatureCollection collection = fs.getFeatures(); // grab all features
featureStore.addFeatures( collection );
t.commit(); // write it out
}
catch( IOException eek){
eek.printStrackTrace();
try {
t.rollback();
}
catch( IOException doubleEeek ){
// rollback failed?
}
}
finally {
t.close();
}
Give that a go (in case I got something wrong) and send me back the
completed code example so I can dump it in the user guide :-)
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users