[Gdal-dev] Strange error during Driver.Create(String filename,...)
Daniele Romagnoli
dany.geotools at gmail.com
Tue Jan 9 11:13:46 EST 2007
Hi list,
In the context of the GDAL ImageIO integration proposal I'm actually
building the framework which will add writing capabilities to the project.
Today I'm fighting against a strange error with Driver.Create (...) method.
>From a stand-alone testCase (I'm using Junit) the following code works
successfully:
------------------------------------------------------------------------------------------------
final File outputFile = new File
("d:\\DatiPlugin\\samples\\writingAttempt.jp2");
final BufferedImage im = ImageIO.read(new
File("D:\\DatiPlugin\\bogota.tif"));
Driver driver = gdal.GetDriverByName("JP2ECW");
final int width = im.getWidth();
final int height = im.getHeight();
Dataset ds = driver.Create (outFile.getAbsolutePath(), width, height, 1,
gdalconstConstants.GDT_Byte,null);
... some code ...
ds.GetRasterBand(1).WriteRaster_Direct(0,0,width,height,width,height,
gdalconstConstants.GDT_Byte,myByteBuffer);
ds.FlushCache();
ds.delete();
------------------------------------------------------------------------------------------------
However, using the SAME code within the body of the "write" method of the
MyJP2KImageWriter class (which extends ImageWriter), it does not work.
(Such a method will be called during an ImageWrite operation performed using
JAI-ImageIO toolkit).
I noticed that the code only works if I chose a filename with a path
containing no subdirectory... As an instance, using "D:\\sample.jp2" instead
of "D:\\DatiPlugin\\samples\\sample.jp2".
(Out of curiosity, I tried using a BMP driver and the problem still exist)
After a deep debug, I finally noticed that the problem could be attributable
to the GDAL methods:
FILE *VSIFOpenL( const char * pszFilename, const char * pszAccess ) [from
cpl_vsil.cpp]
which calls
VSIVirtualHandle *VSIWin32FilesystemHandler::Open( const char *pszFilename,
const char *pszAccess ) [from cpl_vsil_win32.cpp]
containing the code
hFile = CreateFile( pszFilename, dwDesiredAccess, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL
);
which makes hFile equal to INVALID_HANDLE_VALUE (By this reason, the Open
method returns NULL).
Could someone provide me some suggestions?
Thanks a lot.
Best Regards,
Daniele
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20070109/803746d8/attachment.html
More information about the Gdal-dev
mailing list