All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
NearestCoverageAtTimeInterp.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 NearestCoverageAtTimeInterp.cpp
22 
23  \brief This file contains an interpolation function that estimates the
24  nearest coverage at time.
25 */
26 
27 // TerraLib
28 #include "../../../datatype/DateTime.h"
29 #include "../../../datatype/DateTimeUtils.h"
30 
31 // ST
32 #include "../coverage/Coverage.h"
33 #include "../coverage/CoverageSeries.h"
35 
37 {
38 }
39 
41 {
42 }
43 
44 std::auto_ptr<te::st::Coverage>
46 {
47  CoverageSeriesObservationSet::const_iterator itlower, itupper, itbegin, itend;
48  const CoverageSeriesObservationSet& cvObs = cvs.getObservations();
49 
50  te::dt::DateTimeShrPtr dtshr(static_cast<te::dt::DateTime*>(time->clone()));
51  itlower = cvObs.lower_bound(dtshr);
52  itupper = cvObs.upper_bound(dtshr);
53 
54  //If both iterator points to the same position (the first element after dtshr), we have to get
55  //the first element before dtshr
56  if(itlower==itupper && itlower!=cvObs.begin())
57  --itlower;
58 
59  if(itlower!=cvObs.end() && itupper!=cvObs.end())
60  {
61  long distLower = GetDistance(itlower->first.get(),time);
62  long distUpper = GetDistance(itupper->first.get(),time);
63  if(distLower<distUpper)
64  return std::auto_ptr<te::st::Coverage>(itlower->second->clone());
65  else
66  return std::auto_ptr<te::st::Coverage>(itupper->second->clone());
67  }
68 
69  if(itlower!=cvObs.end() && itupper==cvObs.end())
70  return std::auto_ptr<te::st::Coverage>(itlower->second->clone());
71 
72  return std::auto_ptr<te::st::Coverage>(0);
73 }
74 
This file contains an interpolation function that returns the nearest coverage at time...
std::map< te::dt::DateTimeShrPtr, CoverageShrPtr, CompareShrDateTime > CoverageSeriesObservationSet
virtual ~NearestCoverageAtTimeInterp()
Virtual destructor.
TEDATATYPEEXPORT long GetDistance(const te::dt::DateTime *t1, const te::dt::DateTime *t2)
It returns the distance between two datetime types.
std::auto_ptr< Coverage > estimate(const CoverageSeries &cvs, te::dt::DateTime *time) const
It estimates a coverage of a coverage series at a given non-observed time .
boost::shared_ptr< DateTime > DateTimeShrPtr
Definition: DateTime.h:126
const CoverageSeriesObservationSet & getObservations() const
It returns the coverage series observations.
A class to represent a coverage series.
virtual AbstractData * clone() const =0
It returns a clone of this object.