[Gdal-dev] Providing supplemental information to GDALOpen()

Frank Warmerdam warmerdam at pobox.com
Fri Jul 27 15:25:08 EDT 2007


Robert Banfield wrote:
> Hello,
> 
> Suppose I have a .jpg file with no corresponding .jgw file, but I know 
> all of the transform values.  Is it possible through the API to provide 
> supplemental information after GDALOpen() opens this file?
> 
> double Transform[6] = ...  // Provide what would have been provided in 
> the .jgw file
> GDALDatasetH hSrcDS = GDALOpen (MyFile, GA_ReadOnly);  // No .jgw file 
> on disk
> GDALSetGeoTransform(hSrcDS,Transform);  // I tried this with no success
> 
> When I use GDALSetGeoTransform in this fashion I obtain the following:  
> CPL Failure 6: SetGeoTransform() not supported for this dataset.  When I 
> use GDALOpen(MyFile, GA_Update), I am seg faulting... I haven't yet 
> looked at what the cause of that may be...
> 
> My goal is simply to "pretend" the world file was already on disk, so 
> that later code to generate new data files is correct.

Robert,

I'm not sure why GDALOpen() is crashing when you pass GA_Update.  That
definately should not happen.  For JPEG files it should just issue an
error message (about not supporting update access to jpeg files) and
return NULL.

You can't directly do what you want, but an indirect approach is to
create VRT dataset in memory referring to the JPEG file, and then
modify that VRT dataset.  Something like (untested/uncompiled):

   GDALDriverH hVRTDriver;
   GDALDatasetH hJpegDS, hVrtDS;

   hJpegDS = GDALOpen( "your.jpg", GA_ReadOnly );

   hVRTDriver = GDALGetDriverByName( "VRT" );
   hVrtDS = GDALCreateCopy( hVRTDriver, "", hJpegDS, FALSE, NULL,
                            NULL, NULL );

   GDALSetGeoTransform( hVrtDS, Transform );

   ...

The updates should be reflected on hVrtDS, and hVrtDS can be passed
as a proxy for the jpeg file to other code.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org




More information about the Gdal-dev mailing list