Skip to content

Zarr: fix BuildOverviews() on a new multiband dataset - #14977

Open
rouault wants to merge 1 commit into
OSGeo:masterfrom
rouault:fix_14963
Open

Zarr: fix BuildOverviews() on a new multiband dataset#14977
rouault wants to merge 1 commit into
OSGeo:masterfrom
rouault:fix_14963

Conversation

@rouault

@rouault rouault commented Jul 24, 2026

Copy link
Copy Markdown
Member

Fixes #14963

@rouault rouault added this to the 3.14.0 milestone Jul 24, 2026
@rouault rouault added the funded through GSP Work funded through the GDAL Sponsorship Program label Jul 24, 2026
@neilflood

Copy link
Copy Markdown
Contributor

Thank you @rouault
I have just built and tested this branch, and can confirm that it does fix the original problem.

However, it does expose a couple of new problems.

The first involves directly writing the overviews myself (which we use in some circumstances to avoid an extra pass through the data). This is demonstrated by the following Python fragment.

import os
import numpy
from osgeo import gdal, osr
gdal.DontUseExceptions()

zarrFile = "testOverviews.zarr"
drvr = gdal.GetDriverByName('Zarr')
if os.path.exists(zarrFile):
    drvr.Delete(zarrFile)

options = ["COMPRESS=BLOSC", "FORMAT=ZARR_V3"]
(nrows, ncols) = (1000, 1000)
bands = 1
ds = drvr.Create(zarrFile, ncols, nrows, bands, gdal.GDT_Byte, options=options)
ds.BuildOverviews(overviewlist=[4])
b = ds.GetRasterBand(1)
b.SetNoDataValue(0)
a = numpy.full((nrows, ncols), 25, dtype=numpy.uint8)
b.WriteArray(a)

closeReopen = False
if closeReopen:
    ds = None
    ds = gdal.Open(zarrFile, gdal.GA_Update)
    b = ds.GetRasterBand(1)

b_ov = b.GetOverview(0)
ov = a[::4, ::4]
b_ov.WriteArray(ov)

If closeReopen is False, the b_ov object returned from b.GetOverview(0) thinks it is on a read-only Dataset, and so cannot be written to. This produces the following error message

ERROR 8: GDALRasterBand::RasterIO(): attempt to write to dataset opened in read-only mode.

If closeReopen is set to True, it knows it is a writeable Dataset and writes the overview data fine.

That does expose a second problem, which is that the no-data value is not being propagated into the overviews, which I think it should. This shows up as the following messages

Warning 1: fill_value = null is invalid
Warning 1: fill_value = null is invalid
Warning 1: fill_value = null is invalid

The main testOverviews array has the correct fill_value recorded, but the ovr_4x/testOverviews array does not.

Many thanks, as always

Ping @gillins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

funded through GSP Work funded through the GDAL Sponsorship Program

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zarr: Overviews are supported in a re-opened Zarr, but not in a new one

2 participants