Hi,
The only example I found was http://geotools.org/examples/csv2shp.html
(CSV2SHP). I rewrote the code I had and still I am not able to write Shapefile
without any problems. Here is what I get:
Collection size (layer): 2282010-04-29 22.26.34
org.geotools.data.shapefile.ShapefileDataStore createSchemaWARNING: PRJ file
not generated for null CoordinateReferenceSystemCollection size: 2282010-04-29
22.26.35 org.geotools.renderer.lite.StreamingRenderer paintSEVERE: Transaction
has been closedjava.lang.IllegalStateException: Transaction has been closed
at
org.geotools.data.DefaultTransaction.getState(DefaultTransaction.java:153)
at org.geotools.data.AbstractDataStore.state(AbstractDataStore.java:448)
at
org.geotools.data.AbstractDataStore.getFeatureReader(AbstractDataStore.java:375)
at
org.geotools.data.DefaultFeatureResults.reader(DefaultFeatureResults.java:210)
at
org.geotools.data.store.DataFeatureCollection.openIterator(DataFeatureCollection.java:224)
at
org.geotools.data.store.DataFeatureCollection.iterator(DataFeatureCollection.java:194)
at
org.geotools.renderer.lite.StreamingRenderer.drawOptimized(StreamingRenderer.java:1859)
at
org.geotools.renderer.lite.StreamingRenderer.processStylers(StreamingRenderer.java:1792)
at
org.geotools.renderer.lite.StreamingRenderer.paint(StreamingRenderer.java:699)
at
org.geotools.swing.RenderingExecutor$Task.call(RenderingExecutor.java:148)
at org.geotools.swing.RenderingExecutor$Task.call(RenderingExecutor.java:104)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138) at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:637)
Here is my function user for saving MapLayer to the file:
private void saveLayer(MapLayer layer, File file) throws Exception {
DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory();
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("url", file.toURI().toURL()); params.put("create spatial
index", Boolean.TRUE);
ShapefileDataStore newDataStore =
(ShapefileDataStore)dataStoreFactory.createNewDataStore(params);
FeatureSource featureSource = layer.getFeatureSource();
System.out.println("Collection size (layer): " +
layer.getFeatureSource().getFeatures().size());
SimpleFeatureType type = (SimpleFeatureType)featureSource.getSchema();
newDataStore.createSchema(type);
newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
Transaction transaction = new DefaultTransaction("create");
//String typeName = newDataStore.getTypeNames()[0]; //featureSource =
newDataStore.getFeatureSource(typeName);
if (featureSource instanceof FeatureSource) { FeatureStore
featureStore = (FeatureStore)featureSource;
featureStore.setTransaction(transaction);
FeatureCollection collection = featureSource.getFeatures();
System.out.println("Collection size: " + collection.size()); try {
featureStore.addFeatures(collection);
transaction.commit(); } catch (Exception e) {
e.printStackTrace(); transaction.rollback(); }
finally { transaction.close(); } } else {
System.out.println("Can't write Shapefile.");
}}
Any thoughts why it is not working? MapLayer was loaded from Shapefile.
Regards,David
_________________________________________________________________
Hotmail: Trusted email with powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969------------------------------------------------------------------------------
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users