Skip to content

Commit 7d1b25f

Browse files
authored
Merge pull request #13980 from wietzesuijker/feat/zarr-build-overviews
Zarr v3: GDALMDArray::BuildOverviews() with >2D support and dataset b…
2 parents 7a2a0b8 + 0f80425 commit 7d1b25f

File tree

11 files changed

+1507
-11
lines changed

11 files changed

+1507
-11
lines changed

autotest/gdrivers/zarr_driver.py

Lines changed: 533 additions & 8 deletions
Large diffs are not rendered by default.

doc/source/drivers/raster/zarr.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ a ``multiscales`` attribute with a ``layout`` array, the driver exposes
103103
lower-resolution levels as overviews via :cpp:func:`GDALMDArray::GetOverview`
104104
and the classic raster band overview API.
105105

106+
Overviews can be generated using :cpp:func:`GDALMDArray::BuildOverviews` or
107+
equivalently via :cpp:func:`GDALDataset::BuildOverviews` on datasets obtained
108+
through :cpp:func:`GDALMDArray::AsClassicDataset`. For arrays with more than
109+
two dimensions, only the spatial dimensions are downsampled; non-spatial
110+
dimensions (e.g., time) are preserved. Each overview level is resampled
111+
sequentially from the previous level (e.g., 4x from 2x, not from base).
112+
Codec settings are inherited from the source array. Calling
113+
``BuildOverviews`` replaces all existing overviews (unlike the default
114+
``GDALDataset::BuildOverviews`` behavior which adds new levels).
115+
106116
Kerchunk reference stores
107117
-------------------------
108118

doc/source/spelling_wordlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ Decompressor
579579
decompressors
580580
decrementing
581581
decrypted
582+
deduplicate
582583
Deegree
583584
defacto
584585
define'ed
@@ -1886,6 +1887,7 @@ multiproc
18861887
multiprocess
18871888
multireadtest
18881889
multirecords
1890+
multiscales
18891891
multispectral
18901892
multistring
18911893
multisurface

frmts/zarr/zarr.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@ class ZarrV3Group final : public ZarrGroupBase
673673
const std::string &osZarrayFilename,
674674
const CPLJSONObject &oRoot) const;
675675

676+
void GenerateMultiscalesMetadata(const char *pszResampling = nullptr);
677+
676678
std::shared_ptr<GDALMDArray> CreateMDArray(
677679
const std::string &osName,
678680
const std::vector<std::shared_ptr<GDALDimension>> &aoDimensions,
@@ -1404,6 +1406,8 @@ class ZarrV3Array final : public ZarrArray
14041406

14051407
void LoadOverviews() const;
14061408

1409+
void ReconstructCreationOptionsFromCodecs();
1410+
14071411
public:
14081412
~ZarrV3Array() override;
14091413

@@ -1436,6 +1440,11 @@ class ZarrV3Array final : public ZarrArray
14361440

14371441
std::shared_ptr<GDALMDArray> GetOverview(int idx) const override;
14381442

1443+
CPLErr BuildOverviews(const char *pszResampling, int nOverviews,
1444+
const int *panOverviewList,
1445+
GDALProgressFunc pfnProgress, void *pProgressData,
1446+
CSLConstList papszOptions) override;
1447+
14391448
protected:
14401449
std::string GetDataDirectory() const override;
14411450

frmts/zarr/zarr_array.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,11 +3772,15 @@ std::shared_ptr<ZarrGroupBase> ZarrArray::GetParentGroup() const
37723772
if (auto poRootGroup = m_poSharedResource->GetRootGroup())
37733773
{
37743774
const auto nPos = m_osFullName.rfind('/');
3775-
if (nPos != std::string::npos)
3775+
if (nPos == 0)
3776+
{
3777+
poGroup = std::dynamic_pointer_cast<ZarrGroupBase>(poRootGroup);
3778+
}
3779+
else if (nPos != std::string::npos)
37763780
{
37773781
poGroup = std::dynamic_pointer_cast<ZarrGroupBase>(
3778-
poRootGroup->OpenGroupFromFullname(m_osFullName.substr(
3779-
0, std::max(static_cast<size_t>(1), nPos))));
3782+
poRootGroup->OpenGroupFromFullname(
3783+
m_osFullName.substr(0, nPos)));
37803784
}
37813785
}
37823786
}

0 commit comments

Comments
 (0)