All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PointCoverage.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 PointCoverage.cpp
22 
23  \brief This file contains an abstract class to represent a coverage.
24 */
25 
26 //TerraLib
27 #include "../../../datatype/DateTime.h"
28 #include "../../../datatype/AbstractData.h"
29 #include "../../../geometry/Geometry.h"
30 #include "../../../geometry/Point.h"
31 #include "../../../raster/Raster.h"
32 
33 //Boost
34 #include <boost/shared_ptr.hpp>
35 #include <boost/ptr_container/ptr_vector.hpp>
36 
37 //ST
38 #include "PointCoverage.h"
39 #include "../interpolator/AbstractPointCoverageInterp.h"
40 #include "../interpolator/IDWInterpolator.h"
41 
43  m_sextent(0),
44  m_textent(0),
45  m_observations(),
46  m_interpolator(&IDWInterpolator::getInstance()),
47  m_rTree(),
48  m_np(0),
49  m_ptypes(),
50  m_pnames(),
51  m_tp(-1)
52 {
53  //create the internal empty RTree
55 }
56 
58  te::dt::DateTime* textent, int np, const std::vector<int>& ptypes,
59  const std::vector<std::string>& pnames) :
60  m_sextent(sextent),
61  m_textent(textent),
62  m_observations(),
63  m_interpolator(interp),
64  m_rTree(),
65  m_np(np),
66  m_ptypes(),
67  m_pnames(),
68  m_tp(-1)
69 {
70  //create the internal empty RTree
72 }
73 
75  te::dt::DateTime* textent, int np, const std::vector<int>& ptypes,
76  const std::vector<std::string>& pnames, int tp) :
77  m_sextent(sextent),
78  m_textent(textent),
79  m_observations(),
80  m_interpolator(interp),
81  m_rTree(),
82  m_np(np),
83  m_ptypes(),
84  m_pnames(),
85  m_tp(tp)
86 {
87  //create the internal empty RTree
89 }
90 
92 {
93  return PointCoverageIterator(m_observations.begin());
94 }
95 
97 {
98  return PointCoverageIterator(m_observations.end());
99 }
100 
102 {
103  boost::ptr_vector<te::dt::AbstractData> aux;
104  aux.push_back(value);
105 
106  PointCoverageItem* item = new PointCoverageItem(l, aux);
107  PointCoverageObservation obs(item);
108  add(obs);
109 }
110 
111 void te::st::PointCoverage::add(const te::gm::Point& l, boost::ptr_vector<te::dt::AbstractData>& value)
112 {
113  PointCoverageItem* item = new PointCoverageItem(l, value);
114  PointCoverageObservation obs(item);
115  add(obs);
116 }
117 
119 {
120  m_observations.push_back(obs);
121  std::size_t p = m_observations.size()-1;
122 
123  //add to RTree
124  const te::gm::Envelope* env = obs->first.getMBR();
125  m_rTree->insert(*env, p);
126 }
127 
129 {
130  PointCoverage* result = new PointCoverage(m_interpolator,
131  static_cast<te::gm::Geometry*>(m_sextent->clone()),
132  static_cast<te::dt::DateTime*>(m_textent->clone()), m_np,
133  m_ptypes, m_pnames);
134 
135  PointCoverageObservationSet::const_iterator it = m_observations.begin();
136  while(it!=m_observations.end())
137  {
138  PointCoverageItem* item = it->get();
139  std::auto_ptr< boost::ptr_vector<te::dt::AbstractData> > data(item->second.clone());
140  result->add(item->first, *data.release());
141  ++it;
142  }
143  return result;
144 }
145 
147 {
148  return POINT_COVERAGE;
149 }
150 
152 {
153  return m_sextent.get();
154 }
155 
157 {
158  return m_textent.get();
159 }
160 
162 {
163  return m_np;
164 }
165 
166 const std::vector<int>& te::st::PointCoverage::getPropertyTypes() const
167 {
168  return m_ptypes;
169 }
170 
171 const std::vector<std::string>& te::st::PointCoverage::getPropertyNames() const
172 {
173  return m_pnames;
174 }
175 
176 void te::st::PointCoverage::getValue(const te::gm::Point& l, boost::ptr_vector<te::dt::AbstractData>& result) const
177 {
178  for(unsigned int i = 0; i<m_np; ++i)
179  result.push_back(m_interpolator->estimate(*this,i,l));
180  return;
181 }
182 
183 std::auto_ptr<te::dt::AbstractData> te::st::PointCoverage::getValue(const te::gm::Point& l, unsigned int p) const
184 {
185  return std::auto_ptr<te::dt::AbstractData>(m_interpolator->estimate(*this,p,l));
186 }
187 
188 void te::st::PointCoverage::getValue( const te::gm::Polygon& /*l*/, unsigned int /*p*/,
189  boost::ptr_vector<te::dt::AbstractData>& /*result*/) const
190 {
191  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
192  //DESSE POLIGONO
193  return;
194 }
195 
197  boost::ptr_vector<te::dt::AbstractData>& /*result*/) const
198 {
199  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
200  //DESSE POLIGONO
201  return;
202 }
203 
204 void te::st::PointCoverage::getInt(const te::gm::Point& l, std::vector<int>& result) const
205 {
206  for(unsigned int i = 0; i<m_np; ++i)
207  {
208  std::auto_ptr<te::dt::AbstractData> aux = getValue(l,i);
209  result.push_back(atoi(aux->toString().c_str()));
210  }
211 }
212 
213 int te::st::PointCoverage::getInt(const te::gm::Point& l, unsigned int p) const
214 {
215  std::auto_ptr<te::dt::AbstractData> result = getValue(l,p);
216  return atoi(result->toString().c_str());
217 }
218 
219 void te::st::PointCoverage::getInt(const te::gm::Polygon& /*l*/, unsigned int /*p*/, std::vector<int>& /*result*/) const
220 {
221  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
222  //DESSE POLIGONO
223  return;
224 }
225 
226 void te::st::PointCoverage::getInt(const te::gm::Polygon& /*l*/, std::vector<int>& /*result*/) const
227 {
228  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
229  //DESSE POLIGONO
230  return;
231 }
232 
233 void te::st::PointCoverage::getDouble(const te::gm::Point& l, std::vector<double>& result) const
234 {
235  for(unsigned int i = 0; i<m_np; ++i)
236  {
237  std::auto_ptr<te::dt::AbstractData> aux = getValue(l,i);
238  result.push_back(atof(aux->toString().c_str()));
239  }
240 }
241 
242 double te::st::PointCoverage::getDouble(const te::gm::Point& l, unsigned int p) const
243 {
244  std::auto_ptr<te::dt::AbstractData> result = getValue(l,p);
245  return atof(result->toString().c_str());
246 }
247 
248 void te::st::PointCoverage::getDouble(const te::gm::Polygon& /*l*/, unsigned int /*p*/, std::vector<double>& /*result*/) const
249 {
250  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
251  //DESSE POLIGONO
252  return;
253 }
254 
255 void te::st::PointCoverage::getDouble(const te::gm::Polygon& /*l*/, std::vector<double>& /*result*/) const
256 {
257  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
258  //DESSE POLIGONO
259  return;
260 }
261 
262 std::auto_ptr<te::rst::Raster> te::st::PointCoverage::getRaster() const
263 {
264  //falta indicar a resolução do raster que ser?gerado, etc, etc...
265  return std::auto_ptr<te::rst::Raster>();
266 }
267 
268 std::auto_ptr<te::rst::Raster> te::st::PointCoverage::getRaster(unsigned int /*p*/) const
269 {
270  //falta indicar a resolução do raster que ser?gerado, etc, etc...
271  return std::auto_ptr<te::rst::Raster>();
272 }
273 
275 {
276 }
277 
278 
279 
280 
281 
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.
PointCoverage()
A constructor.
A class that represents an R-tree.
Definition: Index.h:56
unsigned int getNumberOfProperties() const
It returns the number of properties associated to the coverage.
CoverageType
An enum for the types of coverage.
Definition: Enums.h:43
An abstract class for interpolation function or interpolator that estimate values at non-observaved l...
Coverage * clone() const
It returns a clone of this coverage.
const std::vector< int > & getPropertyTypes() const
It returns the types of the coverage properties.
virtual ~PointCoverage()
Virtual destructor.
std::pair< te::gm::Point, boost::ptr_vector< te::dt::AbstractData > > PointCoverageItem
PointCvRTreeShrPtr m_rTree
A class to traverse the observations of a PointCoverage.
boost::shared_ptr< PointCoverageItem > PointCoverageObservation
void add(const te::gm::Point &l, te::dt::AbstractData *value)
It adds an observtion to the PointCoverage.
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
void getInt(const te::gm::Point &l, std::vector< int > &result) const
It returns the values as integers associated to a given location.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
const std::vector< std::string > & getPropertyNames() const
It returns the names of the coverage properties.
A class that implements an inverse distance weighted (IDW) interpolationan function for PointCoverage...
CoverageType getType() const
It returns the coverage type.
std::auto_ptr< te::rst::Raster > getRaster() const
It returns a raster associated to the coverage.
void getValue(const te::gm::Point &l, boost::ptr_vector< te::dt::AbstractData > &result) const
It returns the values associated to a given location.
PointCoverageIterator begin() const
It returns an iterator that points to the first observation of the point coverage.
This file contains a concrete class to represent a point coverage.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
An abstract class to represent a coverage.
Definition: Coverage.h:63
te::dt::DateTime * getTime() const
It returns the time associated to the coverage.
void getDouble(const te::gm::Point &l, std::vector< double > &result) const
It returns the values as doubles associated to a given location.
te::gm::Geometry * getSpatialExtent() const
It returns the spatial extent of a coverage.