[udig-devel] new not existing shapefile opened for reading

andrea antonello andrea.antonello at gmail.com
Mon Mar 10 14:23:12 PDT 2008


Hi Jody,
thanks for the help.

On Mon, Mar 10, 2008 at 9:49 PM, Jody Garnett <jgarnett at refractions.net> wrote:
> Hello andrea, lets see if we can help. First of all what version of udig
>  are you using?

I'm on 1.1.x yet and working with the rc14 universal sdk.

> Shapefile got a lot of attention on trunk and we may of
>  introduced a bug...it looks like you are using the createNewDataStore
>  method so you are doing it right. I am available on the IRC channel if
>  needed; and please let me know which version you are using. The
>  tutorials folder has an example of writing a shapefile that you can run
>  if needed.

Yes, when I started to run into problems, I copied and pasted from
those. That is why I'm begging for this in mailinglist, even if I feel
ashamed :)

>  I *have* had some problem with file.toURI() vs file.toURL().toURI()
>  previously - perhaps that is it?

No, I would say no. It deals the path properly, but it wants the file
to exist. In the getReadChannel method it throws an exception if the
file doesn't exist.

I'll jump in the IRC.

Thanks,
Andrea


>  Jody
>
>
>
>  > 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
>  > _______________________________________________
>  > User-friendly Desktop Internet GIS (uDig)
>  > http://udig.refractions.net
>  > http://lists.refractions.net/mailman/listinfo/udig-devel
>  >
>
>  _______________________________________________
>  User-friendly Desktop Internet GIS (uDig)
>  http://udig.refractions.net
>  http://lists.refractions.net/mailman/listinfo/udig-devel
>


More information about the udig-devel mailing list