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 
39 
40 std::unique_ptr<te::dt::AbstractData> te::st::IDWInterpolator::estimate(const te::st::PointCoverage& cv, unsigned int p, const te::gm::Point& l)
41 {
42  std::vector<double> di; //inverso da distancia ao quadrado ao ponto i: 1/(distance)2
43  std::vector<double> vi; //value associated to point i
44  double sumdi = 0.; //soma do inverso das distancias ao quadrado
45 
46  PointCoverageIterator it = cv.begin();
47  while(it!=cv.end())
48  {
49  te::gm::Point& point = it.getLocation();
50  double distance = point.distance(&l);
51  double d = 0.;
52  if(distance!=0.)
53  d = 1/(distance * distance); // 1/(distance)2
54  di.push_back(d);
55  sumdi += d;
56 
57  vi.push_back(it.getDouble(p));
58 
59  ++it;
60  }
61 
62  double result = 0.;
63  for(unsigned int i = 0; i< di.size(); ++i)
64  {
65  double wi = di[i]/sumdi;
66  result += vi[i]*wi;
67  }
68 
69  return std::unique_ptr<te::dt::AbstractData>(new te::dt::Double(result));
70 }
71 
72 
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.
virtual double distance(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns the shortest distance between any two points in the two geometry objects.
std::unique_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.
This file contains an inverse distance weighted (IDW) interpolationan function for 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.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
static te::dt::Date di(2010, 06, 10)
te::gm::Polygon * p
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.