Hi

I do have some problems when trying to export some data from PostGIS into 
Shapefile directory datastore (see code below). After some try and error I 
think it has something to do with the position of the geometry column in 
PostGIS. If the primary key is  the first and the geometry column the second 
one and the parameter "Expose primary keys" is set to false, the export runs 
smoothly. If the geometry column is not the second column it ends with:

Jan 15, 2013 8:41:02 AM java.util.prefs.FileSystemPreferences$7 run
WARNING: Prefs file removed in background 
/home/stefan/.java/.userPrefs/org/geotools/referencing/wkt/prefs.xml
java.io.IOException: Current fid index is null, next must be called before 
write()
        at 
org.geotools.data.shapefile.indexed.IndexedFidWriter.write(IndexedFidWriter.java:252)
        at 
org.geotools.data.shapefile.indexed.IndexedShapefileFeatureWriter.write(IndexedShapefileFeatureWriter.java:101)
        at 
org.geotools.data.shapefile.ShapefileFeatureWriter.close(ShapefileFeatureWriter.java:231)
        at 
org.geotools.data.shapefile.indexed.IndexedShapefileFeatureWriter.close(IndexedShapefileFeatureWriter.java:109)
        at 
org.geotools.data.TransactionStateDiff.applyDiff(TransactionStateDiff.java:277)
        at 
org.geotools.data.TransactionStateDiff.commit(TransactionStateDiff.java:148)
        at 
org.geotools.data.DefaultTransaction.commit(DefaultTransaction.java:183)
        at org.catais.App.main(App.java:93)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to 
com.vividsolutions.jts.geom.Geometry
        at 
org.geotools.data.shapefile.ShapefileFeatureWriter.write(ShapefileFeatureWriter.java:362)
        at 
org.geotools.data.shapefile.indexed.IndexedShapefileFeatureWriter.write(IndexedShapefileFeatureWriter.java:102)
        at 
org.geotools.data.TransactionStateDiff.applyDiff(TransactionStateDiff.java:257)
        ... 3 more

If I expose the primary keys it does not work at all (or at least the geometry 
column should the first column I suppose). Can this be reproduced by someone?

Code:
            Map params= new HashMap();
            params.put("dbtype", "postgis");        
            params.put("host", "localhost");        
            params.put("port", "5432");  
            params.put("database", "rosebud"); 
            params.put("schema", "av_avwmsde_t");
            params.put("user", "geouser01");        
            params.put("passwd", "geouser01"); 
            params.put("Expose primary keys", false);
            params.put(PostgisNGDataStoreFactory.VALIDATECONN, true);
            params.put(PostgisNGDataStoreFactory.MAX_OPEN_PREPARED_STATEMENTS, 
100);
            params.put(PostgisNGDataStoreFactory.LOOSEBBOX, true);
            params.put(PostgisNGDataStoreFactory.PREPARED_STATEMENTS, true);
                            
            DataStore pds = new 
PostgisNGDataStoreFactory().createDataStore(params);
            FeatureSource fs = pds.getFeatureSource("mbsf");
                        
            SimpleFeatureCollection fc = (SimpleFeatureCollection) 
fs.getFeatures();
            SimpleFeature f = (SimpleFeature) fc.toArray()[0];

            // create shapefile
            File file = new File("/home/stefan/tmp/mbsf.shp");            
            params = new HashMap();
            params.put("url", file.toURI().toURL());
            params.put("create spatial index", Boolean.FALSE);            
            
            DirectoryDataStore dds = new DirectoryDataStore(new 
File("/home/stefan/tmp/"), new 
ShapefileDataStoreFactory.ShpFileStoreFactory(new ShapefileDataStoreFactory(), 
params));    
            
            dds.createSchema(fc.getSchema());
            String typeName = dds.getTypeNames()[0];
            SimpleFeatureSource featureSource = dds.getFeatureSource(typeName);
            SimpleFeatureStore featureStore = (SimpleFeatureStore) 
featureSource;
            
            // write data to shapefile
            Transaction t = new DefaultTransaction("addTransaction");
            featureStore.setTransaction(t);
            featureStore.addFeatures(fc);
            t.commit();
            t.close();

Best regards
Stefan

Freundliche Grüsse 
Stefan Ziegler 
Leiter amtliche Vermessung 

Amt für Geoinformation
Amtliche Vermessung 
Rötistrasse 4 
4500 Solothurn 

Telefon +41 32 627 75 96
Telefax +41 32 627 75 98 
stefan.zieg...@bd.so.ch
http://www.so.ch 



------------------------------------------------------------------------------
Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS
and more. Get SQL Server skills now (including 2012) with LearnDevNow -
200+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only - learn more at:
http://p.sf.net/sfu/learnmore_122512
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to