shapefile writer precision

2 messages Options
Embed this post
Permalink
pjackson

shapefile writer precision

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

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;

      }

 



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4429 (20090916) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
aaime

Re: shapefile writer precision

Reply Threaded More More options
Print post
Permalink
Patrick Jackson ha scritto:

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

There is no way that I know of to control the precision of the
coordinates written out.
As far as I know they are just written with all the decimals that
we have available, there is no rounding that I'm aware of in the
writer.

The class actually reading and writing polygons is here:
http://svn.osgeo.org/geotools/trunk/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/PolygonHandler.java

If you have a self contained example showing a precision reduction
I can investigate.

Cheers
Andrea


--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users