All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSet.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 terralib/gdal/DataSet.cpp
22 
23  \brief Implementation of a DataSet for GDAL data provider.
24 */
25 
26 // TerraLib
27 #include "../dataaccess/dataset/DataSetType.h"
28 #include "../datatype/Enums.h"
29 #include "../geometry/Envelope.h"
30 #include "../raster/RasterProperty.h"
31 #include "../raster/Grid.h"
32 #include "DataSet.h"
33 #include "Raster.h"
34 
35 // STL
36 #include <cassert>
37 #include <memory>
38 
39 te::gdal::DataSet::DataSet(std::auto_ptr<te::da::DataSetType> dt,
40  te::common::AccessPolicy rwRole, std::string uri)
41  : m_dsType(dt),
42  m_uri(uri),
43  m_rwRole(rwRole),
44  m_size(1),
45  m_i(-1)
46 {}
47 
49 {}
50 
51 void te::gdal::DataSet::setURI(const std::string& uri)
52 {
53  m_uri = uri;
54 }
55 
56 std::auto_ptr<te::gm::Envelope> te::gdal::DataSet::getExtent(std::size_t i)
57 {
58  assert(getPropertyDataType(i) == te::dt::RASTER_TYPE);
59 
60  const te::rst::RasterProperty* rp = static_cast<const te::rst::RasterProperty*>(m_dsType->getProperty(i));
61 
62  const te::gm::Envelope* env = rp->getGrid()->getExtent();
63 
64  return std::auto_ptr<te::gm::Envelope>(new te::gm::Envelope(env->getLowerLeftX(), env->getLowerLeftY(),
65  env->getUpperRightX(), env->getUpperRightY()));
66 }
67 
69 {
70  return m_dsType->size();
71 }
72 
73 int te::gdal::DataSet::getPropertyDataType(std::size_t pos) const
74 {
75  return m_dsType->getProperty(pos)->getType();
76 }
77 
78 std::string te::gdal::DataSet::getPropertyName(std::size_t pos) const
79 {
80  return m_dsType->getProperty(pos)->getName();
81 }
82 
83 std::string te::gdal::DataSet::getDatasetNameOfProperty(std::size_t pos) const
84 {
85  return "";
86 }
87 
88 std::auto_ptr<te::rst::Raster> te::gdal::DataSet::getRaster(std::size_t i) const
89 {
90  assert(i < getNumProperties());
91  assert(getPropertyDataType(i) == te::dt::RASTER_TYPE);
92 
93  te::gdal::Raster* rs = new te::gdal::Raster(m_uri, m_rwRole);
94 
95  return std::auto_ptr<te::rst::Raster>(rs);
96 }
97 
98 std::auto_ptr<te::rst::Raster> te::gdal::DataSet::getRaster(const std::string& name) const
99 {
100  std::size_t pos = m_dsType->getPropertyPosition(name);
101 
102  return std::auto_ptr<te::rst::Raster>(getRaster(pos));
103 }
104 
106 {
107  ++m_i;
108  return (m_i < m_size);
109 }
110 
112 {
113  --m_i;
114  return (m_i > -1);
115 }
116 
118 {
119  m_i = -1;
120  return (m_size != 0);
121 }
122 
124 {
125  m_i = 0;
126  return (m_size != 0);
127 }
128 
130 {
131  m_i = m_size - 1;
132  return (m_size != 0);
133 }
134 
135 bool te::gdal::DataSet::move(std::size_t i)
136 {
137  m_i = static_cast<int>(i);
138  return (m_i < m_size);
139 }
140 
142 {
143  return (m_i == 0);
144 }
145 
147 {
148  return (m_i < 0);
149 }
150 
152 {
153  return (m_i == (m_size - 1));
154 }
155 
157 {
158  return (m_i >= m_size);
159 }
160 
void setURI(const std::string &uri)
Definition: DataSet.cpp:51
This is a class that represents a GDAL Raster.
std::auto_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
Definition: DataSet.cpp:56
int getPropertyDataType(std::size_t pos) const
It returns the underlying data type of the property at position pos.
Definition: DataSet.cpp:73
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
Definition: DataSet.cpp:151
~DataSet()
Destructor.
Definition: DataSet.cpp:48
This class represents Raster data.
Definition: Raster.h:61
DataSet()
Default constructor.
Definition: DataSet.h:117
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:410
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
Definition: Envelope.h:400
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:420
std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
Definition: DataSet.cpp:88
Raster property.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
Definition: DataSet.cpp:146
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.
Definition: DataSet.cpp:129
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
Definition: DataSet.cpp:68
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
Definition: DataSet.cpp:111
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not...
Definition: DataSet.cpp:141
std::string getDatasetNameOfProperty(std::size_t pos) const
It returns the underlying dataset name of the property at position pos.
Definition: DataSet.cpp:83
te::rst::Grid * getGrid()
Returns the definition of the raster grid support.
bool moveFirst()
It moves the internal pointer to the first item in the collection.
Definition: DataSet.cpp:123
std::string getPropertyName(std::size_t pos) const
It returns the property name at position pos.
Definition: DataSet.cpp:78
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
Definition: DataSet.cpp:135
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
Definition: Envelope.h:390
bool isAfterEnd() const
It tells if the dataset internal pointer is on the sentinel position after the last element of the co...
Definition: DataSet.cpp:156
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
Definition: Grid.cpp:275
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
Definition: DataSet.cpp:117
bool moveNext()
It moves the internal pointer to the next item of the collection.
Definition: DataSet.cpp:105