/src/gdal/apps/gdalalg_raster_aspect.cpp
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Project: GDAL |
4 | | * Purpose: "aspect" 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_aspect.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 | | /* GDALRasterAspectAlgorithm::GDALRasterAspectAlgorithm() */ |
28 | | /************************************************************************/ |
29 | | |
30 | | GDALRasterAspectAlgorithm::GDALRasterAspectAlgorithm(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("convention", 0, _("Convention for output angles"), &m_convention) |
38 | 0 | .SetChoices("azimuth", "trigonometric-angle") |
39 | 0 | .SetDefault(m_convention); |
40 | 0 | AddArg("gradient-alg", 0, _("Algorithm used to compute terrain gradient"), |
41 | 0 | &m_gradientAlg) |
42 | 0 | .SetChoices("Horn", "ZevenbergenThorne") |
43 | 0 | .SetDefault(m_gradientAlg); |
44 | 0 | AddArg("zero-for-flat", 0, _("Whether to output zero for flat areas"), |
45 | 0 | &m_zeroForFlat); |
46 | 0 | AddArg("no-edges", 0, |
47 | 0 | _("Do not try to interpolate values at dataset edges or close to " |
48 | 0 | "nodata values"), |
49 | 0 | &m_noEdges); |
50 | 0 | } |
51 | | |
52 | | /************************************************************************/ |
53 | | /* GDALRasterAspectAlgorithm::RunStep() */ |
54 | | /************************************************************************/ |
55 | | |
56 | | bool GDALRasterAspectAlgorithm::RunStep(GDALPipelineStepRunContext &) |
57 | 0 | { |
58 | 0 | const auto poSrcDS = m_inputDataset[0].GetDatasetRef(); |
59 | 0 | CPLAssert(poSrcDS); |
60 | 0 | CPLAssert(m_outputDataset.GetName().empty()); |
61 | 0 | CPLAssert(!m_outputDataset.GetDatasetRef()); |
62 | | |
63 | 0 | CPLStringList aosOptions; |
64 | 0 | aosOptions.AddString("-of"); |
65 | 0 | aosOptions.AddString("stream"); |
66 | 0 | aosOptions.AddString("-b"); |
67 | 0 | aosOptions.AddString(CPLSPrintf("%d", m_band)); |
68 | 0 | if (m_convention == "trigonometric-angle") |
69 | 0 | aosOptions.AddString("-trigonometric"); |
70 | 0 | aosOptions.AddString("-alg"); |
71 | 0 | aosOptions.AddString(m_gradientAlg.c_str()); |
72 | 0 | if (m_zeroForFlat) |
73 | 0 | aosOptions.AddString("-zero_for_flat"); |
74 | 0 | if (!m_noEdges) |
75 | 0 | aosOptions.AddString("-compute_edges"); |
76 | |
|
77 | 0 | GDALDEMProcessingOptions *psOptions = |
78 | 0 | GDALDEMProcessingOptionsNew(aosOptions.List(), nullptr); |
79 | |
|
80 | 0 | auto poOutDS = std::unique_ptr<GDALDataset>(GDALDataset::FromHandle( |
81 | 0 | GDALDEMProcessing("", GDALDataset::ToHandle(poSrcDS), "aspect", nullptr, |
82 | 0 | psOptions, nullptr))); |
83 | 0 | GDALDEMProcessingOptionsFree(psOptions); |
84 | 0 | const bool bRet = poOutDS != nullptr; |
85 | 0 | if (poOutDS) |
86 | 0 | { |
87 | 0 | m_outputDataset.Set(std::move(poOutDS)); |
88 | 0 | } |
89 | |
|
90 | 0 | return bRet; |
91 | 0 | } |
92 | | |
93 | 0 | GDALRasterAspectAlgorithmStandalone::~GDALRasterAspectAlgorithmStandalone() = |
94 | | default; |
95 | | |
96 | | //! @endcond |