2727/* ***********************************************************************/
2828
2929GDALMdimConvertAlgorithm::GDALMdimConvertAlgorithm ()
30- : GDALAlgorithm(NAME , DESCRIPTION , HELP_URL )
30+ : GDALMdimPipelineStepAlgorithm(NAME , DESCRIPTION , HELP_URL ,
31+ ConstructorOptions ()
32+ .SetStandaloneStep(true )
33+ .SetInputDatasetMaxCount(1 )
34+ .SetAddDefaultArguments(false ))
3135{
36+ AddMdimInputArgs (false , false , /* acceptRaster = */ true );
3237 AddProgressArg ();
33- AddOutputFormatArg (&m_outputFormat)
34- .AddMetadataItem (GAAMDI_REQUIRED_CAPABILITIES ,
35- {GDAL_DCAP_CREATE_MULTIDIMENSIONAL });
36- AddOpenOptionsArg (&m_openOptions);
37- AddInputFormatsArg (&m_inputFormats)
38- .AddMetadataItem (GAAMDI_REQUIRED_CAPABILITIES ,
39- {GDAL_ALG_DCAP_RASTER_OR_MULTIDIM_RASTER });
40- AddInputDatasetArg (&m_inputDataset,
41- GDAL_OF_RASTER | GDAL_OF_MULTIDIM_RASTER );
42- AddOutputDatasetArg (&m_outputDataset, GDAL_OF_MULTIDIM_RASTER );
43- AddCreationOptionsArg (&m_creationOptions);
44- AddOverwriteArg (&m_overwrite);
38+ AddMdimOutputArgs (false );
4539
4640 {
4741 auto &arg = AddArg (" array" , 0 ,
@@ -55,14 +49,18 @@ GDALMdimConvertAlgorithm::GDALMdimConvertAlgorithm()
5549 [this ](const std::string &)
5650 {
5751 std::vector<std::string> ret;
58-
59- if (auto poDS = std::unique_ptr<GDALDataset>(GDALDataset::Open (
60- m_inputDataset.GetName ().c_str (),
61- GDAL_OF_MULTIDIM_RASTER , nullptr , nullptr , nullptr )))
52+ if (m_inputDataset.size () == 1 )
6253 {
63- if (auto poRG = poDS->GetRootGroup ())
54+ if (auto poDS =
55+ std::unique_ptr<GDALDataset>(GDALDataset::Open (
56+ m_inputDataset[0 ].GetName ().c_str (),
57+ GDAL_OF_MULTIDIM_RASTER , nullptr , nullptr ,
58+ nullptr )))
6459 {
65- ret = poRG->GetMDArrayFullNamesRecursive ();
60+ if (auto poRG = poDS->GetRootGroup ())
61+ {
62+ ret = poRG->GetMDArrayFullNamesRecursive ();
63+ }
6664 }
6765 }
6866
@@ -84,17 +82,22 @@ GDALMdimConvertAlgorithm::GDALMdimConvertAlgorithm()
8482 [this ](const std::string ¤tValue)
8583 {
8684 std::vector<std::string> ret;
87-
88- if (auto poDS = std::unique_ptr<GDALDataset>(GDALDataset::Open (
89- m_inputDataset.GetName ().c_str (),
90- GDAL_OF_MULTIDIM_RASTER , nullptr , nullptr , nullptr )))
85+ if (m_inputDataset.size () == 1 )
9186 {
92- if (auto poDriver = poDS->GetDriver ())
87+ if (auto poDS =
88+ std::unique_ptr<GDALDataset>(GDALDataset::Open (
89+ m_inputDataset[0 ].GetName ().c_str (),
90+ GDAL_OF_MULTIDIM_RASTER , nullptr , nullptr ,
91+ nullptr )))
9392 {
94- if (const char *pszXML = poDriver->GetMetadataItem (
95- GDAL_DMD_MULTIDIM_ARRAY_OPENOPTIONLIST ))
93+ if (auto poDriver = poDS->GetDriver ())
9694 {
97- AddOptionsSuggestions (pszXML, 0 , currentValue, ret);
95+ if (const char *pszXML = poDriver->GetMetadataItem (
96+ GDAL_DMD_MULTIDIM_ARRAY_OPENOPTIONLIST ))
97+ {
98+ AddOptionsSuggestions (pszXML, 0 , currentValue,
99+ ret);
100+ }
98101 }
99102 }
100103 }
@@ -129,14 +132,28 @@ GDALMdimConvertAlgorithm::GDALMdimConvertAlgorithm()
129132bool GDALMdimConvertAlgorithm::RunImpl (GDALProgressFunc pfnProgress,
130133 void *pProgressData)
131134{
132- CPLAssert (m_inputDataset.GetDatasetRef ());
135+ GDALPipelineStepRunContext stepCtxt;
136+ stepCtxt.m_pfnProgress = pfnProgress;
137+ stepCtxt.m_pProgressData = pProgressData;
138+ return RunPreStepPipelineValidations () && RunStep (stepCtxt);
139+ }
140+
141+ /* ***********************************************************************/
142+ /* GDALMdimConvertAlgorithm::RunStep() */
143+ /* ***********************************************************************/
144+
145+ bool GDALMdimConvertAlgorithm::RunStep (GDALPipelineStepRunContext &ctxt)
146+ {
147+ auto poSrcDS = m_inputDataset[0 ].GetDatasetRef ();
148+ CPLAssert (poSrcDS);
149+
133150 CPLAssert (!m_outputDataset.GetDatasetRef ());
134151
135152 CPLStringList aosOptions;
136- if (!m_outputFormat .empty ())
153+ if (!m_format .empty ())
137154 {
138155 aosOptions.AddString (" -of" );
139- aosOptions.AddString (m_outputFormat .c_str ());
156+ aosOptions.AddString (m_format .c_str ());
140157 }
141158 if (m_overwrite)
142159 {
@@ -192,10 +209,12 @@ bool GDALMdimConvertAlgorithm::RunImpl(GDALProgressFunc pfnProgress,
192209
193210 GDALMultiDimTranslateOptions *psOptions =
194211 GDALMultiDimTranslateOptionsNew (aosOptions.List (), nullptr );
212+ auto pfnProgress = ctxt.m_pfnProgress ;
213+ auto pProgressData = ctxt.m_pProgressData ;
195214 GDALMultiDimTranslateOptionsSetProgress (psOptions, pfnProgress,
196215 pProgressData);
197216
198- auto hSrcDS = GDALDataset::ToHandle (m_inputDataset. GetDatasetRef () );
217+ auto hSrcDS = GDALDataset::ToHandle (poSrcDS );
199218 auto poOutDS = std::unique_ptr<GDALDataset>(GDALDataset::FromHandle (
200219 GDALMultiDimTranslate (m_outputDataset.GetName ().c_str (), nullptr , 1 ,
201220 &hSrcDS, psOptions, nullptr )));
0 commit comments