Hi,

I'm new to the "geotools-world" and so far i really like it!
I'm kinda stuck on one thing though and would really appreciate your
help/hints.

Ok... i got a little mapviewer and on right-clicking on for example a
polygon, i display
the attribute table just for the 'clicked-on' polygon. that all works fine.
now... what do i 
have to do if i want to change an attribute value of a shapefile? what i'm
trying to do is,
enter a new value in the displayed table and then write it to the shapefile.
i tried using 
store.modifyFeatures() and a transaction, see the following code....


public void changeAttributeData(FeatureSource source,  Feature f,  String
attName, String newValue) throws IOException {
        FeatureStore store = (FeatureStore) source;
        
        DefaultTransaction transaction = new DefaultTransaction("test1");
        store.setTransaction(transaction);

        FeatureType featureType = store.getSchema();
        AttributeType attributeType = featureType.getAttributeType(attName);
                
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(
GeoTools.getDefaultHints() );
        Filter filter = ff.id( Collections.singleton( ff.featureId(f.getID())));
        
        try {
           store.modifyFeatures( attributeType, newValue, filter );
           transaction.commit();
           transaction.close();
        } catch(Exception e){
           transaction.rollback();
           transaction.close();
           e.printStackTrace();
        }
}


... what am i doing wrong here... as i always get an IOException saying:



java.io.IOException: Unable to delete original file:
file:/C:/shapefiles/testShapefile.shp
        at
org.geotools.data.shapefile.ShapefileDataStore.copyAndDelete(ShapefileDataStore.java:1187)
        at
org.geotools.data.shapefile.ShapefileDataStore$Writer.clean(ShapefileDataStore.java:1460)
        at
org.geotools.data.shapefile.ShapefileDataStore$Writer.close(ShapefileDataStore.java:1526)
        at
org.geotools.data.InProcessLockingManager$1.close(InProcessLockingManager.java:343)
        at
org.geotools.data.FilteringFeatureWriter.close(FilteringFeatureWriter.java:148)
        at
org.geotools.data.AbstractFeatureStore.modifyFeatures(AbstractFeatureStore.java:146)
        at
org.geotools.data.AbstractFeatureStore.modifyFeatures(AbstractFeatureStore.java:85)
        at shp.ShpData.changeAttributeData(ShpData.java:90)   
        ...
        thats thrown by the store.modifyFeatures(...) call

it seems like there is a lock on the shapefile or something? or maybe im
totaly on the wrong way in how to change the data? i would really appreciate
your help guys. 

thanks
anna
-- 
View this message in context: 
http://www.nabble.com/changing-attribute-values-tf4787814.html#a13696893
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to