Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: "astype" step of "raster pipeline" 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 : #include "gdalalg_raster_astype.h" 14 : 15 : #include "gdal_priv.h" 16 : #include "gdal_utils.h" 17 : 18 : //! @cond Doxygen_Suppress 19 : 20 : #ifndef _ 21 : #define _(x) (x) 22 : #endif 23 : 24 : /************************************************************************/ 25 : /* GDALRasterAsTypeAlgorithm::GDALRasterAsTypeAlgorithm() */ 26 : /************************************************************************/ 27 : 28 9 : GDALRasterAsTypeAlgorithm::GDALRasterAsTypeAlgorithm(bool standaloneStep) 29 : : GDALRasterPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL, 30 9 : standaloneStep) 31 : { 32 9 : AddOutputDataTypeArg(&m_type).SetRequired(); 33 9 : } 34 : 35 : /************************************************************************/ 36 : /* GDALRasterAsTypeAlgorithm::RunStep() */ 37 : /************************************************************************/ 38 : 39 1 : bool GDALRasterAsTypeAlgorithm::RunStep(GDALProgressFunc, void *) 40 : { 41 1 : CPLAssert(m_inputDataset.GetDatasetRef()); 42 1 : CPLAssert(m_outputDataset.GetName().empty()); 43 1 : CPLAssert(!m_outputDataset.GetDatasetRef()); 44 : 45 2 : CPLStringList aosOptions; 46 1 : aosOptions.AddString("-of"); 47 1 : aosOptions.AddString("VRT"); 48 1 : aosOptions.AddString("-ot"); 49 1 : aosOptions.AddString(m_type.c_str()); 50 : 51 : GDALTranslateOptions *psOptions = 52 1 : GDALTranslateOptionsNew(aosOptions.List(), nullptr); 53 : 54 : auto poOutDS = std::unique_ptr<GDALDataset>(GDALDataset::FromHandle( 55 : GDALTranslate("", GDALDataset::ToHandle(m_inputDataset.GetDatasetRef()), 56 1 : psOptions, nullptr))); 57 1 : GDALTranslateOptionsFree(psOptions); 58 1 : const bool bRet = poOutDS != nullptr; 59 1 : if (poOutDS) 60 : { 61 1 : m_outputDataset.Set(std::move(poOutDS)); 62 : } 63 : 64 2 : return bRet; 65 : } 66 : 67 : //! @endcond