1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
/******************************************************************************
*
* Project: GDAL
* Purpose: "roughness" step of "raster pipeline"
* Author: Even Rouault <even dot rouault at spatialys.com>
*
******************************************************************************
* Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com>
*
* SPDX-License-Identifier: MIT
****************************************************************************/
#include "gdalalg_raster_roughness.h"
#include "gdal_priv.h"
#include "gdal_utils.h"
#include <cmath>
//! @cond Doxygen_Suppress
#ifndef _
#define _(x) (x)
#endif
/************************************************************************/
/* GDALRasterRoughnessAlgorithm::GDALRasterRoughnessAlgorithm() */
/************************************************************************/
GDALRasterRoughnessAlgorithm::GDALRasterRoughnessAlgorithm(bool standaloneStep)
: GDALRasterPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
standaloneStep)
{
SetOutputVRTCompatible(false);
AddBandArg(&m_band).SetDefault(m_band);
AddArg("no-edges", 0,
_("Do not try to interpolate values at dataset edges or close to "
"nodata values"),
&m_noEdges);
}
/************************************************************************/
/* GDALRasterRoughnessAlgorithm::RunStep() */
/************************************************************************/
bool GDALRasterRoughnessAlgorithm::RunStep(GDALPipelineStepRunContext &)
{
auto poSrcDS = m_inputDataset[0].GetDatasetRef();
CPLAssert(poSrcDS);
CPLAssert(m_outputDataset.GetName().empty());
CPLAssert(!m_outputDataset.GetDatasetRef());
CPLStringList aosOptions;
aosOptions.AddString("-of");
aosOptions.AddString("stream");
aosOptions.AddString("-b");
aosOptions.AddString(CPLSPrintf("%d", m_band));
if (!m_noEdges)
aosOptions.AddString("-compute_edges");
GDALDEMProcessingOptions *psOptions =
GDALDEMProcessingOptionsNew(aosOptions.List(), nullptr);
auto poOutDS = std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(
GDALDEMProcessing("", GDALDataset::ToHandle(poSrcDS), "roughness",
nullptr, psOptions, nullptr)));
GDALDEMProcessingOptionsFree(psOptions);
const bool bRet = poOutDS != nullptr;
if (poOutDS)
{
m_outputDataset.Set(std::move(poOutDS));
}
return bRet;
}
GDALRasterRoughnessAlgorithmStandalone::
~GDALRasterRoughnessAlgorithmStandalone() = default;
//! @endcond
|