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 
39 
40 std::unique_ptr<te::st::Coverage>
42 {
43  CoverageSeriesObservationSet::const_iterator itlower, itupper, itbegin, itend;
44  const CoverageSeriesObservationSet& cvObs = cvs.getObservations();
45 
46  te::dt::DateTimeShrPtr dtshr(static_cast<te::dt::DateTime*>(time->clone()));
47  itlower = cvObs.lower_bound(dtshr);
48  itupper = cvObs.upper_bound(dtshr);
49 
50  //If both iterator points to the same position (the first element after dtshr), we have to get
51  //the first element before dtshr
52  if(itlower==itupper && itlower!=cvObs.begin())
53  --itlower;
54 
55  if(itlower!=cvObs.end() && itupper!=cvObs.end())
56  {
57  long distLower = GetDistance(itlower->first.get(),time);
58  long distUpper = GetDistance(itupper->first.get(),time);
59  if(distLower<distUpper)
60  return std::unique_ptr<te::st::Coverage>(itlower->second->clone());
61  else
62  return std::unique_ptr<te::st::Coverage>(itupper->second->clone());
63  }
64 
65  if(itlower!=cvObs.end() && itupper==cvObs.end())
66  return std::unique_ptr<te::st::Coverage>(itlower->second->clone());
67 
68  return std::unique_ptr<te::st::Coverage>(nullptr);
69 }
70 
This file contains an interpolation function that returns the nearest coverage at time...
std::unique_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 .
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.
boost::shared_ptr< DateTime > DateTimeShrPtr
Definition: DateTime.h:126
const CoverageSeriesObservationSet & getObservations() const
It returns the coverage series observations.
virtual AbstractData * clone() const =0
It returns a clone of this object.
A class to represent a coverage series.