[geotk] Writing Shapefile Example

Torey Alford talford at usgs.gov
Wed Jul 25 14:06:20 PDT 2012


I'm trying to create a shapefile with geotoolkit, and I keep getting 
weird issues w/it trying to open a Reader when I clearly need a writer:


---------code snippit--------------
ShapefileDataStore store = new ShapefileDataStore(file.toURI().toURL());
SimpleFeatureType featureType = createFeatureType();
final Session session = store.createSession(true);
FeatureCollection collection = session
     .getFeatureCollection(QueryBuilder.all(featureType.getName()));

for (Result result : list) {
     Feature feature = FeatureUtilities.defaultFeature(featureType, "");
     ...
     collection.add(feature);
}
session.commit();

-----end code snippit--------------

Exceptions:

         at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
         at 
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
         at 
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
*Caused by: org.geotoolkit.storage.DataStoreException: Error creating 
ShapefileReader*
         at 
org.geotoolkit.data.shapefile.ShapefileDataStore.openShapeReader(ShapefileDataStore.java:747)
         at 
org.geotoolkit.data.shapefile.ShapefileDataStore.readAttributes(ShapefileDataStore.java:613)
         at 
org.geotoolkit.data.shapefile.ShapefileDataStore.buildSchema(ShapefileDataStore.java:572)
         at 
org.geotoolkit.data.shapefile.ShapefileDataStore.checkTypeExist(ShapefileDataStore.java:205)
         at 
org.geotoolkit.data.shapefile.ShapefileDataStore.getName(ShapefileDataStore.java:192)
         at 
org.geotoolkit.data.shapefile.ShapefileDataStore.getNames(ShapefileDataStore.java:214)
         at 
org.geotoolkit.data.AbstractDataStore.typeCheck(AbstractDataStore.java:413)
         at 
org.geotoolkit.data.shapefile.ShapefileDataStore.getFeatureType(ShapefileDataStore.java:222)
         at 
org.geotoolkit.data.session.DefaultSession.addFeatures(DefaultSession.java:141)
         at 
org.geotoolkit.data.DefaultSelectorFeatureCollection.addAll(DefaultSelectorFeatureCollection.java:168)
         ... 59 more
*Caused by: java.io.EOFException: Premature end of header*
         at 
org.geotoolkit.data.shapefile.shp.ShapefileReader.readHeader(ShapefileReader.java:239)
         at 
org.geotoolkit.data.shapefile.shp.ShapefileReader.<init>(ShapefileReader.java:168)
         at 
org.geotoolkit.data.shapefile.ShapefileDataStore.openShapeReader(ShapefileDataStore.java:745)
         ... 68 more
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geotoolkit/attachments/20120725/fb605255/attachment-0001.html>


More information about the Geotoolkit mailing list