[gdal-dev] clear band level metadata
Michael Sumner
mdsumner at gmail.com
Wed May 29 23:12:37 PDT 2024
Hello, I have this process to convert a URL to a MEM dataset.
It's not the target data but it's representative, a netcdf with band-level
and dataset-level metadata. We can clear the dataset level with
COPY_SRC_MDD, but I can't see how to do that for the band level. We're
hoping to keep this without generating files, the final step uses VSI to
read into a byte array.
Can I clear the band metadata without an intermediate dataset? Opening in
update mode breaks the COG layout (or is that ok to do this with
IGNORE_COG_LAYOUT_BREAK=YES ?).
from osgeo import gdal
gdal.UseExceptions()
dsn = "vrt:///vsicurl/
https://www.ncei.noaa.gov/data/sea-surface-temperature-optimum-interpolation/v2.1/access/avhrr/202405/oisst-avhrr-v02r01.20240511.nc?sd_name=sst
"
opts = gdal.TranslateOptions(format = "COG",
creationOptions = [ "COMPRESS=ZSTD", "PREDICTOR=STANDARD",
"RESAMPLING=AVERAGE",
"SPARSE_OK=YES", "COPY_SRC_MDD=NO"])
ds = gdal.Open(dsn)
tmp = "/vsimem/tmp1.tif"
## here we lose the dataset-level metadata as desired with COPY_SRC_MDD
gdal.Translate(tmp, ds, options = opts)
## but the band metadata is still there
lds = gdal.Open(tmp)
#{'add_offset': '0', 'long_name': 'Daily sea surface temperature',
'NETCDF_DIM_time': '16932', 'NETCDF_DIM_zlev': '0', 'NETCDF_VARNAME':
'sst', 'scale_factor': '0.0099999998', 'units': 'Celsius', 'valid_max':
'4500', 'valid_min': '-300', '_FillValue': '-999'}
lds.Close()
ds.Close()
I guess I need to open and translate to another COG dataset after breaking
the COG layout?
## now open in rw, to zap band level md (but breaks COG layout)
#lds = gdal.OpenEx(tmp, gdal.GA_Update, open_options =
["IGNORE_COG_LAYOUT_BREAK=YES"])
#lds.GetRasterBand(1).SetMetadata({})
#lds.Close()
#Warning 1: tmp1.tif: The IFD has been rewritten at the end of the file,
which breaks COG layout.
ds = gdal.Open(tmp)
#Warning 1: tmp1.tif: This file used to have optimizations in its layout,
but those have been, at least partly, invalidated by later changes
Cheers, Mike
--
Michael Sumner
Research Software Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsumner at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20240530/37e21f19/attachment.htm>
More information about the gdal-dev
mailing list