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