/src/gdal/apps/gdalalg_mdim_mosaic.h
Line | Count | Source |
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 "gdalmdimpipelinestepalgorithm.h" |
17 | | |
18 | | #include "gdal_multidim.h" |
19 | | |
20 | | #include <optional> |
21 | | #include <utility> |
22 | | |
23 | | //! @cond Doxygen_Suppress |
24 | | |
25 | | /************************************************************************/ |
26 | | /* GDALMdimMosaicAlgorithm */ |
27 | | /************************************************************************/ |
28 | | |
29 | | class GDALMdimMosaicAlgorithm /* non final*/ |
30 | | : public GDALMdimPipelineStepAlgorithm |
31 | | { |
32 | | public: |
33 | | static constexpr const char *NAME = "mosaic"; |
34 | | static constexpr const char *DESCRIPTION = |
35 | | "Build a mosaic, either virtual (VRT) or materialized, from " |
36 | | "multidimensional datasets."; |
37 | | static constexpr const char *HELP_URL = "/programs/gdal_mdim_mosaic.html"; |
38 | | |
39 | | explicit GDALMdimMosaicAlgorithm(bool standaloneStep = false); |
40 | | |
41 | | bool CanBeFirstStep() const override |
42 | 0 | { |
43 | 0 | return true; |
44 | 0 | } |
45 | | |
46 | | private: |
47 | | bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) override; |
48 | | bool RunStep(GDALPipelineStepRunContext &ctxt) override; |
49 | | |
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 | | // indexing variable unit (e.g. CF 'units') |
62 | | std::string osUnit{}; |
63 | | bool bHasIndexingVar = false; |
64 | | |
65 | | // Used for dimensions with irregular spaced labels |
66 | | int nProgressionSign = |
67 | | 0; // 1=increasing, -1=decreasing, 0=single value |
68 | | // Groups of irregularly spaced values. In common cases, |
69 | | // aaValues[i].size() will be just one |
70 | | std::vector<std::vector<double>> aaValues{}; |
71 | | |
72 | | // Used for dimensions with regularly spaced labels |
73 | | double dfStart = 0; |
74 | | double dfIncrement = 0; |
75 | | }; |
76 | | |
77 | | // Minimum information about a dimension of a source array. |
78 | | struct SourceShortDimDesc |
79 | | { |
80 | | uint64_t nSize = 0; |
81 | | double dfStart = 0; |
82 | | bool bIsRegularlySpaced = false; |
83 | | }; |
84 | | |
85 | | // For a given output array, gather parameters from source arrays and |
86 | | // output dimensions. |
87 | | struct ArrayParameters |
88 | | { |
89 | | std::vector<DimensionDesc> mosaicDimensions{}; |
90 | | std::shared_ptr<GDALMDArray> poFirstSourceArray{}; |
91 | | std::vector<std::vector<SourceShortDimDesc>> aaoSourceShortDimDesc{}; |
92 | | }; |
93 | | |
94 | | bool GetInputDatasetNames(GDALProgressFunc pfnProgress, void *pProgressData, |
95 | | CPLStringList &aosInputDatasetNames) const; |
96 | | |
97 | | std::optional<DimensionDesc> |
98 | | // cppcheck-suppress functionStatic |
99 | | GetDimensionDesc(const std::string &osDSName, |
100 | | const std::shared_ptr<GDALDimension> &poDim) const; |
101 | | |
102 | | bool BuildArrayParameters(const CPLStringList &aosInputDatasetNames, |
103 | | std::vector<ArrayParameters> &aoArrayParameters); |
104 | | }; |
105 | | |
106 | | /************************************************************************/ |
107 | | /* GDALMdimMosaicAlgorithmStandalone */ |
108 | | /************************************************************************/ |
109 | | |
110 | | class GDALMdimMosaicAlgorithmStandalone final : public GDALMdimMosaicAlgorithm |
111 | | { |
112 | | public: |
113 | | GDALMdimMosaicAlgorithmStandalone() |
114 | 0 | : GDALMdimMosaicAlgorithm(/* standaloneStep = */ true) |
115 | 0 | { |
116 | 0 | } |
117 | | |
118 | | ~GDALMdimMosaicAlgorithmStandalone() override; |
119 | | }; |
120 | | |
121 | | //! @endcond |
122 | | |
123 | | #endif |