|
From: johann S. <sor...@in...> - 2007-11-27 18:28:30
|
hello again,
I'm beginning a map2d on wich we should be able to edit geometries. I =
started with adding point geometry on a shape and it stuck at the second =
add.
A .fix file is created and blocks the new add, it keeps saying =
=22transaction not close=22... but i'm sure it is close.
the code i use :
private void createPoint(int mx, int my) =7B
if (mapArea =21=3D null && editionLayer =21=3D null) =7B
=20
//stuff to build the geometry
Rectangle bounds =3D getBounds();
double width =3D mapArea.getWidth();
double height =3D mapArea.getHeight();
Coordinate coord =3D toMapCoord(mx, my, width, height, bounds);
Geometry geometry =3D gf.createPoint(coord);
SimpleFeatureType featureType =3D =
editionLayer.getFeatureSource().getSchema();
FeatureCollection collection =3D =
FeatureCollections.newCollection();
Object=5B=5D values =3D new =
Object=5BfeatureType.getAttributeCount()=5D;
=20
AttributeDescriptor geomAttribut =3D =
featureType.getDefaultGeometry();
=20
List<AttributeDescriptor> lst =3D featureType.getAttributes();
for (int i=3D0, n=3Dlst.size(); i<n; i++) =7B
AttributeDescriptor desc =3D lst.get(i);
=20
if(desc.equals(geomAttribut))=7B
values=5Bi=5D =3D geometry;
=7Delse=7B
values=5Bi=5D =3D desc.getDefaultValue();
=7D
=7D
//featureType.
SimpleFeature sf =3D SimpleFeatureBuilder.build(featureType, =
values, null);
collection.add(sf);
//commit in shape
DataStore data =3D =
editionLayer.getFeatureSource().getDataStore();
DefaultTransaction transaction =3D null;
FeatureStore store =3D null;
try =7B
String featureName =3D data.getTypeNames()=5B0=5D; // =
there is only one in a shapefile
// Create the DefaultTransaction Object
transaction =3D new DefaultTransaction();
// Tell it the name of the shapefile it should look for in =
our DataStore
store =3D (FeatureStore) data.getFeatureSource(featureName);
=20
// Then set the transaction for that FeatureStore
store.setTransaction(transaction);
store.addFeatures(collection);
store.getTransaction().commit();
store.getTransaction().close();
=7D catch (Exception eek) =7B
eek.printStackTrace();
try =7B
store.getTransaction().rollback();
=7D catch (IOException e) =7B
e.printStackTrace();
=7D
=7D
=20
=7D
=7D
the error :
java.io.IOException: Unable to delete original file: =
file:/H:/DEV/GEOTOOLS/modules/unsupported/widgets-swing-pending/target/clas=
ses/org/geotools/gui/swing/demo/shape/test_point.fix
at =
org.geotools.data.shapefile.ShapefileDataStore.copyAndDelete(ShapefileDataS=
tore.java:1178)
at =
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore.access=242000=
(IndexedShapefileDataStore.java:112)
at =
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore=24Writer.clea=
n(IndexedShapefileDataStore.java:1538)
at =
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore=24Writer.clos=
e(IndexedShapefileDataStore.java:1606)
at =
org.geotools.data.TransactionStateDiff.applyDiff(TransactionStateDiff.java:=
264)
at =
org.geotools.data.TransactionStateDiff.commit(TransactionStateDiff.java:149)
at =
org.geotools.data.DefaultTransaction.commit(DefaultTransaction.java:181)
at =
org.geotools.gui.swing.map.map2d.DefaultEditableMap2D.createPoint(DefaultEd=
itableMap2D.java:254)
second error :
GRAVE: There's code leaving transaction unclosed. Call Transaction.close() =
after using them to ensure they do not hold state such as JDCB connections =
or file handles
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop=21
Check it out at http://www.inbox.com/earth
|