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 "transaction not
close"... but i'm sure it is close.
the code i use :
private void createPoint(int mx, int my) {
if (mapArea != null && editionLayer != null) {
//stuff to build the geometry
Rectangle bounds = getBounds();
double width = mapArea.getWidth();
double height = mapArea.getHeight();
Coordinate coord = toMapCoord(mx, my, width, height, bounds);
Geometry geometry = gf.createPoint(coord);
SimpleFeatureType featureType =
editionLayer.getFeatureSource().getSchema();
FeatureCollection collection = FeatureCollections.newCollection();
Object[] values = new Object[featureType.getAttributeCount()];
AttributeDescriptor geomAttribut = featureType.getDefaultGeometry();
List<AttributeDescriptor> lst = featureType.getAttributes();
for (int i=0, n=lst.size(); i<n; i++) {
AttributeDescriptor desc = lst.get(i);
if(desc.equals(geomAttribut)){
values[i] = geometry;
}else{
values[i] = desc.getDefaultValue();
}
}
//featureType.
SimpleFeature sf = SimpleFeatureBuilder.build(featureType, values,
null);
collection.add(sf);
//commit in shape
DataStore data = editionLayer.getFeatureSource().getDataStore();
DefaultTransaction transaction = null;
FeatureStore store = null;
try {
String featureName = data.getTypeNames()[0]; // there is only
one in a shapefile
// Create the DefaultTransaction Object
transaction = new DefaultTransaction();
// Tell it the name of the shapefile it should look for in our
DataStore
store = (FeatureStore) data.getFeatureSource(featureName);
// Then set the transaction for that FeatureStore
store.setTransaction(transaction);
store.addFeatures(collection);
store.getTransaction().commit();
store.getTransaction().close();
} catch (Exception eek) {
eek.printStackTrace();
try {
store.getTransaction().rollback();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
the error :
java.io.IOException: Unable to delete original file:
file:/H:/DEV/GEOTOOLS/modules/unsupported/widgets-swing-pending/target/classes/org/geotools/gui/swing/demo/shape/test_point.fix
at
org.geotools.data.shapefile.ShapefileDataStore.copyAndDelete(ShapefileDataStore.java:1178)
at
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore.access$2000(IndexedShapefileDataStore.java:112)
at
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore$Writer.clean(IndexedShapefileDataStore.java:1538)
at
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore$Writer.close(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(DefaultEditableMap2D.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!
Check it out at http://www.inbox.com/earth
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel