All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
36 {
37 }
38 
39 boost::numeric::ublas::matrix<double> te::sa::GeostatisticalMethodSemivariogram::calculate()
40 {
41  //increment tolerance will be 50% of the lag increment.
42  double incrementTolerance = m_lagIncrement / 2.;
43 
44  //define the minimum and maximum directions
45  double dirMin = 0.;
46  double dirMax = 0.;
47 
48  if(m_angleTolerance != 90.0)
49  {
50  dirMin = m_angleDirection - m_angleTolerance;
51  dirMax = m_angleDirection + m_angleTolerance;
52  }
53 
54  //set increment value
55  double incrementCount = 0.;
56 
57  //start aux vectors
58  std::vector<double> np, gam, dis;
59  np.resize(m_nLags, 0.);
60  gam.resize(m_nLags, 0.);
61  dis.resize(m_nLags, 0.);
62 
63  //calculate information for each lag
64  for(std::size_t lag = 0; lag < m_nLags; ++ lag)
65  {
66  incrementCount += m_lagIncrement;
67 
68  double minDistance = incrementCount - incrementTolerance;
69  double maxDistance = incrementCount + incrementTolerance;
70 
71  //fill matrix
72  for(std::size_t line = 0; line < m_dataMatrix.size1() - 1; ++line)
73  {
74  for(std::size_t column = 0; column < m_dataMatrix.size2() - 1; ++column)
75  {
76  if(m_angleTolerance == 90.0) //Omnidirectional
77  {
78  if(line < column && m_dataMatrix(line, column) > 0. && m_dataMatrix(line, column) <= incrementTolerance && lag == 0)
79  {
80  np[lag] = np[lag] + 1.;
81  dis[lag] = dis[lag] + m_dataMatrix(line, column);
82  gam[lag] = gam[lag] + ((m_dataMatrix(line, line) - m_dataMatrix(column, column)) * (m_dataMatrix(line, line) - m_dataMatrix(column, column)));
83  }
84  else if(line < column && m_dataMatrix(line, column) > minDistance && m_dataMatrix(line, column) <= maxDistance && lag != 0)
85  {
86  np[lag] = np[lag] + 1.;
87  dis[lag] = dis[lag] + m_dataMatrix(line, column);
88  gam[lag] = gam[lag] + ((m_dataMatrix(line, line) - m_dataMatrix(column, column)) * (m_dataMatrix(line, line) - m_dataMatrix(column, column)));
89  }
90  }
91  else //Directional
92  {
93  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)
94  {
95  np[lag] = np[lag] + 1.;
96  dis[lag] = dis[lag] + m_dataMatrix(line, column);
97  gam[lag] = gam[lag] + ((m_dataMatrix(line, line) - m_dataMatrix(column, column)) * (m_dataMatrix(line, line) - m_dataMatrix(column, column)));
98  }
99  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)
100  {
101  np[lag] = np[lag] + 1.;
102  dis[lag] = dis[lag] + m_dataMatrix(line, column);
103  gam[lag] = gam[lag] + ((m_dataMatrix(line, line) - m_dataMatrix(column, column)) * (m_dataMatrix(line, line) - m_dataMatrix(column, column)));
104  }
105  }
106  }
107  }
108  }
109 
110  //set output matrix
111  boost::numeric::ublas::matrix<double> matrix(m_nLags, 2);
112 
113  for(std::size_t lag = 0; lag < m_nLags; ++ lag)
114  {
115  if(np[lag] != 0)
116  {
117  dis[lag] = dis[lag] / np[lag];
118  gam[lag] = (gam[lag] / np[lag]) * .5;
119  }
120 
121  matrix(lag,0) = dis[lag];
122  matrix(lag,1) = gam[lag];
123  }
124 
125  return matrix;
126 }
virtual boost::numeric::ublas::matrix< double > calculate()
Function to calculate the geostatistical information.
This file contains a class that represents the geostatistical semivariogram method.
Geostatistics is used for modelling spatial data. It provides accurate and reliable estimations of ph...