Hi,

I am trying to create a litle tool to set the projection on shapefiles that
don't have their projection info set.

I know what the projection is and theirfore I don't need to reproject.
I've tried the samples available in the wiki with no success.

Basically I just want to update the existing shapefiles with the appropriate
CRS. I don't really need to create new ones.

Is there a simple way to do this ?


The code below seems to simply copy my shapefiles to a different directory.
Their projection info doesn't seem to have changed ...



                ShapefileDataStore dataStore =  new
ShapefileDataStore(inputFile.toURI().toURL());
                String[] typeNames = dataStore.getTypeNames();
                String typeName = typeNames[0];

                DefaultQuery q = new DefaultQuery();
                q.setCoordinateSystem(originCrs);

                System.out.println("Reading content " + typeName);
                FeatureSource<SimpleFeatureType, SimpleFeature>
featureSource = dataStore.getFeatureSource(typeName);
                SimpleFeatureType simpleFeatureType =
featureSource.getSchema();
                System.out.println("Header: " + DataUtilities.spec(
simpleFeatureType ));


                File resultFile = new File( destFolderPath + children[i]);
                FeatureCollection<SimpleFeatureType, SimpleFeature>
collection = featureSource.getFeatures(q);
                DataStoreFactorySpi factory = new
ShapefileDataStoreFactory();

                Map<String, Serializable> create = new
HashMap<String,Serializable>();
                create.put("url", resultFile.toURI().toURL());
                create.put("create spatial index", Boolean.TRUE);
                DataStore newDataStore = factory.createNewDataStore(create);

                newDataStore.createSchema(collection.getSchema());
                Transaction transaction = new DefaultTransaction();
                FeatureStore<SimpleFeatureType, SimpleFeature> featureStore;
                featureStore = (FeatureStore<SimpleFeatureType,
SimpleFeature>) newDataStore
                        .getFeatureSource(typeName);


                featureStore.setTransaction(transaction);
                try {
                    featureStore.addFeatures(collection);
                    transaction.commit();
                } catch (Exception problem) {
                    problem.printStackTrace();
                    transaction.rollback();
                }
                finally {
                    transaction.close();
                }




Many thanks for your help.
------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to