[gdal-dev] JPEG 2000 change geotransform via Python bindinds Gdal 3.2.0

Even Rouault even.rouault at spatialys.com
Wed Nov 25 11:45:40 PST 2020


On mercredi 25 novembre 2020 19:53:38 CET Bucek, Lubomir wrote:
> Dear all,
> I did not want to file the following question as an issue, as I am not sure
> if I am just not missing anything in configuration, so putting it as a
> question here:
> 
> I am trying to change the geotransform of a JPEG2000 file and then save
> back the content via Python bindings on Ubuntu 20.04 - gdal 3.2.0 (based on
> osgeo/gdal:ubuntu-full-latest -
> sha256:6a82b53f12945a3ba8ac168a7488d1cf5ecb351020f67c88abc6691275a70b68)
> 
> Following code:
> ds = gdal.Open(input_filename, gdal.GA_Update)
> ulx, xres, xskew, uly, yskew, yres = ds.GetGeoTransform()
> ... do something with geotransform
> ds.SetGeoTransform(geotransform_new)
> del ds
> Throws me into this exception "USE_SRC_CODESTREAM=YES specified, but no
> codestream found":
> https://github.com/OSGeo/gdal/blob/master/gdal/frmts/openjpeg/openjpegdatase
> t.cpp#L3718-L3722
> 
> How does this creationOption by default being False according to
> https://gdal.org/drivers/raster/jp2openjpeg.html#creation-options come into
> play while opening and saving an already existing file?

When updating in place a file, USE_SRC_CODESTREAM=YES is set internally at
https://github.com/OSGeo/gdal/blob/master/gdal/frmts/openjpeg/
openjpegdataset.cpp#L1457
to cause the generation of a new file, reusing the code stream, but just 
modifying the other JP2 boxes.
I'm not sure why this doesn't work for you. Perhaps something with the 
particular image you edit.

But I doubt this is what you want to do anyway. Updating the geotransform will 
just change the transform and not change any pixel value.
So gdal.Warp() is probably more what you want to do indeed.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list