Hello list,

I've tried a simple application that just reads a shapefile (with WGS84 
projection) and writes it to a PostGIS data store. The result in PostGIS 
comes out fine, but unfortunately the projection info is lost (column 
entry 'srid' ends up as '-1' in table 'geometry_columns'). Thus, when 
reading the data back from PostGIS I get a null 
CoordinateReferenceSystem (and yes, I have cheched that the original 
FeatureSource does come with a valid CRS)

Am I missing something? Is this a confusion between EPSG codes from 
epsg-hsql (which is what I'm using) and the internal PostGIS codes? Is 
there anything I can do about it?

Not sure if it helps, but here goes the simple code I'm using to do this:

     // source DataStore
     URL shapeUrlSrc = new URL("file:///D:/myshape.shp");
     Map<Object,Object> connect = new HashMap<Object,Object>();
     connect.put("url", shapeUrlSrc);
     DataStore dataStoreSrc = DataStoreFinder.getDataStore(connect);

     // destination DataStore
     Map<Object,Object> pgConnect = new HashMap<Object,Object>();
     pgConnect.put("dbtype", "postgis");
     pgConnect.put("host", "pgservername");
     pgConnect.put("port", new Integer(5432));
     pgConnect.put("database", "geotools_test");
     pgConnect.put("user", "postgres");
     pgConnect.put("passwd", "<passwd>");
     DataStore dataStoreDest = DataStoreFinder.getDataStore(pgConnect);

     // copies data from source to destination
     String[] typeNames = dataStoreSrc.getTypeNames();
     for (String typeName : typeNames)
     {
         // gets FeatureSource from source DataStore
         FeatureSource<SimpleFeatureType,SimpleFeature> featSource =
                  dataStoreSrc.getFeatureSource(typeName);

         // gets FeatureSource collection from source DataStore
         FeatureCollection<SimpleFeatureType,SimpleFeature>
                  featSrcCollection = featSource.getFeatures();

         // creates equivalent schema in destination DataStore
         SimpleFeatureType schema = dataStoreSrc.getSchema(typeName);
         dataStoreDest.createSchema(schema);

         // retrieves destination FeatureStore
         FeatureStore<SimpleFeatureType,SimpleFeature> featStore =
                  (FeatureStore<SimpleFeatureType,SimpleFeature>)
                  dataStoreDest.getFeatureSource(typeName);

         // copies FeatureCollection to destination
         featStore.addFeatures(featSrcCollection);
     }
     System.out.println( "DONE" );

---

Thanks a lot!
Milton



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to