All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RasterCoverage.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 RasterCoverage.cpp
22 
23  \brief This file contains an abstract class to represent a coverage.
24 */
25 
26 //TerraLib
27 #include "../../../datatype/AbstractData.h"
28 #include "../../../datatype/SimpleData.h"
29 #include "../../../geometry/Geometry.h"
30 #include "../../../geometry/Point.h"
31 #include "../../../geometry/Utils.h"
32 #include "../../../raster/RasterProperty.h"
33 #include "../../../raster/Grid.h"
34 #include "../../../raster/PositionIterator.h"
35 
36 //Boost
37 #include <boost/shared_ptr.hpp>
38 #include <boost/ptr_container/ptr_vector.hpp>
39 
40 //ST
41 #include "RasterCoverage.h"
42 
44  m_raster(),
45  m_time(),
46  m_sextent(),
47  m_ptypes(),
48  m_pnames()
49 {
50 }
51 
53  m_raster(r),
54  m_time(t),
55  m_sextent(),
56  m_ptypes(),
57  m_pnames()
58 {
59 
60  m_sextent.reset(te::gm::GetGeomFromEnvelope(m_raster->getGrid()->getExtent(), m_raster->getGrid()->getSRID()));
61 
62  for(std::size_t i=0; i<m_raster->getNumberOfBands(); ++i)
63  m_ptypes.push_back(m_raster->getBandDataType(i));
64 }
65 
67 {
68  m_raster.reset(r);
69  m_time.reset(t);
70  m_ptypes.clear();
71  m_pnames.clear();
72 
73  m_sextent.reset(te::gm::GetGeomFromEnvelope(m_raster->getGrid()->getExtent(), m_raster->getGrid()->getSRID()));
74 
75  for(std::size_t i=0; i<m_raster->getNumberOfBands(); ++i)
76  m_ptypes.push_back(m_raster->getBandDataType(i));
77 }
78 
80 {
81  return m_raster.get();
82 }
83 
85 {
86  return m_time.get();
87 }
88 
90 {
91  return new te::st::RasterCoverage( static_cast<te::rst::Raster*>(m_raster->clone()),
92  static_cast<te::dt::DateTime*>(m_time->clone()));
93 }
94 
96 {
97  return RASTER_COVERAGE;
98 }
99 
101 {
102  return m_sextent.get();
103 }
104 
106 {
107  return m_time.get();
108 }
109 
111 {
112  return m_raster->getNumberOfBands();
113 }
114 
115 const std::vector<int>& te::st::RasterCoverage::getPropertyTypes() const
116 {
117  return m_ptypes;
118 }
119 
120 const std::vector<std::string>& te::st::RasterCoverage::getPropertyNames() const
121 {
122  return m_pnames;
123 }
124 
125 void te::st::RasterCoverage::getValue(const te::gm::Point& l, boost::ptr_vector<te::dt::AbstractData>& result) const
126 {
127  std::vector<double> aux;
128  getDouble(l,aux);
129  for(unsigned int i = 0; i<aux.size(); ++i)
130  result.push_back(new te::dt::Double(aux[i]));
131  return;
132 }
133 
134 std::auto_ptr<te::dt::AbstractData> te::st::RasterCoverage::getValue(const te::gm::Point& l, unsigned int p) const
135 {
136  double result = getDouble(l,p);
137  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Double(result));
138 }
139 
140 void te::st::RasterCoverage::getValue( const te::gm::Polygon& l, unsigned int p,
141  boost::ptr_vector<te::dt::AbstractData>& result) const
142 {
145  while(it!=itend)
146  {
147  double value = it[p];
148  result.push_back(std::auto_ptr<te::dt::AbstractData> (new te::dt::Double(value)));
149  ++it;
150  }
151  return;
152 }
153 
155  boost::ptr_vector<te::dt::AbstractData>& result) const
156 {
159  while(it!=itend)
160  {
161  std::vector<double> values = *it;
162  for(unsigned int i=0; i<values.size(); ++i)
163  result.push_back(std::auto_ptr<te::dt::AbstractData> (new te::dt::Double(values[i])));
164  ++it;
165  }
166  return;
167 }
168 
169 void te::st::RasterCoverage::getInt(const te::gm::Point& l, std::vector<int>& result) const
170 {
171  std::vector<double> aux;
172  getDouble(l,aux);
173  for(unsigned int i = 0; i<aux.size(); ++i)
174  result.push_back((int)aux[i]);
175  return;
176 }
177 
178 int te::st::RasterCoverage::getInt(const te::gm::Point& l, unsigned int p) const
179 {
180  return (int)getDouble(l,p);
181 }
182 
183 void te::st::RasterCoverage::getInt(const te::gm::Polygon& l, unsigned int p, std::vector<int>& result) const
184 {
187  while(it!=itend)
188  {
189  result.push_back((int)it[p]);
190  ++it;
191  }
192  return;
193 }
194 
195 void te::st::RasterCoverage::getInt(const te::gm::Polygon& l, std::vector<int>& result) const
196 {
199  while(it!=itend)
200  {
201  std::vector<double> values = *it;
202  for(unsigned int i=0; i<values.size(); ++i)
203  result.push_back((int)values[i]);
204  ++it;
205  }
206  return;
207 }
208 
209 void te::st::RasterCoverage::getDouble(const te::gm::Point& l, std::vector<double>& result) const
210 {
211  te::gm::Coord2D coord = m_raster->getGrid()->geoToGrid(l.getX(), l.getY());
212  m_raster->getValues((unsigned int)coord.x, (unsigned int)coord.y, result);
213  return;
214 }
215 
216 double te::st::RasterCoverage::getDouble(const te::gm::Point& l, unsigned int p) const
217 {
218  te::gm::Coord2D coord = m_raster->getGrid()->geoToGrid(l.getX(), l.getY());
219  double result;
220  m_raster->getValue((unsigned int)coord.x, (unsigned int)coord.y, result, p);
221  return result;
222 }
223 
224 void te::st::RasterCoverage::getDouble(const te::gm::Polygon& l, unsigned int p, std::vector<double>& result) const
225 {
228  while(it!=itend)
229  {
230  result.push_back(it[p]);
231  ++it;
232  }
233  return;
234 }
235 
236 void te::st::RasterCoverage::getDouble(const te::gm::Polygon& l, std::vector<double>& result) const
237 {
240  while(it!=itend)
241  {
242  std::vector<double> values = *it;
243  for(unsigned int i=0; i<values.size(); ++i)
244  result.push_back(values[i]);
245  ++it;
246  }
247  return;
248 }
249 
250 std::auto_ptr<te::rst::Raster> te::st::RasterCoverage::getRaster() const
251 {
252  return std::auto_ptr<te::rst::Raster>(static_cast<te::rst::Raster*>(m_raster->clone()));
253 }
254 
255 std::auto_ptr<te::rst::Raster> te::st::RasterCoverage::getRaster(unsigned int /*p*/) const
256 {
257  //falta indicar a resolução do raster que será gerado, etc, etc...
258  return std::auto_ptr<te::rst::Raster>();
259 }
260 
262 {
263 }
264 
265 
266 
267 
double y
y-coordinate.
Definition: Coord2D.h:114
virtual ~RasterCoverage()
Virtual destructor.
double x
x-coordinate.
Definition: Coord2D.h:113
double getDouble(const std::string &value, std::vector< std::string > &sVector)
Definition: Utils.cpp:179
This file contains a concrete class to represent a raster coverage.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
CoverageType
An enum for the types of coverage.
Definition: Enums.h:43
void set(te::rst::Raster *r, te::dt::DateTime *t)
It sets the raster and its associated datetime.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
const std::vector< std::string > & getPropertyNames() const
It returns the names of the coverage properties.
void getDouble(const te::gm::Point &l, std::vector< double > &result) const
It returns the values as doubles associated to a given location.
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
const double & getY() const
It returns the Point y-coordinate value.
Definition: Point.h:150
A point with x and y coordinate values.
Definition: Point.h:50
An abstract class for raster data strucutures.
Definition: Raster.h:71
std::auto_ptr< te::gm::Geometry > m_sextent
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
A concrete class to represent a raster coverage.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
void getInt(const te::gm::Point &l, std::vector< int > &result) const
It returns the values as integers associated to a given location.
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to the first value of the band.
SimpleData< double, DOUBLE_TYPE > Double
Definition: SimpleData.h:227
void getValue(const te::gm::Point &l, boost::ptr_vector< te::dt::AbstractData > &result) const
It returns the values associated to a given location.
An abstract class to represent a coverage.
Definition: Coverage.h:63
te::dt::DateTime * getTime()
It returns the time.
A template for atomic data types (integers, floats, strings and others).
Definition: SimpleData.h:59
RasterCoverage()
A constructor.
te::rst::RasterPtr m_raster
unsigned int getNumberOfProperties() const
It returns the number of properties associated to the coverage.
Coverage * clone() const
It returns a clone of this coverage.
te::rst::Raster * getRaster()
It returns the raster.
const double & getX() const
It returns the Point x-coordinate value.
Definition: Point.h:136
const std::vector< int > & getPropertyTypes() const
It returns the types of the coverage properties.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
Definition: Utils.cpp:38
std::vector< int > m_ptypes
CoverageType getType() const
It returns the coverage type.
te::gm::Geometry * getSpatialExtent() const
It returns the spatial extent of a coverage.