[udig-devel] new not existing shapefile opened for reading
andrea antonello
andrea.antonello at gmail.com
Mon Mar 10 13:32:56 PDT 2008
I think I'm gone mad, since I am no more able to write a shapefile...
Following Jody's/Jesse's tutorials about writing shapefiles from
featurecollections properly, things that used to work in the past do
not work for me any longer.
The problem seems to be that it always tries to open the file as a
reading channel, supposing that it exists already.
java.io.FileNotFoundException: /home/moovida/TMP/brenta_net.shp
at org.geotools.data.shapefile.ShapefileDataStore.getReadChannel(ShapefileDataStore.java:293)
at org.geotools.data.shapefile.ShapefileDataStore.openShapeReader(ShapefileDataStore.java:448)
at org.geotools.data.shapefile.ShapefileDataStore.readAttributes(ShapefileDataStore.java:659)
at org.geotools.data.shapefile.ShapefileDataStore.getSchema(ShapefileDataStore.java:615)
at org.geotools.data.AbstractFileDataStore.getFeatureSource(AbstractFileDataStore.java:70)
Am I missing some change in the api?
Shouldn't it be something like:
// Create the DataStoreFactory
ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
// Create the file you want to write to
File file = null;
if (shapeFilePath.toLowerCase().endsWith(".shp")) {
file = new File(shapeFilePath);
} else {
file = new File(shapeFilePath + ".shp");
}
// Create a Map object used by our DataStore Factory
// NOTE: file.toURI().toURL() is used because file.toURL()
is deprecated
Map<String, URL> map = Collections.singletonMap("url",
file.toURI().toURL());
// Create the ShapefileDataStore from our factory based on
our Map object
ShapefileDataStore dStore = (ShapefileDataStore)
factory.createNewDataStore(map);
dStore.createSchema(fet.getSchema());
dStore.forceSchemaCRS(crs);
[...]
String featureName = dStore.getTypeNames()[0];
DefaultTransaction transaction = null;
FeatureStore store = null;
// Create the DefaultTransaction Object
transaction = new DefaultTransaction();
// Tell it the name of the shapefile it should look for in
our DataStore
store = (FeatureStore) data.getFeatureSource(featureName);
// Then set the transaction for that FeatureStore
store.setTransaction(transaction);
store.addFeatures(collection);
transaction.commit();
transaction.close();
return true;
???????
Thanks for any help,
Andrea
More information about the udig-devel
mailing list