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  :
44 
45  m_interpolator(&IDWInterpolator::getInstance()),
46 
47  m_np(0),
48 
49  m_tp(-1)
50 {
51  //create the internal empty RTree
53 }
54 
56  te::gm::Geometry* sextent,
57  te::dt::DateTime* textent, int np,
58  const std::vector<int>& /*ptypes*/,
59  const std::vector<std::string>& /*pnames*/)
60  : m_sextent(sextent),
61  m_textent(textent),
62 
63  m_interpolator(interp),
64 
65  m_np(np),
66 
67  m_tp(-1)
68 {
69  //create the internal empty RTree
71 }
72 
74  te::gm::Geometry* sextent,
75  te::dt::DateTime* textent, int np,
76  const std::vector<int>& /*ptypes*/,
77  const std::vector<std::string>& /*pnames*/,
78  int tp)
79  : m_sextent(sextent),
80  m_textent(textent),
81 
82  m_interpolator(interp),
83 
84  m_np(np),
85 
86  m_tp(tp)
87 {
88  //create the internal empty RTree
90 }
91 
93 {
94  return PointCoverageIterator(m_observations.begin());
95 }
96 
98 {
100 }
101 
103 {
104  boost::ptr_vector<te::dt::AbstractData> aux;
105  aux.push_back(value);
106 
107  PointCoverageItem* item = new PointCoverageItem(l, aux);
108  PointCoverageObservation obs(item);
109  add(obs);
110 }
111 
112 void te::st::PointCoverage::add(const te::gm::Point& l, boost::ptr_vector<te::dt::AbstractData>& value)
113 {
114  PointCoverageItem* item = new PointCoverageItem(l, value);
115  PointCoverageObservation obs(item);
116  add(obs);
117 }
118 
120 {
121  m_observations.push_back(obs);
122  std::size_t p = m_observations.size()-1;
123 
124  //add to RTree
125  const te::gm::Envelope* env = obs->first.getMBR();
126  m_rTree->insert(*env, p);
127 }
128 
130 {
132  static_cast<te::gm::Geometry*>(m_sextent->clone()),
133  static_cast<te::dt::DateTime*>(m_textent->clone()), m_np,
134  m_ptypes, m_pnames);
135 
136  PointCoverageObservationSet::const_iterator it = m_observations.begin();
137  while(it!=m_observations.end())
138  {
139  PointCoverageItem* item = it->get();
140  std::unique_ptr< boost::ptr_vector<te::dt::AbstractData> > data(item->second.clone());
141  result->add(item->first, *data.release());
142  ++it;
143  }
144  return result;
145 }
146 
148 {
149  return POINT_COVERAGE;
150 }
151 
153 {
154  return m_sextent.get();
155 }
156 
158 {
159  return m_textent.get();
160 }
161 
163 {
164  return m_np;
165 }
166 
167 const std::vector<int>& te::st::PointCoverage::getPropertyTypes() const
168 {
169  return m_ptypes;
170 }
171 
172 const std::vector<std::string>& te::st::PointCoverage::getPropertyNames() const
173 {
174  return m_pnames;
175 }
176 
177 void te::st::PointCoverage::getValue(const te::gm::Point& l, boost::ptr_vector<te::dt::AbstractData>& result) const
178 {
179  for(unsigned int i = 0; i<m_np; ++i)
180  result.push_back(m_interpolator->estimate(*this,i,l).release());
181  return;
182 }
183 
184 std::unique_ptr<te::dt::AbstractData> te::st::PointCoverage::getValue(const te::gm::Point& l, unsigned int p) const
185 {
186  return std::unique_ptr<te::dt::AbstractData>(m_interpolator->estimate(*this,p,l));
187 }
188 
189 void te::st::PointCoverage::getValue( const te::gm::Polygon& /*l*/, unsigned int /*p*/,
190  boost::ptr_vector<te::dt::AbstractData>& /*result*/) const
191 {
192  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
193  //DESSE POLIGONO
194  return;
195 }
196 
198  boost::ptr_vector<te::dt::AbstractData>& /*result*/) const
199 {
200  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
201  //DESSE POLIGONO
202  return;
203 }
204 
205 void te::st::PointCoverage::getInt(const te::gm::Point& l, std::vector<int>& result) const
206 {
207  for(unsigned int i = 0; i<m_np; ++i)
208  {
209  std::unique_ptr<te::dt::AbstractData> aux = getValue(l,i);
210  result.push_back(atoi(aux->toString().c_str()));
211  }
212 }
213 
214 int te::st::PointCoverage::getInt(const te::gm::Point& l, unsigned int p) const
215 {
216  std::unique_ptr<te::dt::AbstractData> result = getValue(l,p);
217  return atoi(result->toString().c_str());
218 }
219 
220 void te::st::PointCoverage::getInt(const te::gm::Polygon& /*l*/, unsigned int /*p*/, std::vector<int>& /*result*/) const
221 {
222  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
223  //DESSE POLIGONO
224  return;
225 }
226 
227 void te::st::PointCoverage::getInt(const te::gm::Polygon& /*l*/, std::vector<int>& /*result*/) const
228 {
229  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
230  //DESSE POLIGONO
231  return;
232 }
233 
234 void te::st::PointCoverage::getDouble(const te::gm::Point& l, std::vector<double>& result) const
235 {
236  for(unsigned int i = 0; i<m_np; ++i)
237  {
238  std::unique_ptr<te::dt::AbstractData> aux = getValue(l,i);
239  result.push_back(atof(aux->toString().c_str()));
240  }
241 }
242 
243 double te::st::PointCoverage::getDouble(const te::gm::Point& l, unsigned int p) const
244 {
245  std::unique_ptr<te::dt::AbstractData> result = getValue(l,p);
246  return atof(result->toString().c_str());
247 }
248 
249 void te::st::PointCoverage::getDouble(const te::gm::Polygon& /*l*/, unsigned int /*p*/, std::vector<double>& /*result*/) const
250 {
251  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
252  //DESSE POLIGONO
253  return;
254 }
255 
256 void te::st::PointCoverage::getDouble(const te::gm::Polygon& /*l*/, std::vector<double>& /*result*/) const
257 {
258  //TEM QUE SETAR UMA RESOLUÇÃO/GRADE PARA PODER IDENTIFICAR UM CONJUNTO DE PONTOS DENTRO
259  //DESSE POLIGONO
260  return;
261 }
262 
263 std::unique_ptr<te::rst::Raster> te::st::PointCoverage::getRaster() const
264 {
265  //falta indicar a resolução do raster que ser?gerado, etc, etc...
266  return std::unique_ptr<te::rst::Raster>();
267 }
268 
269 std::unique_ptr<te::rst::Raster> te::st::PointCoverage::getRaster(unsigned int /*p*/) const
270 {
271  //falta indicar a resolução do raster que ser?gerado, etc, etc...
272  return std::unique_ptr<te::rst::Raster>();
273 }
274 
std::unique_ptr< te::dt::DateTime > m_textent
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.
unsigned int getNumberOfProperties() const
It returns the number of properties associated to the coverage.
virtual std::unique_ptr< te::dt::AbstractData > estimate(const PointCoverage &cv, unsigned int p, const te::gm::Point &l)=0
It estimates a value at a given non-observed location, in a PointCoverage.
CoverageType
An enum for the types of coverage.
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
std::unique_ptr< te::rst::Raster > getRaster() const
It returns a raster associated to the coverage.
AbstractPointCoverageInterp * m_interpolator
PointCoverageObservationSet m_observations
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.
te::gm::Polygon * p
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.
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.
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.
std::unique_ptr< te::gm::Geometry > m_sextent
This file contains a concrete class to represent a point coverage.
std::vector< std::string > m_pnames
The types of the point coverage properties.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
int m_tp
The names of the point coverage properties.
An abstract class to represent a coverage.
Definition: Coverage.h:63
std::vector< int > m_ptypes
The number of properties of the point coverage.
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.