GeostatisticalMethodSemivariogram.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib 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,
8  or (at your option) any later version.
9 
10  TerraLib 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 TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/sa/core/GeostatisticalMethodSemivariogram.cpp
22 
23  \brief This file contains a class that represents the geostatistical semivariogram method.
24 
25  \reference Adapted from TerraLib4.
26 */
27 
28 //TerraLib Include
30 
32 {
33 }
34 
37 
38 boost::numeric::ublas::matrix<double> te::sa::GeostatisticalMethodSemivariogram::calculate()
39 {
40  //increment tolerance will be 50% of the lag increment.
41  double incrementTolerance = m_lagIncrement / 2.;
42 
43  //define the minimum and maximum directions
44  double dirMin = 0.;
45  double dirMax = 0.;
46 
47  if(m_angleTolerance != 90.0)
48  {
51  }
52 
53  //set increment value
54  double incrementCount = 0.;
55 
56  //start aux vectors
57  std::vector<double> np, gam, dis;
58  np.resize(m_nLags, 0.);
59  gam.resize(m_nLags, 0.);
60  dis.resize(m_nLags, 0.);
61 
62  //calculate information for each lag
63  for(std::size_t lag = 0; lag < m_nLags; ++ lag)
64  {
65  incrementCount += m_lagIncrement;
66 
67  double minDistance = incrementCount - incrementTolerance;
68  double maxDistance = incrementCount + incrementTolerance;
69 
70  //fill matrix
71  for(std::size_t line = 0; line < m_dataMatrix.size1() - 1; ++line)
72  {
73  for(std::size_t column = 0; column < m_dataMatrix.size2() - 1; ++column)
74  {
75  if(m_angleTolerance == 90.0) //Omnidirectional
76  {
77  if(line < column && m_dataMatrix(line, column) > 0. && m_dataMatrix(line, column) <= incrementTolerance && lag == 0)
78  {
79  np[lag] = np[lag] + 1.;
80  dis[lag] = dis[lag] + m_dataMatrix(line, column);
81  gam[lag] = gam[lag] + ((m_dataMatrix(line, line) - m_dataMatrix(column, column)) * (m_dataMatrix(line, line) - m_dataMatrix(column, column)));
82  }
83  else if(line < column && m_dataMatrix(line, column) > minDistance && m_dataMatrix(line, column) <= maxDistance && lag != 0)
84  {
85  np[lag] = np[lag] + 1.;
86  dis[lag] = dis[lag] + m_dataMatrix(line, column);
87  gam[lag] = gam[lag] + ((m_dataMatrix(line, line) - m_dataMatrix(column, column)) * (m_dataMatrix(line, line) - m_dataMatrix(column, column)));
88  }
89  }
90  else //Directional
91  {
92  if(line < column && m_dataMatrix(line, column) > 0. && m_dataMatrix(line, column) <= incrementTolerance && m_dataMatrix(column, line) >= dirMin && m_dataMatrix(column, line) <= dirMax && lag == 0)
93  {
94  np[lag] = np[lag] + 1.;
95  dis[lag] = dis[lag] + m_dataMatrix(line, column);
96  gam[lag] = gam[lag] + ((m_dataMatrix(line, line) - m_dataMatrix(column, column)) * (m_dataMatrix(line, line) - m_dataMatrix(column, column)));
97  }
98  else if(line < column && m_dataMatrix(line, column) > minDistance && m_dataMatrix(line, column) <= maxDistance && m_dataMatrix(column, line) >= dirMin && m_dataMatrix(column, line) <= dirMax && lag !=0)
99  {
100  np[lag] = np[lag] + 1.;
101  dis[lag] = dis[lag] + m_dataMatrix(line, column);
102  gam[lag] = gam[lag] + ((m_dataMatrix(line, line) - m_dataMatrix(column, column)) * (m_dataMatrix(line, line) - m_dataMatrix(column, column)));
103  }
104  }
105  }
106  }
107  }
108 
109  //set output matrix
110  boost::numeric::ublas::matrix<double> matrix(m_nLags, 2);
111 
112  for(std::size_t lag = 0; lag < m_nLags; ++ lag)
113  {
114  if(np[lag] != 0)
115  {
116  dis[lag] = dis[lag] / np[lag];
117  gam[lag] = (gam[lag] / np[lag]) * .5;
118  }
119 
120  matrix(lag,0) = dis[lag];
121  matrix(lag,1) = gam[lag];
122  }
123 
124  return matrix;
125 }
double m_lagIncrement
Attribute used to define the distance between each lag.
virtual boost::numeric::ublas::matrix< double > calculate()
Function to calculate the geostatistical information.
boost::numeric::ublas::matrix< double > m_dataMatrix
Matrix with input data information.
unsigned int line
std::size_t m_nLags
Attribute used to specifies the basic distance unit.
This file contains a class that represents the geostatistical semivariogram method.
double m_angleTolerance
Attribute used to define the minimum and maximum angular direction.
virtual ~GeostatisticalMethodSemivariogram()
Virtual destructor.
double m_angleDirection
Attribute used to define the direction used to calculate the variogram.