Hi,
when I export a Postgis table to a shape file and the try to import it into Arc 
Gis, I will always have to reproject the file from eg Wgs84(4326) to 
Wgs84(4326) at the import stage. It seems that Arc Gis  don't understand that 
the prj file describes the wgs84 projection, but funny enough ArcGis 
understands it when it should project the file! ArcGis prj file is not the same 
as my prj file, but the result of the description in the prj files is the same.
The result when importing the wgs84 shape file is still correct when it is 
imported and projected to wgs84.

It is really annoying to have to reproject to the same projection when 
importing to ArcGis.
Is there anyone who has an solution for this?
I'm using the following example code:
private void exportLayer(String layerName, File directory) throws IOException {
            SimpleFeatureSource featureSource = 
MainDialog.getDataStore().getFeatureSource(layerName);
            SimpleFeatureType ft = featureSource.getSchema();
            String fileName = ft.getTypeName();
            File file = new File(directory, fileName + ".shp");
            Map<String, java.io.Serializable> creationParams = new HashMap<>();
            creationParams.put("url", URLs.fileToUrl(file));
            FileDataStoreFactorySpi factory = 
FileDataStoreFinder.getDataStoreFactory("shp");
            DataStore dataStore = factory.createNewDataStore(creationParams);
            dataStore.createSchema(ft);
            // The following workaround to write out the prj is no longer needed
            // 
((ShapefileDataStore)dataStore).forceSchemaCRS(ft.getCoordinateReferenceSystem());

            SimpleFeatureStore featureStore = (SimpleFeatureStore) 
dataStore.getFeatureSource(layerName);

            Transaction t = new DefaultTransaction();
            try {
                         SimpleFeatureCollection collection = 
featureSource.getFeatures(); // grab all features
                         featureStore.addFeatures(collection);
                         t.commit(); // write it out
            } catch (IOException eek) {
                         JOptionPane.showMessageDialog(null, eek.toString());
                         eek.printStackTrace();
                         try {
                                     t.rollback();
                         } catch (IOException doubleEeek) {
                                     // rollback failed?
                         }
            } finally {
                         t.close();
            }
            MainDialog.removeDataStore();
}


Kind regars,
Paul

_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to