ShapefileDataStore not working with extension less files
--------------------------------------------------------

                 Key: GEOT-1717
                 URL: http://jira.codehaus.org/browse/GEOT-1717
             Project: GeoTools
          Issue Type: Bug
          Components: data shapefile
    Affects Versions: 2.4.0
         Environment: Sun OS, JAVA 6
            Reporter: Enamul Haque
            Assignee: Jesse Eichar


ShapefileDataStore's createSchema() method fails if the filename provided does 
not end in .shp, .shx, .dbf. For example the following piece of code will not 
work with geotools 2.4.x, 

ShapefileDataStore ds = new ShapefileDataStore(new File("a").toURI().toURL());
ds.createSchema(someSchema);


In geotools 2.3.x, file extension would be appended to the file name if no 
[known] extension is found. In geotools 2.4.x, however, file names are 
determined in the following way:

shpURL = ShapefileDataStoreFactory.toShpURL(url);
       dbfURL = ShapefileDataStoreFactory.toDbfURL(url);
       shxURL = ShapefileDataStoreFactory.toShxURL(url);
       prjURL = ShapefileDataStoreFactory.toPrjURL(url);
       xmlURL = ShapefileDataStoreFactory.toXmlURL(url);

If url points to a file with no extension, then shpURL, dbfURL, .... would be 
the same. When you call createSchema() of ShapefileDataStore:

           FileChannel shpChannel = (FileChannel)
getWriteChannel(getStorageURL(
                       shpURL, temp));
           FileChannel shxChannel = (FileChannel)
getWriteChannel(getStorageURL(
                       shxURL, temp));

In getWriteChannel():

((FileChannel) channel).lock();

Therefore, you lock the same file twice since shpURL == shxURL and hence the 
following exception:

java.nio.channels.OverlappingFileLockException
       at 
sun.nio.ch.FileChannelImpl$SharedFileLockTable.checkList(FileChannelImpl.java:1173)
       at 
sun.nio.ch.FileChannelImpl$SharedFileLockTable.add(FileChannelImpl.java:1075)
       at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:837)
       at java.nio.channels.FileChannel.lock(FileChannel.java:860)
       at 
org.geotools.data.shapefile.ShapefileDataStore.getWriteChannel(ShapefileDataStore.java:359)
       at 
org.geotools.data.shapefile.ShapefileDataStore.createSchema(ShapefileDataStore.java:814)

Solution would be to modify the methods: ShapefileDataStoreFactory.toShpURL(), 
toDbfURL(), toShxURL(), toPrjURL() in the following way (shown only for shx 
files; this should be done for all the 4 methods) :

public static URL toShxURL( URL url ) throws java.net.MalformedURLException {
        String filename = toFilename(url);
        if (filename.endsWith(".shp") || filename.endsWith(".dbf")
                || filename.endsWith(".shx")) {
            filename = filename.substring(0, filename.length() - 4);
            filename += ".shx";
        } else if (filename.endsWith(".SHP") || filename.endsWith(".DBF")
                || filename.endsWith(".SHX")) {
            filename = filename.substring(0, filename.length() - 4);
            filename += ".SHX";            
        } else {          /////////////////////////////////// ADD THIS
            filename += ".shx";     /////////////// Just append the correct 
extension if the filename doesn't end in any of the shapefile extensions        
  
        }
        return new URL(filename);
    }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to