I'm trying to use geotools (version 2.3.3) to create shapefiles. These
shapefiles contain at least one polygon, along with a set of attributes in
the .dbf file for each polygon. I noticed that when the attributes contain
unusual characters like the degree symbol (°), I got this exception in
geotools:

[14:42:52,830    ERROR    WriteShapeUtil]      Error to write features to
shapefile: 
java.io.IOException: Current fid index is null, next must be called before
remove
    at
org.geotools.data.shapefile.indexed.IndexedFidWriter.write(IndexedFidWriter.java:192)
    at
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore$Writer.write(IndexedShapefileDataStore.java:1766)
    at
org.geotools.data.shapefile.indexed.IndexedShapefileDataStore$Writer.close(IndexedShapefileDataStore.java:1578)
    at
org.geotools.data.TransactionStateDiff.applyDiff(TransactionStateDiff.java:252)
    at
org.geotools.data.TransactionStateDiff.commit(TransactionStateDiff.java:139)
    at
org.geotools.data.DefaultTransaction.commit(DefaultTransaction.java:181)
..........

My code to create shapefiles is as follows:

//attrNames are the attribute names/labels
//attrTypes are the attribute type, and they are all Strings
//the createShapeFile method creates the ShapefileDataStore by setting the
shapefile name, 
// setting the CRS, and creating the schema
ShapefileDataStore  shapeStoreData = createShapeFile( file, geomType,
attrNames, attrTypes, epsgCode );

//pointList is the polygon points
//values are values of the attributes, and the degree symbol is contained in
one of these values
//the createPolygonFeatures method creates a FeatureCollection.
//One of the features in the FeatureCollection contains a value with the
degree symbol in it
FeatureCollection polygonCollection = createPolygonFeatures(
shapeStoreData.getSchema(), pointList,
                                                                                
                        attrNames, values );
FeatureCollection collection = FeatureCollections.newCollection();
collection.addAll( polygonCollection );

writeToShapefile( shapeStoreData, collection );

The writeToShapefile method is copied below:
        public void writeToShapefile( ShapefileDataStore data, FeatureCollection
collection ) throws JShapeException
        {
                String featureName = data.getTypeNames()[0];// there is only 
one in a
shapefile
                DefaultTransaction transaction = null;
                FeatureStore store = null;

                try
                {
                        // 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 );

                }
                catch ( IOException io_e )
                {
                        logger.error( "I/O exception: ", io_e );
                        throw new JShapeException( "I/O exception: " + 
io_e.getMessage() );
                }

                try
                {
                        store.addFeatures( collection );
                        transaction.commit(); //Got an exception at this point
                        transaction.close();
                }
                catch ( ...........

Any help is much appreciated!
-- 
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Problem-with-creating-shapefiles-with-degree-symbol-in-a-feature-tp5746307p5746307.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to