Janne Nivala wrote:
I'm trying to use a WFS layer as a template to create a shapefile with
no features, and add that file as a map layer.
Okay that makes sense...
That shapefile would later be used for storing features from the very
same WFS source.
Please be aware that shapefile is not as "capable" as WFS (you can only
have one Geometry and it *must* be the first attribute in the Feature,
string length is limited to 256 characters; and so on ....).
The problem I'm facing is that the shapefile is only created on disk
when adding features, not when doing createSchema() to the associated
DataStore.
Interesting observation; not something I had thought of. Is there any
way to create an empty shapefile?
I've tried the following. In this example, layer is a WFS layer, of
type ILayer.
FileDataStoreFactorySpi factory = new
IndexedShapefileDataStoreFactory();
File file = new File("c:/test.shp");
HashMap<String, URL> map = new HashMap<String, URL>();
map.put(IndexedShapefileDataStoreFactory.URLP.key, file.toURL());
DataStore myData = factory.createNewDataStore(map);
FeatureSource featureSource =
layer.getResource(FeatureSource.class,
monitor);
FeatureType ft = featureSource.getSchema();
myData.createSchema(ft);
FeatureStore store = (FeatureStore) ((ShapefileDataStore) myData)
.getFeatureSource(); /* Return to caller, used later */
After this, when I start adding features to store, then the shapefile
gets created.
When you added your Features were you using a Transaction? Or were you
using Transaction.AUTO_COMMIT? The preferred thing to do would be to use
a transaction; the featues would be held in memory; and then when
transaction.commit() is called your shapefile would be created.
That is contrary to what happens with the example at "Creating a new
Shapefile" at
http://docs.codehaus.org/display/GEOTDOC/Shapefile+Plugin , where
after executing myData.createSchema( featureType ), SHP appears.
In uDig we do our best to hold a single transaction open for each Map;
when the user hits the "Commit" button the results will be committed; it
looks like you are using a DataStoreFactory directly so that cannot be it...
I am going to guess that you have found a bug in shapefile datastore;
when commit() is called and the "Transaction State Diff" is empty it
probably is not doing anything; we need to have it check to see if the
file exists at all and write the thing out anyways (even if it looks
like the thing is empty and unchanged).
Is it the WFS featuresource that makes a difference here? Or am I
overlooking something?
I think you are just the first person to try generating an empty shapefile.
Jody
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel