All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IDWInterpolator.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 IDWInterpolator.cpp
22 
23  \brief This file contains an inverse distance weighted (IDW)
24  interpolationan function.
25 */
26 
27 // TerraLib
28 #include "../../../datatype/AbstractData.h"
29 #include "../../../datatype/SimpleData.h"
30 #include "../../../geometry/Point.h"
31 
32 // ST
33 #include "IDWInterpolator.h"
34 #include "../coverage/PointCoverage.h"
35 
37 {
38 }
39 
41 {
42 }
43 
44 std::auto_ptr<te::dt::AbstractData> te::st::IDWInterpolator::estimate(const te::st::PointCoverage& cv, unsigned int p, const te::gm::Point& l)
45 {
46  std::vector<double> di; //inverso da distancia ao quadrado ao ponto i: 1/(distance)2
47  std::vector<double> vi; //value associated to point i
48  double sumdi = 0.; //soma do inverso das distancias ao quadrado
49 
50  PointCoverageIterator it = cv.begin();
51  while(it!=cv.end())
52  {
53  te::gm::Point& point = it.getLocation();
54  double distance = point.distance(&l);
55  double d = 0.;
56  if(distance!=0.)
57  d = 1/(distance * distance); // 1/(distance)2
58  di.push_back(d);
59  sumdi += d;
60 
61  vi.push_back(it.getDouble(p));
62 
63  ++it;
64  }
65 
66  double result = 0.;
67  for(unsigned int i = 0; i< di.size(); ++i)
68  {
69  double wi = di[i]/sumdi;
70  result += vi[i]*wi;
71  }
72 
73  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Double(result));
74 }
75 
76 
A concrete class to represent a point coverage.
Definition: PointCoverage.h:70
PointCoverageIterator end() const
It returns an iterator that points to the end of the time series.
This file contains an inverse distance weighted (IDW) interpolationan function for PointCoverage...
std::auto_ptr< te::dt::AbstractData > estimate(const PointCoverage &cv, unsigned int p, const te::gm::Point &l)
It estimates a value at a given non-observed location, in a PointCoverage.
IDWInterpolator()
Constructor.
A class to traverse the observations of a PointCoverage.
A point with x and y coordinate values.
Definition: Point.h:50
virtual ~IDWInterpolator()
Virtual destructor.
double getDouble(int i) const
It returns the i-th attribute value as a double pointed by the internal cursor.
PointCoverageIterator begin() const
It returns an iterator that points to the first observation of the point coverage.
SimpleData< double, DOUBLE_TYPE > Double
Definition: SimpleData.h:227
te::gm::Point & getLocation() const
It returns the location pointed by the internal cursor.
virtual double distance(const Geometry *const rhs) const
It returns the shortest distance between any two points in the two geometry objects.
Definition: Geometry.cpp:453