gdal/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::unique_ptr<te::da::DataSetType> dt,
40  te::common::AccessPolicy rwRole, std::string uri)
41  : m_dsType(std::move(dt)),
42  m_uri(uri),
43  m_rwRole(rwRole),
44  m_size(1),
45  m_i(-1)
46 {}
47 
48 te::gdal::DataSet::~DataSet() = default;
49 
50 void te::gdal::DataSet::setURI(const std::string& uri)
51 {
52  m_uri = uri;
53 }
54 
55 std::unique_ptr<te::gm::Envelope> te::gdal::DataSet::getExtent(std::size_t i)
56 {
58 
59  const te::rst::RasterProperty* rp = static_cast<const te::rst::RasterProperty*>(m_dsType->getProperty(i));
60 
61  const te::gm::Envelope* env = rp->getGrid()->getExtent();
62 
63  return std::unique_ptr<te::gm::Envelope>(new te::gm::Envelope(env->getLowerLeftX(), env->getLowerLeftY(),
64  env->getUpperRightX(), env->getUpperRightY()));
65 }
66 
68 {
69  return m_dsType->size();
70 }
71 
72 int te::gdal::DataSet::getPropertyDataType(std::size_t pos) const
73 {
74  return m_dsType->getProperty(pos)->getType();
75 }
76 
77 std::string te::gdal::DataSet::getPropertyName(std::size_t pos) const
78 {
79  return m_dsType->getProperty(pos)->getName();
80 }
81 
83  std::size_t /*pos*/) const
84 {
85  return "";
86 }
87 
88 std::unique_ptr<te::rst::Raster> te::gdal::DataSet::getRaster(std::size_t i) const
89 {
90  assert(i < getNumProperties());
92 
94 
95  return std::unique_ptr<te::rst::Raster>(rs);
96 }
97 
98 std::unique_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::unique_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 
162 {
163  return m_i > -1 && m_i < m_size;
164 }
165 
void setURI(const std::string &uri)
int getPropertyDataType(std::size_t pos) const
It returns the underlying data type of the property at position pos.
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
virtual ~DataSet()
Destructor.
int m_size
For GDAL driver this will be constant: 1.
Definition: gdal/DataSet.h:170
This class represents Raster data.
bool isPositionValid() const
It tells if the dataset internal pointer is on a valid position.
std::unique_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
DataSet()
Default constructor.
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
This is a class that represents a GDAL Raster.
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
Raster property.
std::string m_uri
Definition: gdal/DataSet.h:168
AccessPolicy
Supported data access policies (can be used as bitfield).
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
An Envelope defines a 2D rectangular region.
std::unique_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
int m_i
Just to indicate the internal pointer movement.
Definition: gdal/DataSet.h:171
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not...
std::string getDatasetNameOfProperty(std::size_t pos) const
It returns the underlying dataset name of the property at position pos.
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.
std::unique_ptr< te::da::DataSetType > m_dsType
It describes the dataset.
Definition: gdal/DataSet.h:167
std::string getPropertyName(std::size_t pos) const
It returns the property name at position pos.
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
bool isAfterEnd() const
It tells if the dataset internal pointer is on the sentinel position after the last element of the co...
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
bool moveNext()
It moves the internal pointer to the next item of the collection.
te::common::AccessPolicy m_rwRole
Access role.
Definition: gdal/DataSet.h:169