Thanks, I change the prj file, the way ESRI wants it, when the export is done. 
Ihave 5 hard coded prj configurations for the 5 projections I use, in the java 
program.

10 juli 2019 kl. 11:51 skrev Ian Turton 
<ijtur...@gmail.com<mailto:ijtur...@gmail.com>>:

You can use something like (from 
https://docs.geotools.org/stable/userguide/library/referencing/crs.html#matching-a-coordinatereferencesystem):


CoordinateReferenceSystem crs = CRS.decode("EPSG:32735");
        Formattable f = (Formattable) CRS.decode("EPSG:32735", true);
        String wkt = f.toWKT(Citations.ESRI, 2); // use 0 indent for single line

        System.out.println("wkt for EPSG:32735 (ESRI)");
        System.out.println(wkt);

To produce a more ESRI friendly WKT in your .prj file. I thought there was a 
flag you could pass to the ShapefileWriter to set that up but I can't see it on 
a quick look.

Alternatively, you could open a bug report with ESRI asking them to support the 
standard better.

Ian

On Wed, 10 Jul 2019 at 10:38, <paul.m...@lfv.se<mailto:paul.m...@lfv.se>> wrote:
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<mailto:GeoTools-GT2-Users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


--
Ian Turton


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

Reply via email to