I need to check/set the precision on geometries written to shapefile, and am
having trouble locating information about this in the code or documentation.


 

What prompts this is that I'm writing MultiPolygon geometries (geographic
crs) that are physically fairly small, so I need to get precision on
coordinates out to several decimal places.  While the geometries in the
features are showing double precision (out to many decimal places) before
being written to shapefile, when I open the output shapefile in ArcMap, they
seem to have only 2-decimal precision.

 

I'm just using the default method of writing shapefiles used by example in
the online userguide (see appended source).

 

Can anyone point me in the right direction?

 

Thanks,

Patrick

 

 

public ShapefileDataStore exportToShapefile( FeatureCollection collection,
File directory ) throws IOException {

            SimpleFeatureType ft = (SimpleFeatureType)
collection.getSchema();

            String ftName = ft.getName().toString();

            CoordinateReferenceSystem crs =
ft.getCoordinateReferenceSystem();

            ftName = ftName.substring( ftName.lastIndexOf("/")+4 );

 

            File file = new File( directory, ftName+".shp" );

         

            Map<String, Serializable> params = new HashMap<String,
Serializable>();

            params.put("url", file.toURI().toURL() );

      

            FileDataStoreFactorySpi factory = new
IndexedShapefileDataStoreFactory();

            ShapefileDataStore dataStore = (ShapefileDataStore)
factory.createNewDataStore(params);

            dataStore.createSchema(ft);

            dataStore.forceSchemaCRS( crs );

            

            FeatureStore featureStore = (FeatureStore)
dataStore.getFeatureSource( ftName );

      

            Transaction t = new DefaultTransaction();

            try {

                  featureStore.addFeatures( collection );

                  t.commit(); // write it out

            }

            catch( IOException e){

                  e.printStackTrace();

                  try {

                        t.rollback();

                  }

                  catch( IOException e2 ){

                        e.printStackTrace();

                  }

            }

            finally {

                  t.close();

            }

            return dataStore;

      }

 

------------------------------------------------------------------------------
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