/src/gdal/apps/gdalalg_raster_tri.cpp
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Project: GDAL |
4 | | * Purpose: "tri" 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_tri.h" |
14 | | |
15 | | #include "gdal_priv.h" |
16 | | #include "gdal_utils.h" |
17 | | |
18 | | #include <cmath> |
19 | | |
20 | | //! @cond Doxygen_Suppress |
21 | | |
22 | | #ifndef _ |
23 | 0 | #define _(x) (x) |
24 | | #endif |
25 | | |
26 | | /************************************************************************/ |
27 | | /* GDALRasterTRIAlgorithm::GDALRasterTRIAlgorithm() */ |
28 | | /************************************************************************/ |
29 | | |
30 | | GDALRasterTRIAlgorithm::GDALRasterTRIAlgorithm(bool standaloneStep) |
31 | 0 | : GDALRasterPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL, |
32 | 0 | standaloneStep) |
33 | 0 | { |
34 | 0 | SetOutputVRTCompatible(false); |
35 | |
|
36 | 0 | AddBandArg(&m_band).SetDefault(m_band); |
37 | 0 | AddArg("algorithm", 0, _("Algorithm to compute TRI"), &m_algorithm) |
38 | 0 | .SetChoices("Riley", "Wilson") |
39 | 0 | .SetDefault(m_algorithm); |
40 | 0 | AddArg("no-edges", 0, |
41 | 0 | _("Do not try to interpolate values at dataset edges or close to " |
42 | 0 | "nodata values"), |
43 | 0 | &m_noEdges); |
44 | 0 | } |
45 | | |
46 | | /************************************************************************/ |
47 | | /* GDALRasterTRIAlgorithm::RunStep() */ |
48 | | /************************************************************************/ |
49 | | |
50 | | bool GDALRasterTRIAlgorithm::RunStep(GDALPipelineStepRunContext &) |
51 | 0 | { |
52 | 0 | const auto poSrcDS = m_inputDataset[0].GetDatasetRef(); |
53 | 0 | CPLAssert(poSrcDS); |
54 | 0 | CPLAssert(m_outputDataset.GetName().empty()); |
55 | 0 | CPLAssert(!m_outputDataset.GetDatasetRef()); |
56 | | |
57 | 0 | CPLStringList aosOptions; |
58 | 0 | aosOptions.AddString("-of"); |
59 | 0 | aosOptions.AddString("stream"); |
60 | 0 | aosOptions.AddString("-b"); |
61 | 0 | aosOptions.AddString(CPLSPrintf("%d", m_band)); |
62 | 0 | aosOptions.AddString("-alg"); |
63 | 0 | aosOptions.AddString(m_algorithm.c_str()); |
64 | 0 | if (!m_noEdges) |
65 | 0 | aosOptions.AddString("-compute_edges"); |
66 | |
|
67 | 0 | GDALDEMProcessingOptions *psOptions = |
68 | 0 | GDALDEMProcessingOptionsNew(aosOptions.List(), nullptr); |
69 | |
|
70 | 0 | auto poOutDS = std::unique_ptr<GDALDataset>(GDALDataset::FromHandle( |
71 | 0 | GDALDEMProcessing("", GDALDataset::ToHandle(poSrcDS), "TRI", nullptr, |
72 | 0 | psOptions, nullptr))); |
73 | 0 | GDALDEMProcessingOptionsFree(psOptions); |
74 | 0 | const bool bRet = poOutDS != nullptr; |
75 | 0 | if (poOutDS) |
76 | 0 | { |
77 | 0 | m_outputDataset.Set(std::move(poOutDS)); |
78 | 0 | } |
79 | |
|
80 | 0 | return bRet; |
81 | 0 | } |
82 | | |
83 | 0 | GDALRasterTRIAlgorithmStandalone::~GDALRasterTRIAlgorithmStandalone() = default; |
84 | | |
85 | | //! @endcond |