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 
45 {
46 }
47 
49  : m_raster(r), m_time(t)
50 
51 {
52 
53  m_sextent.reset(te::gm::GetGeomFromEnvelope(m_raster->getGrid()->getExtent(), m_raster->getGrid()->getSRID()));
54 
55  for(std::size_t i=0; i<m_raster->getNumberOfBands(); ++i)
56  m_ptypes.push_back(m_raster->getBandDataType(i));
57 }
58 
60 {
61  m_raster.reset(r);
62  m_time.reset(t);
63  m_ptypes.clear();
64  m_pnames.clear();
65 
66  m_sextent.reset(te::gm::GetGeomFromEnvelope(m_raster->getGrid()->getExtent(), m_raster->getGrid()->getSRID()));
67 
68  for(std::size_t i=0; i<m_raster->getNumberOfBands(); ++i)
69  m_ptypes.push_back(m_raster->getBandDataType(i));
70 }
71 
73 {
74  return m_raster.get();
75 }
76 
78 {
79  return m_time.get();
80 }
81 
83 {
84  return new te::st::RasterCoverage( static_cast<te::rst::Raster*>(m_raster->clone()),
85  static_cast<te::dt::DateTime*>(m_time->clone()));
86 }
87 
89 {
90  return RASTER_COVERAGE;
91 }
92 
94 {
95  return m_sextent.get();
96 }
97 
99 {
100  return m_time.get();
101 }
102 
104 {
105  return static_cast<unsigned int>(m_raster->getNumberOfBands());
106 }
107 
108 const std::vector<int>& te::st::RasterCoverage::getPropertyTypes() const
109 {
110  return m_ptypes;
111 }
112 
113 const std::vector<std::string>& te::st::RasterCoverage::getPropertyNames() const
114 {
115  return m_pnames;
116 }
117 
118 void te::st::RasterCoverage::getValue(const te::gm::Point& l, boost::ptr_vector<te::dt::AbstractData>& result) const
119 {
120  std::vector<double> aux;
121  getDouble(l,aux);
122  for(unsigned int i = 0; i<aux.size(); ++i)
123  result.push_back(new te::dt::Double(aux[i]));
124  return;
125 }
126 
127 std::unique_ptr<te::dt::AbstractData> te::st::RasterCoverage::getValue(const te::gm::Point& l, unsigned int p) const
128 {
129  double result = getDouble(l,p);
130  return std::unique_ptr<te::dt::AbstractData>(new te::dt::Double(result));
131 }
132 
133 void te::st::RasterCoverage::getValue( const te::gm::Polygon& l, unsigned int p,
134  boost::ptr_vector<te::dt::AbstractData>& result) const
135 {
138  while(it!=itend)
139  {
140  double value = it[p];
141  result.push_back(new te::dt::Double(value));
142  ++it;
143  }
144  return;
145 }
146 
148  boost::ptr_vector<te::dt::AbstractData>& result) const
149 {
152  while(it!=itend)
153  {
154  std::vector<double> values = *it;
155  for(unsigned int i=0; i<values.size(); ++i)
156  result.push_back(new te::dt::Double(values[i]));
157  ++it;
158  }
159  return;
160 }
161 
162 void te::st::RasterCoverage::getInt(const te::gm::Point& l, std::vector<int>& result) const
163 {
164  std::vector<double> aux;
165  getDouble(l,aux);
166  for(unsigned int i = 0; i<aux.size(); ++i)
167  result.push_back((int)aux[i]);
168  return;
169 }
170 
171 int te::st::RasterCoverage::getInt(const te::gm::Point& l, unsigned int p) const
172 {
173  return (int)getDouble(l,p);
174 }
175 
176 void te::st::RasterCoverage::getInt(const te::gm::Polygon& l, unsigned int p, std::vector<int>& result) const
177 {
180  while(it!=itend)
181  {
182  result.push_back((int)it[p]);
183  ++it;
184  }
185  return;
186 }
187 
188 void te::st::RasterCoverage::getInt(const te::gm::Polygon& l, std::vector<int>& result) const
189 {
192  while(it!=itend)
193  {
194  std::vector<double> values = *it;
195  for(unsigned int i=0; i<values.size(); ++i)
196  result.push_back((int)values[i]);
197  ++it;
198  }
199  return;
200 }
201 
202 void te::st::RasterCoverage::getDouble(const te::gm::Point& l, std::vector<double>& result) const
203 {
204  te::gm::Coord2D coord = m_raster->getGrid()->geoToGrid(l.getX(), l.getY());
205  m_raster->getValues((unsigned int)coord.x, (unsigned int)coord.y, result);
206  return;
207 }
208 
209 double te::st::RasterCoverage::getDouble(const te::gm::Point& l, unsigned int p) const
210 {
211  te::gm::Coord2D coord = m_raster->getGrid()->geoToGrid(l.getX(), l.getY());
212  double result;
213  m_raster->getValue((unsigned int)coord.x, (unsigned int)coord.y, result, p);
214  return result;
215 }
216 
217 void te::st::RasterCoverage::getDouble(const te::gm::Polygon& l, unsigned int p, std::vector<double>& result) const
218 {
221  while(it!=itend)
222  {
223  result.push_back(it[p]);
224  ++it;
225  }
226  return;
227 }
228 
229 void te::st::RasterCoverage::getDouble(const te::gm::Polygon& l, std::vector<double>& result) const
230 {
233  while(it!=itend)
234  {
235  std::vector<double> values = *it;
236  for(unsigned int i=0; i<values.size(); ++i)
237  result.push_back(values[i]);
238  ++it;
239  }
240  return;
241 }
242 
243 std::unique_ptr<te::rst::Raster> te::st::RasterCoverage::getRaster() const
244 {
245  return std::unique_ptr<te::rst::Raster>(static_cast<te::rst::Raster*>(m_raster->clone()));
246 }
247 
248 std::unique_ptr<te::rst::Raster> te::st::RasterCoverage::getRaster(unsigned int /*p*/) const
249 {
250  //falta indicar a resolução do raster que será gerado, etc, etc...
251  return std::unique_ptr<te::rst::Raster>();
252 }
253 
double y
y-coordinate.
Definition: Coord2D.h:114
virtual ~RasterCoverage()
Virtual destructor.
double x
x-coordinate.
Definition: Coord2D.h:113
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.
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
std::vector< std::string > m_pnames
The types of the raster coverage properties.
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:152
A point with x and y coordinate values.
Definition: Point.h:50
An abstract class for raster data strucutures.
te::gm::Polygon * p
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A concrete class to represent a raster coverage.
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p, const IterationType iterationType)
Returns an iterator referring to the first value of the band.
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.
te::dt::DateTimeShrPtr m_time
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.
std::unique_ptr< te::gm::Geometry > m_sextent
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:138
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.
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.