MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEMObject.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
3 /***********************************************************************************/
4 /* This file is part of MeteoIO.
5  MeteoIO is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  MeteoIO is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef DEMOBJECT_H
19 #define DEMOBJECT_H
20 
23 #include <meteoio/meteoLaws/Meteoconst.h> //for math constants
24 
25 namespace mio {
26 
39 class DEMObject : public Grid2DObject {
40  public:
47 
49  typedef enum SLOPE_TYPE {
50  DFLT,
51  FLEM,
52  HICK,
53  HORN,
54  CORR,
55  D8
56  } slope_type;
57 
59  typedef enum UPDATE_TYPE {
61  SLOPE=1,
62  NORMAL=2,
64  } update_type;
65 
67  typedef enum {
68  FULL,
70  } FORMATS;
71 
72  DEMObject(const slope_type& i_algorithm=DFLT);
73 
74  DEMObject(const size_t& ncols_in, const size_t& nrows_in,
75  const double& cellsize_in, const Coords& llcorner_in, const slope_type& i_algorithm=DFLT);
76 
77  DEMObject(const double& cellsize_in, const Coords& llcorner_in, const Array2D<double>& altitude_in,
78  const bool& i_update=true, const slope_type& i_algorithm=DFLT);
79 
80  DEMObject(const Grid2DObject& dem_in, const bool& i_update=true, const slope_type& i_algorithm=DFLT);
81 
82  DEMObject (const DEMObject& i_dem,
83  const size_t& i_nx, const size_t& i_ny, //Point in the plane
84  const size_t& i_ncols, const size_t& i_nrows, //dimensions of the sub-plane
85  const bool& i_update=true, const slope_type& i_algorithm=DFLT);
86 
87  void setDefaultAlgorithm(const slope_type& i_algorithm);
88  int getDefaultAlgorithm() const;
89  void setUpdatePpt(const update_type& in_update_flag);
90  int getUpdatePpt() const;
91 
92  void update(const std::string& algorithm);
93  void update(const slope_type& algorithm=DFLT);
94  void updateAllMinMax();
95  void printFailures();
96  void sanitize();
97 
98  Grid2DObject getHillshade(const double& elev=38., const double& azimuth=0.) const;
99  double getHorizon(const size_t& ix1, const size_t& iy1, const double& bearing) const;
100  double getHorizon(const Coords& point, const double& bearing) const;
101  void getHorizon(const Coords& point, const double& increment, std::vector< std::pair<double,double> >& horizon) const;
102  double getCellSkyViewFactor(const size_t& ii, const size_t& jj) const;
103 
104  DEMObject& operator=(const Grid2DObject&);
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::iostream& operator<<(std::iostream& os, const DEMObject& dem);
132  friend std::iostream& operator>>(std::iostream& is, DEMObject& dem);
133 
134  private:
135  double getTanMaxSlope(const double& tan_local_slope, const double& dmax, const double& bearing, const size_t& i, const size_t& j) const;
136  void CalculateAziSlopeCurve(slope_type algorithm);
137  double CalculateAspect(const double& o_Nx, const double& o_Ny, const double& o_Nz, const double& o_slope, const double no_slope=Cst::PI);
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  double getCurvature(double A[4][4]);
144 
145  double steepestGradient(double A[4][4]);
146  double lineGradient(const double& A1, const double& A2, const double& A3);
147  double fillMissingGradient(const double& delta1, const double& delta2);
148  void surfaceGradient(double& dx_sum, double& dy_sum, double A[4][4]);
149  double avgHeight(const double& z1, const double &z2, const double& z3);
150  void getNeighbours(const size_t i, const size_t j, double A[4][4]);
151  double safeGet(const int i, const int j);
152 
153  double max_shade_distance;
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
surface normal vector using the two triangle method (Corripio, 2003) and eight-neighbor algorithm (Ho...
Definition: DEMObject.h:54
no updates at all
Definition: DEMObject.h:60
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:194
Simplified, lat/lon only.
Definition: DEMObject.h:69
const DEMObject operator+(const double &rhs) const
Definition: DEMObject.cc:1021
four nearest neighbors (Fleming and Hoffer, 1979). It seems to be the same as (Zevenbergen and Thorne...
Definition: DEMObject.h:51
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:248
DEMObject & operator/=(const double &rhs)
Definition: DEMObject.cc:1105
update the curvatures
Definition: DEMObject.h:63
int getDefaultAlgorithm() const
Get the default slope calculation algorithm.
Definition: DEMObject.cc:289
double min_slope
Definition: DEMObject.h:45
const DEMObject operator*(const double &rhs) const
Definition: DEMObject.cc:1081
maximum downhill slope method (Dunn and Hickey, 1998)
Definition: DEMObject.h:52
bool operator!=(const DEMObject &in) const
Operator that tests for inequality.
Definition: DEMObject.cc:1139
update the slopes
Definition: DEMObject.h:61
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:41
DEMObject & operator+=(const double &rhs)
Definition: DEMObject.cc:1015
slope_type
Keywords for slope computation algorithm.
Definition: DEMObject.h:49
whatever algorithm that has been defined as default
Definition: DEMObject.h:50
double getHorizon(const size_t &ix1, const size_t &iy1, const double &bearing) const
Returns the tangente of the horizon from a given point looking toward a given bearing.
Definition: DEMObject.cc:434
A class to handle geographic coordinate systems. This class offers an easy way to transparently conve...
Definition: Coords.h:81
friend std::iostream & operator>>(std::iostream &is, DEMObject &dem)
Definition: DEMObject.cc:974
FORMATS
Keywords for selecting the toString formats.
Definition: DEMObject.h:67
Array2D< double > slope
Definition: DEMObject.h:41
Array2D< double > Nx
Definition: DEMObject.h:44
double min_altitude
Definition: DEMObject.h:45
const DEMObject operator/(const double &rhs) const
Definition: DEMObject.cc:1111
eight neighbor algorithm (Horn, 1981) as used by ArcGIS. It seems to be the same as (Corripio...
Definition: DEMObject.h:53
discretized azimuth directions (angles for N, NE, etc) and slope rounded to nearest integer ...
Definition: DEMObject.h:55
Array2D< double > Ny
Definition: DEMObject.h:44
void printFailures()
Prints the list of points that have an elevation different than nodata but no slope or curvature Such...
Definition: DEMObject.cc:320
Array2D< double > Nz
Definition: DEMObject.h:44
DEMObject & operator*=(const double &rhs)
Definition: DEMObject.cc:1075
update the normals
Definition: DEMObject.h:62
bool operator==(const DEMObject &in) const
Operator that tests for equality.
Definition: DEMObject.cc:1135
DEMObject & operator-=(const double &rhs)
Definition: DEMObject.cc:1045
A class to represent DEMs and automatically compute some properties. This class stores elevation grid...
Definition: DEMObject.h:39
friend std::iostream & operator<<(std::iostream &os, const DEMObject &dem)
Definition: DEMObject.cc:951
const DEMObject operator-(const double &rhs) const
Definition: DEMObject.cc:1051
void setDefaultAlgorithm(const slope_type &i_algorithm)
Sets the default slope calculation algorithm.
Definition: DEMObject.cc:276
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:37
const double PI
Definition: Meteoconst.h:71
double max_curvature
Definition: DEMObject.h:46
update_type
Keywords for automatic update of parameters. They can be combined with "|".
Definition: DEMObject.h:59
double getCellSkyViewFactor(const size_t &ii, const size_t &jj) const
Compute the sky view factors for the terrain radiation based on the DEM. This is based on Manners...
Definition: DEMObject.cc:512
double max_slope
Definition: DEMObject.h:46
const std::string toString() const
Definition: Grid2DObject.cc:430
DEMObject & operator=(const Grid2DObject &)
Assignement operator.
void updateAllMinMax()
Recomputes the min/max of altitude, slope and curvature It return +/- std::numeric_limits<double>\:\:...
Definition: DEMObject.cc:296
Array2D< double > azi
Definition: DEMObject.h:42
double bearing(std::string bearing_str)
Converts a string bearing to a compass bearing.
Definition: IOUtils.cc:70
double min_curvature
Definition: DEMObject.h:45
Grid2DObject getHillshade(const double &elev=38., const double &azimuth=0.) const
Computes the hillshade for the dem This "fake illumination" method is used to better show the relief ...
Definition: DEMObject.cc:398
Array2D< double > curvature
Definition: DEMObject.h:43
double max_altitude
Definition: DEMObject.h:46
void sanitize()
Clean up the DEM Object When computing the slope and curvature, it is possible to get points where th...
Definition: DEMObject.cc:368
Provide all the usually necessary information.
Definition: DEMObject.h:68
int getUpdatePpt() const
Get the properties that will be calculated by the object when updating.
Definition: DEMObject.cc:202