GDAL
gdalalg_mdim_mosaic.h
1/******************************************************************************
2 *
3 * Project: GDAL
4 * Purpose: gdal "mdim mosaic" subcommand
5 * Author: Even Rouault <even dot rouault at spatialys.com>
6 *
7 ******************************************************************************
8 * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com>
9 *
10 * SPDX-License-Identifier: MIT
11 ****************************************************************************/
12
13#ifndef GDALALG_MDIM_MOSAIC_INCLUDED
14#define GDALALG_MDIM_MOSAIC_INCLUDED
15
16#include "gdalalgorithm.h"
17
18#include "gdal_multidim.h"
19
20#include <optional>
21#include <utility>
22
24
25/************************************************************************/
26/* GDALMdimMosaicAlgorithm */
27/************************************************************************/
28
29class GDALMdimMosaicAlgorithm final : public GDALAlgorithm
30{
31 public:
32 static constexpr const char *NAME = "mosaic";
33 static constexpr const char *DESCRIPTION =
34 "Build a mosaic, either virtual (VRT) or materialized, from "
35 "multidimensional datasets.";
36 static constexpr const char *HELP_URL = "/programs/gdal_mdim_mosaic.html";
37
38 explicit GDALMdimMosaicAlgorithm();
39
40 private:
41 bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) override;
42
43 std::string m_outputFormat{};
44 std::vector<GDALArgDatasetValue> m_inputDatasets{};
45 std::vector<std::string> m_openOptions{};
46 std::vector<std::string> m_inputFormats{};
47 GDALArgDatasetValue m_outputDataset{};
48 std::vector<std::string> m_creationOptions{};
49 bool m_overwrite = false;
50 std::vector<std::string> m_array{};
51
52 // Describes a dimension of the mosaic array.
53 struct DimensionDesc
54 {
55 std::string osName{};
56 std::string osType{};
57 std::string osDirection{};
58 uint64_t nSize = 0;
59 uint64_t nBlockSize = 0;
60 std::vector<std::shared_ptr<GDALAttribute>> attributes{};
61
62 bool bHasIndexingVar = false;
63
64 // Used for dimensions with irregular spaced labels
65 int nProgressionSign =
66 0; // 1=increasing, -1=decreasing, 0=single value
67 // Groups of irregularly spaced values. In common cases,
68 // aaValues[i].size() will be just one
69 std::vector<std::vector<double>> aaValues{};
70
71 // Used for dimensions with regularly spaced labels
72 double dfStart = 0;
73 double dfIncrement = 0;
74 };
75
76 // Minimum information about a dimension of a source array.
77 struct SourceShortDimDesc
78 {
79 uint64_t nSize = 0;
80 double dfStart = 0;
81 bool bIsRegularlySpaced = false;
82 };
83
84 // For a given output array, gather parameters from source arrays and
85 // output dimensions.
86 struct ArrayParameters
87 {
88 std::vector<DimensionDesc> mosaicDimensions{};
89 std::shared_ptr<GDALMDArray> poFirstSourceArray{};
90 std::vector<std::vector<SourceShortDimDesc>> aaoSourceShortDimDesc{};
91 };
92
93 bool GetInputDatasetNames(GDALProgressFunc pfnProgress, void *pProgressData,
94 CPLStringList &aosInputDatasetNames) const;
95
96 std::optional<DimensionDesc>
97 // cppcheck-suppress functionStatic
98 GetDimensionDesc(const std::string &osDSName,
99 const std::shared_ptr<GDALDimension> &poDim) const;
100
101 bool BuildArrayParameters(const CPLStringList &aosInputDatasetNames,
102 std::vector<ArrayParameters> &aoArrayParameters);
103};
104
106
107#endif
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:476
GDAL algorithm.
Definition gdalalgorithm_cpp.h:2445
Value for an argument that points to a GDALDataset.
Definition gdalalgorithm_cpp.h:163