Line data Source code
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 3 : bool CanBeFirstStep() const override 42 : { 43 3 : return true; 44 : } 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 : 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 : 105 : /************************************************************************/ 106 : /* GDALMdimMosaicAlgorithmStandalone */ 107 : /************************************************************************/ 108 : 109 152 : class GDALMdimMosaicAlgorithmStandalone final : public GDALMdimMosaicAlgorithm 110 : { 111 : public: 112 76 : GDALMdimMosaicAlgorithmStandalone() 113 76 : : GDALMdimMosaicAlgorithm(/* standaloneStep = */ true) 114 : { 115 76 : } 116 : 117 : ~GDALMdimMosaicAlgorithmStandalone() override; 118 : }; 119 : 120 : //! @endcond 121 : 122 : #endif