MeteoIODoc 2.11.0
DEMObject.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef DEMOBJECT_H
20#define DEMOBJECT_H
21
24#include <meteoio/meteoLaws/Meteoconst.h> //for math constants
25
26namespace mio {
27
40class DEMObject : public Grid2DObject {
41 public:
48
50 typedef enum SLOPE_TYPE {
56 D8
58
60 typedef enum UPDATE_TYPE {
67
69 typedef enum {
71 SHORT
73
74 DEMObject(const slope_type& i_algorithm=DFLT);
75
76 DEMObject(const size_t& ncols_in, const size_t& nrows_in, const Coords& llcorner_in, const double& init);
77
78 DEMObject(const size_t& ncols_in, const size_t& nrows_in,
79 const double& cellsize_in, const Coords& llcorner_in, const slope_type& i_algorithm=DFLT);
80
81 DEMObject(const double& cellsize_in, const Coords& llcorner_in, const Array2D<double>& altitude_in,
82 const bool& i_update=true, const slope_type& i_algorithm=DFLT);
83
84 DEMObject(const Grid2DObject& dem_in, const bool& i_update=true, const slope_type& i_algorithm=DFLT);
85
86 DEMObject (const DEMObject& i_dem,
87 const size_t& i_nx, const size_t& i_ny, //Point in the plane
88 const size_t& i_ncols, const size_t& i_nrows, //dimensions of the sub-plane
89 const bool& i_update=true, const slope_type& i_algorithm=DFLT);
90
91 void setDefaultAlgorithm(const std::string& i_algorithm);
92 void setDefaultAlgorithm(const slope_type& i_algorithm);
93 int getDefaultAlgorithm() const;
94 void setUpdatePpt(const update_type& in_update_flag);
95 int getUpdatePpt() const;
96 void setCurvatureScale(const double& in_curvature_scale);
97
98 void update(const std::string& algorithm);
99 void update(const slope_type& algorithm=DFLT);
100 void updateAllMinMax();
101 void printFailures();
102 void sanitize();
103
105 DEMObject& operator=(const double& value);
106
107 DEMObject& operator+=(const double& rhs);
108 const DEMObject operator+(const double& rhs) const;
109 DEMObject& operator+=(const Grid2DObject& rhs);
110 const DEMObject operator+(const Grid2DObject& rhs) const;
111
112 DEMObject& operator-=(const double& rhs);
113 const DEMObject operator-(const double& rhs) const;
114 DEMObject& operator-=(const Grid2DObject& rhs);
115 const DEMObject operator-(const Grid2DObject& rhs) const;
116
117 DEMObject& operator*=(const double& rhs);
118 const DEMObject operator*(const double& rhs) const;
119 DEMObject& operator*=(const Grid2DObject& rhs);
120 const DEMObject operator*(const Grid2DObject& rhs) const;
121
122 DEMObject& operator/=(const double& rhs);
123 const DEMObject operator/(const double& rhs) const;
124 DEMObject& operator/=(const Grid2DObject& rhs);
125 const DEMObject operator/(const Grid2DObject& rhs) const;
126
127 bool operator==(const DEMObject& in) const;
128 bool operator!=(const DEMObject& in) const;
129
130 const std::string toString(const FORMATS& type = FULL) const;
131 friend std::ostream& operator<<(std::ostream& os, const DEMObject& dem);
132 friend std::istream& operator>>(std::istream& is, DEMObject& dem);
133
134 private:
135 void CalculateAziSlopeCurve(slope_type algorithm);
136 static double CalculateAzimuth(const double& o_Nx, const double& o_Ny, const double& o_Nz, const double& o_slope, const double& no_slope=0.);
137 double getCurvature(double A[4][4], const double& scale=IOUtils::nodata);
138 void CalculateHick(double A[4][4], double& o_slope, double& o_Nx, double& o_Ny, double& o_Nz);
139 void CalculateFleming(double A[4][4], double& o_slope, double& o_Nx, double& o_Ny, double& o_Nz);
140 void CalculateHorn(double A[4][4], double& o_slope, double& o_Nx, double& o_Ny, double& o_Nz);
141 void CalculateCorripio(double A[4][4], double& o_slope, double& o_Nx, double& o_Ny, double& o_Nz);
142 void (DEMObject::*CalculateSlope)(double A[4][4], double& o_slope, double& o_Nx, double& o_Ny, double& o_Nz);
143
144 static double steepestGradient(const double& i_cellsize, double A[4][4]);
145 static double lineGradient(const double& A1, const double& A2, const double& A3);
146 static double fillMissingGradient(const double& delta1, const double& delta2);
147 static void surfaceGradient(double& dx_sum, double& dy_sum, double A[4][4]);
148 static double avgHeight(const double& z1, const double &z2, const double& z3);
149 void getNeighbours(const size_t& i, const size_t& j, double A[4][4], const double& scale=IOUtils::nodata) const;
150 double safeGet(const int& i, const int& j) const;
151
152 double max_shade_distance;
153 double curvature_scale;
154 int update_flag;
155 slope_type dflt_algorithm;
156 size_t slope_failures;
157 size_t curvature_failures;
158};
159} //end namespace
160
161#endif
A class to handle geographic coordinate systems. This class offers an easy way to transparently conve...
Definition: Coords.h:83
A class to represent DEMs and automatically compute some properties. This class stores elevation grid...
Definition: DEMObject.h:40
DEMObject & operator-=(const double &rhs)
Definition: DEMObject.cc:960
DEMObject & operator*=(const double &rhs)
Definition: DEMObject.cc:990
DEMObject & operator/=(const double &rhs)
Definition: DEMObject.cc:1020
double min_curvature
Definition: DEMObject.h:46
int getDefaultAlgorithm() const
Get the default slope calculation algorithm.
Definition: DEMObject.cc:340
FORMATS
Keywords for selecting the toString formats.
Definition: DEMObject.h:69
@ SHORT
Simplified, lat/lon only.
Definition: DEMObject.h:71
@ FULL
Provide all the usually necessary information.
Definition: DEMObject.h:70
void updateAllMinMax()
Recomputes the min/max of altitude, slope and curvature It returns +/- std::numeric_limits<double> ::...
Definition: DEMObject.cc:348
Array2D< double > Nz
Definition: DEMObject.h:45
slope_type
Keywords for slope computation algorithm.
Definition: DEMObject.h:50
@ HORN
eight neighbor algorithm (Horn, 1981) as used by ArcGIS. It seems to be the same as (Corripio,...
Definition: DEMObject.h:54
@ DFLT
whatever algorithm that has been defined as default
Definition: DEMObject.h:51
@ FLEM
four nearest neighbors (Fleming and Hoffer, 1979). It seems to be the same as (Zevenbergen and Thorne...
Definition: DEMObject.h:52
@ D8
discretized azimuth directions (angles for N, NE, etc) and slope rounded to nearest integer
Definition: DEMObject.h:56
@ HICK
maximum downhill slope method (Dunn and Hickey, 1998)
Definition: DEMObject.h:53
@ CORR
surface normal vector using the two triangle method (Corripio, 2003) and eight-neighbor algorithm (Ho...
Definition: DEMObject.h:55
void setCurvatureScale(const double &in_curvature_scale)
Set the curvature length scale for calculating curvature.
Definition: DEMObject.cc:229
void update(const std::string &algorithm)
Force the computation of the local slope, azimuth, normal vector and curvature. It has to be called m...
Definition: DEMObject.cc:275
const DEMObject operator+(const double &rhs) const
Definition: DEMObject.cc:936
bool operator==(const DEMObject &in) const
Operator that tests for equality.
Definition: DEMObject.cc:1050
double max_curvature
Definition: DEMObject.h:47
Array2D< double > Nx
Definition: DEMObject.h:45
double max_slope
Definition: DEMObject.h:47
friend std::istream & operator>>(std::istream &is, DEMObject &dem)
Definition: DEMObject.cc:888
void printFailures()
Prints the list of points that have an elevation different than nodata but no slope or curvature Such...
Definition: DEMObject.cc:368
DEMObject & operator+=(const double &rhs)
Definition: DEMObject.cc:930
Array2D< double > Ny
Definition: DEMObject.h:45
Array2D< double > curvature
Definition: DEMObject.h:44
DEMObject & operator=(const Grid2DObject &)
Assignement operator.
const DEMObject operator/(const double &rhs) const
Definition: DEMObject.cc:1026
const DEMObject operator-(const double &rhs) const
Definition: DEMObject.cc:966
void sanitize()
Clean up the DEM Object When computing the slope and curvature, it is possible to get points where th...
Definition: DEMObject.cc:419
int getUpdatePpt() const
Get the properties that will be calculated by the object when updating.
Definition: DEMObject.cc:222
const DEMObject operator*(const double &rhs) const
Definition: DEMObject.cc:996
update_type
Keywords for automatic update of parameters. They can be combined with "|".
Definition: DEMObject.h:60
@ SLOPE
update the slopes
Definition: DEMObject.h:62
@ UPDATE_UNSET
property not set
Definition: DEMObject.h:65
@ NO_UPDATE
no updates at all
Definition: DEMObject.h:61
@ NORMAL
update the normals
Definition: DEMObject.h:63
@ CURVATURE
update the curvatures
Definition: DEMObject.h:64
bool operator!=(const DEMObject &in) const
Operator that tests for inequality.
Definition: DEMObject.cc:1054
DEMObject(const slope_type &i_algorithm=DFLT)
Default constructor. Initializes all variables to 0, except lat/long which are initialized to IOUtils...
Definition: DEMObject.cc:42
void setDefaultAlgorithm(const std::string &i_algorithm)
Sets the default slope calculation algorithm.
Definition: DEMObject.cc:303
Array2D< double > slope
Definition: DEMObject.h:42
double min_altitude
Definition: DEMObject.h:46
double max_altitude
Definition: DEMObject.h:47
double min_slope
Definition: DEMObject.h:46
void setUpdatePpt(const update_type &in_update_flag)
Set the properties that will be calculated by the object when updating The following properties can b...
Definition: DEMObject.cc:214
friend std::ostream & operator<<(std::ostream &os, const DEMObject &dem)
Definition: DEMObject.cc:864
Array2D< double > azi
Definition: DEMObject.h:43
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:42
const std::string toString() const
Definition: Grid2DObject.cc:583
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:75
Definition: Config.cc:31