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
29 class 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 // Used for dimensions with irregular spaced labels
63 int nProgressionSign =
64 0; // 1=increasing, -1=decreasing, 0=single value
65 // Groups of irregularly spaced values. In common cases,
66 // aaValues[i].size() will be just one
67 std::vector<std::vector<double>> aaValues{};
68
69 // Used for dimensions with regularly spaced labels
70 double dfStart = 0;
71 double dfIncrement = 0;
72 };
73
74 // Minimum information about a dimension of a source array.
75 struct SourceShortDimDesc
76 {
77 uint64_t nSize = 0;
78 double dfStart = 0;
79 bool bIsRegularlySpaced = false;
80 };
81
82 // For a given output array, gather parameters from source arrays and
83 // output dimensions.
84 struct ArrayParameters
85 {
86 std::vector<DimensionDesc> mosaicDimensions{};
87 std::shared_ptr<GDALMDArray> poFirstSourceArray{};
88 std::vector<std::vector<SourceShortDimDesc>> aaoSourceShortDimDesc{};
89 };
90
91 bool GetInputDatasetNames(GDALProgressFunc pfnProgress, void *pProgressData,
92 CPLStringList &aosInputDatasetNames) const;
93
94 std::optional<DimensionDesc>
95 // cppcheck-suppress functionStatic
96 GetDimensionDesc(const std::string &osDSName,
97 const std::shared_ptr<GDALDimension> &poDim) const;
98
99 bool BuildArrayParameters(const CPLStringList &aosInputDatasetNames,
100 std::vector<ArrayParameters> &aoArrayParameters);
101};
102
104
105#endif
CPLStringList
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:454
GDALAlgorithm
GDAL algorithm.
Definition gdalalgorithm_cpp.h:2261
GDALArgDatasetValue
Value for an argument that points to a GDALDataset.
Definition gdalalgorithm_cpp.h:149