David Abdurachmanov ha scritto:
> 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:
You are leaving the feature store with the same transaction you
have closed. From there on it won't be possible to do anything
with it because of that.
Suggestion -> create a separate feature store if you want to play
with transactions
Cheers
Andrea
> Collection size (layer): 228
> 2010-04-29 22.26.34 org.geotools.data.shapefile.ShapefileDataStore
> createSchema
> WARNING: PRJ file not generated for null CoordinateReferenceSystem
> Collection size: 228
> 2010-04-29 22.26.35 org.geotools.renderer.lite.StreamingRenderer paint
> SEVERE: Transaction has been closed
> java.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. Sign up now.
> <https://signup.live.com/signup.aspx?id=60969>
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.
------------------------------------------------------------------------------
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users