[gdal-dev] Python gdal.Translate(...) and unicode in Band Descriptions.

Matt.Wilkie at yukon.ca Matt.Wilkie at yukon.ca
Thu Oct 14 13:42:19 PDT 2021


> you could do something along:
>
> tmp_vrt = gdal.Translate("", src_ds, format = 'VRT')
> call SetColorInterpretation() / SetDescription() on tmp_vrt
> gdal.Translate(dstname, tmp_vrt, format = 'COG', ...)


Thanks Even, that works perfectly. It also revealed more depth on my on-again off-again troubles: In my final write I was feeding the input vsi image to Translate instead of the gdal dataset object I had applied the changes to. So:

	gdal.Translate(outdata, VSIPATH, ...)

instead of:

	gdal.Translate(outdata, DATAOBJ, ...)

The fixed and working script is attached.

-Matt


-----Original Message-----
From: Even Rouault <even.rouault at spatialys.com> 
Sent: October 14, 2021 12:11 PM
To: Matt.Wilkie <Matt.Wilkie at yukon.ca>; gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] Python gdal.Translate(...) and unicode in Band Descriptions.

<strong>*** External email: Do not click on links or attachments except from trusted senders. *** ******************************************************************************************</strong>
<br>
<br>
you could do something along:

tmp_vrt = gdal.Translate("", src_ds, format = 'VRT')

call SetColorInterpretation() / SetDescription() on tmp_vrt

gdal.Translate(dstname, tmp_vrt, format = 'COG', ...)


Le 14/10/2021 à 20:45, Matt.Wilkie at yukon.ca a écrit :
>> For Problem 2 there’s a new wrinkle: in spite of the warning about 
>> being unable to save the .aux.xml info into the source zip sometimes 
>> it actually does. I haven’t sorted out when it can and can’t yet.
> Solved it: the first time the script is run it saves the Color Interp and Descriptions in the .aux.xml within the zip, and the output image remains Undefined for these fields. In subsequent runs saving the aux fails, and the output image fields for Color Interp and Description are filled out. As I've been using the same input archive repeatedly while testing this sequence was being masked.
>
> So now I'm at the crux I think: how to tell gdal.Translate() to use these metadata without applying them to `data_in.GetRasterBand(1)` and saving first?
>
> Is there a more efficient method than:
>
> ~~~
> data_in = gdal.Open(vsipath)
> gdal.Translate(dstname, vsipath, width=w, height=h, ...)
>
> data_out = gdal.Open(dstname)
>      data_out.GetRasterBand(1).SetColorInterpretation(gdal.GCI_RedBand)
>      data_out.GetRasterBand(1).SetDescription("Red (0.625 - 0.695 microns)")
>      ...
>
> data_in = None
> data_out = None
> ~~~
>
>
> Matt
> Geomatics Developer and Administrator | Environment | T 867-667-8133 | 
> Yukon.ca
> Hours: 08:30-16:30, Mon-Wed: Office, Thu: Remote, Fri: Away.
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev

--
https://imsva91-ctp.trendmicro.com:443/wis/clicktime/v1/query?url=http%3a%2f%2fwww.spatialys.com&umid=7AF69E2A-CE54-D505-9E07-D6028B22F810&auth=c132af8ee7c9d1278d61a701569070a095ce962e-3d324fe99905db1c25d2b023d6680d9f015cf9ec
My software is free, but my time generally not.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SPOT-zip-to-preview.zip
Type: application/x-zip-compressed
Size: 2401 bytes
Desc: SPOT-zip-to-preview.zip
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20211014/076d36f2/attachment.bin>


More information about the gdal-dev mailing list