Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: gdal "raster stack" subcommand 5 : * Author: Even Rouault <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2024, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "gdalalg_raster_stack.h" 14 : #include "gdalalg_raster_write.h" 15 : 16 : #include "cpl_conv.h" 17 : 18 : #include "gdal_priv.h" 19 : #include "gdal_utils.h" 20 : 21 : //! @cond Doxygen_Suppress 22 : 23 : /************************************************************************/ 24 : /* GDALRasterStackAlgorithm::GDALRasterStackAlgorithm() */ 25 : /************************************************************************/ 26 : 27 28 : GDALRasterStackAlgorithm::GDALRasterStackAlgorithm(bool bStandalone) 28 : : GDALRasterMosaicStackCommonAlgorithm(NAME, DESCRIPTION, HELP_URL, 29 28 : bStandalone) 30 : { 31 28 : } 32 : 33 : /************************************************************************/ 34 : /* GDALRasterStackAlgorithm::RunStep() */ 35 : /************************************************************************/ 36 : 37 5 : bool GDALRasterStackAlgorithm::RunStep(GDALPipelineStepRunContext &ctxt) 38 : { 39 5 : CPLAssert(!m_outputDataset.GetDatasetRef()); 40 : 41 10 : std::vector<GDALDatasetH> ahInputDatasets; 42 10 : CPLStringList aosInputDatasetNames; 43 5 : bool foundByName = false; 44 5 : if (!GetInputDatasetNames(ctxt, ahInputDatasets, aosInputDatasetNames, 45 : foundByName)) 46 : { 47 : // Error message emitted by GetInputDatasetNames() 48 1 : return false; 49 : } 50 : 51 4 : CPLStringList aosOptions; 52 : 53 4 : aosOptions.push_back("-strict"); 54 : 55 4 : aosOptions.push_back("-program_name"); 56 4 : aosOptions.push_back("gdal raster stack"); 57 : 58 4 : aosOptions.push_back("-separate"); 59 : 60 4 : SetBuildVRTOptions(aosOptions); 61 : 62 4 : bool bOK = false; 63 : GDALBuildVRTOptions *psOptions = 64 4 : GDALBuildVRTOptionsNew(aosOptions.List(), nullptr); 65 4 : if (psOptions) 66 : { 67 : auto poOutDS = 68 : std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(GDALBuildVRT( 69 : "", 70 2 : foundByName ? aosInputDatasetNames.size() 71 2 : : static_cast<int>(m_inputDataset.size()), 72 6 : ahInputDatasets.empty() ? nullptr : ahInputDatasets.data(), 73 18 : aosInputDatasetNames.List(), psOptions, nullptr))); 74 4 : GDALBuildVRTOptionsFree(psOptions); 75 4 : bOK = poOutDS != nullptr; 76 4 : if (bOK) 77 : { 78 4 : m_outputDataset.Set(std::move(poOutDS)); 79 : } 80 : } 81 4 : return bOK; 82 : } 83 : 84 : GDALRasterStackAlgorithmStandalone::~GDALRasterStackAlgorithmStandalone() = 85 : default; 86 : 87 : //! @endcond