All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VectorDataSet.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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/terralib4/VectorDataSet.cpp
22 
23  \brief Implementation of a dataset for the TerraLib 4 driver.
24 */
25 
26 // TerraLib
27 #include "../common/ByteSwapUtils.h"
28 #include "../common/Globals.h"
29 #include "../common/StringUtils.h"
30 #include "../common/Translator.h"
31 #include "../dataaccess/dataset/DataSetType.h"
32 #include "../datatype/Array.h"
33 #include "../datatype/ByteArray.h"
34 #include "../datatype/DateTimeProperty.h"
35 #include "../datatype/SimpleData.h"
36 #include "../datatype/TimeInstant.h"
37 #include "../geometry/Envelope.h"
38 #include "../geometry/Geometry.h"
39 #include "../geometry/GeometryProperty.h"
40 #include "../geometry/WKBReader.h"
41 #include "VectorDataSet.h"
42 #include "DataSource.h"
43 #include "Exception.h"
44 #include "GeomReader.h"
45 #include "Utils.h"
46 
47 // Terralib 4.x
48 #include <terralib/kernel/TeAttribute.h>
49 #include <terralib/kernel/TeDatabase.h>
50 #include <terralib/kernel/TeLayer.h>
51 
52 #include <terralib/kernel/TeQuerierParams.h>
53 
54 // STL
55 #include <cassert>
56 #include <memory>
57 
58 // Boost
59 #include <boost/dynamic_bitset.hpp>
60 #include <boost/lexical_cast.hpp>
61 
63  : m_dt(0),
64  m_querier(0),
65  m_i(-1),
66  m_size(-1),
67  m_nCols(-1),
68  m_geomCol(-1),
69  m_hasGeometry(false),
70  m_layer(layer)
71 {
72  TeQuerierParams params(true, true);
73  params.setParams(m_layer);
74 
75  m_querier = new TeQuerier(params);
76 
77  m_querier->loadInstances();
78 
79  m_nCols = m_querier->getAttrList().size();
80 
81  m_dt = new te::da::DataSetType(layer->name());
82 
83  for(int i = 0; i != m_nCols; ++i)
84  {
85  std::auto_ptr<te::dt::Property> p(terralib4::Convert2T5(m_querier->getAttrList()[i].rep_));
86 
87  m_dt->add(p.release());
88  }
89 
90  if((m_layer->hasGeometry(TePOLYGONS) ||
91  m_layer->hasGeometry(TeLINES) ||
92  m_layer->hasGeometry(TePOINTS) ||
93  m_layer->hasGeometry(TeNODES) ||
94  m_layer->hasGeometry(TeCELLS)))
95  {
96  te::gm::GeometryProperty* gp = new te::gm::GeometryProperty("spatial_data");
97 
98  m_dt->add(gp);
99 
100  m_geomCol = m_nCols;
101 
102  ++m_nCols;
103  }
104 
105 }
106 
108 {
109  delete m_querier;
110  delete m_dt;
111 }
112 
114 {
115  throw;
116 }
117 
119 {
120  throw;
121 }
122 
123 std::auto_ptr<te::gm::Envelope> terralib4::VectorDataSet::getExtent(std::size_t i)
124 {
125  return terralib4::Convert2T5(m_layer->box());
126 }
127 
129 {
130  return m_nCols;
131 }
132 
134 {
135  return m_dt->getProperty(i)->getType();
136 }
137 
138 std::string terralib4::VectorDataSet::getPropertyName(std::size_t i) const
139 {
140  /*TeAttributeList list = m_querier->getAttrList();
141  return list[i].rep_.name_();*/
142  throw;
143 }
144 
146 {
147  throw;
148 }
149 
151 {
152  return !(size() > 0);
153 }
154 
156 {
157  throw;
158 }
159 
161 {
162  return m_size;
163 }
164 
166 {
167  return m_querier->fetchInstance(m_instance);
168 }
169 
171 {
172  return false;
173 }
174 
176 {
177  return false;
178 }
179 
181 {
182  return false;
183 }
184 
186 {
187  return false;
188 }
189 
190 bool terralib4::VectorDataSet::move(std::size_t /*i*/)
191 {
192  return false;
193 }
194 
196 {
197  return false;
198 }
199 
201 {
202  return false;
203 }
204 
206 {
207  return false;
208 }
209 
211 {
212  return false;
213 }
214 
215 char terralib4::VectorDataSet::getChar(std::size_t i) const
216 {
217  throw;
218 }
219 
220 unsigned char terralib4::VectorDataSet::getUChar(std::size_t i) const
221 {
222  throw;
223 }
224 
225 boost::int16_t terralib4::VectorDataSet::getInt16(std::size_t i) const
226 {
227  std::string val;
228  int ii = static_cast<int>(i);
229  m_instance.getPropertyValue(val, ii);
230 
231  return boost::lexical_cast<boost::int16_t>(val);
232 }
233 
234 boost::int32_t terralib4::VectorDataSet::getInt32(std::size_t i) const
235 {
236  std::string val;
237  int ii = static_cast<int>(i);
238  m_instance.getPropertyValue(val, ii);
239 
240  return boost::lexical_cast<boost::int32_t>(val);
241 }
242 
243 boost::int64_t terralib4::VectorDataSet::getInt64(std::size_t i) const
244 {
245  std::string val;
246  int ii = static_cast<int>(i);
247  m_instance.getPropertyValue(val, ii);
248 
249  return boost::lexical_cast<boost::int64_t>(val);
250 }
251 
252 bool terralib4::VectorDataSet::getBool(std::size_t i) const
253 {
254  std::string val;
255  int ii = static_cast<int>(i);
256  m_instance.getPropertyValue(val, ii);
257 
258  return boost::lexical_cast<bool>(val);
259 }
260 
261 float terralib4::VectorDataSet::getFloat(std::size_t i) const
262 {
263  return (float)getDouble(i);
264 }
265 
266 double terralib4::VectorDataSet::getDouble(std::size_t i) const
267 {
268  std::string val;
269  int ii = static_cast<int>(i);
270  m_instance.getPropertyValue(val, ii);
271 
272  return boost::lexical_cast<double>(val);
273 }
274 
275 std::string terralib4::VectorDataSet::getNumeric(std::size_t i) const
276 {
277  std::string val;
278  int ii = static_cast<int>(i);
279 
280  m_instance.getPropertyValue(val, ii);
281 
282  return val;
283 }
284 
285 std::string terralib4::VectorDataSet::getString(std::size_t i) const
286 {
287  std::string val;
288  int ii = static_cast<int>(i);
289 
290  m_instance.getPropertyValue(val, ii);
291 
292  return val;
293 }
294 
295 std::auto_ptr<te::dt::ByteArray> terralib4::VectorDataSet::getByteArray(std::size_t i) const
296 {
297  /*unsigned char * data;
298  long size;
299  m_result->getBlob(m_result->getAttribute(i).rep_.name_, data, size);
300 
301  return std::auto_ptr<te::dt::ByteArray>(new te::dt::ByteArray((char*)data, size));*/
302  throw;
303 }
304 
305 std::auto_ptr<te::gm::Geometry> terralib4::VectorDataSet::getGeometry(std::size_t i) const
306 {
307  assert(i == m_geomCol);
308 
309  std::vector<TeGeometry*> geoms;
310  m_instance.getGeometry(geoms);
311 
312  std::auto_ptr<te::gm::Geometry> t5g(terralib4::GeomReader::getGeometry(*geoms[0]));
313 
314  t5g->setSRID(m_layer->projection()->epsgCode());
315 
316  return t5g;
317 }
318 
319 std::auto_ptr<te::rst::Raster> terralib4::VectorDataSet::getRaster(std::size_t i) const
320 {
321  throw;
322 }
323 
324 std::auto_ptr<te::dt::DateTime> terralib4::VectorDataSet::getDateTime(std::size_t i) const
325 {
326  //TeTime time = m_result->getDate(i);
327  //time.
328  throw;
329 }
330 
331 std::auto_ptr<te::dt::Array> terralib4::VectorDataSet::getArray(std::size_t i) const
332 {
333  return std::auto_ptr<te::dt::Array>(0);
334 }
335 
336 bool terralib4::VectorDataSet::isNull(std::size_t i) const
337 {
338  if(i == m_geomCol)
339  return false;
340 
341  if(getPropertyDataType(i) == te::dt::STRING_TYPE)
342  return false;
343 
344  std::string val;
345 
346  int ii = static_cast<int>(i);
347 
348  m_instance.getPropertyValue(val, ii);
349 
350  if(val.empty())
351  return true;
352 
353  return false;
354 }
bool getBool(std::size_t i) const
Method for retrieving a boolean attribute value.
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not...
int getPropertyDataType(std::size_t i) const
It returns the underlying data type of the property at position pos.
std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
double getDouble(std::size_t i) const
Method for retrieving a double attribute value.
bool moveNext()
It moves the internal pointer to the next item of the collection.
std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
std::auto_ptr< te::dt::Property > Convert2T5(const TeAttributeRep &attRep)
It creates a valid TerraLib 5 property given a valid TerraLib 4.x attribute representation.
Definition: Utils.cpp:52
An utility class for converting a TerraLib 4.x geometry to a TerraLib 5.
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
std::string getString(std::size_t i) const
Method for retrieving a string value attribute.
void add(Constraint *c)
It adds a new constraint.
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
bool isAfterEnd() const
It tells if the dataset internal pointer is on the sentinel position after the last element of the co...
unsigned char getUChar(std::size_t i) const
Method for retrieving an unsigned character attribute value (1 byte long).
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
std::auto_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
std::size_t size() const
It returns the collection size, if it is known.
std::string getNumeric(std::size_t i) const
Method for retrieving a numeric attribute value.
Utilitary functions for dealing with TerraLib 5 and 4.x conversion.
float getFloat(std::size_t i) const
Method for retrieving a float attribute value.
bool moveFirst()
It moves the internal pointer to the first item in the collection.
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
static std::auto_ptr< te::gm::Geometry > getGeometry(const TeGeometry &geom)
Definition: GeomReader.cpp:173
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
std::string getPropertyName(std::size_t i) const
It returns the property name at position pos.
Implements the DataSource class for the TerraLib 4.x Data Access Driver.
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
char getChar(std::size_t i) const
Method for retrieving a signed character attribute value (1 byte long).
std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
A class that models the description of a dataset.
Definition: DataSetType.h:72
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
boost::int64_t getInt64(std::size_t i) const
Method for retrieving a 64-bit integer attribute value (8 bytes long).
bool isEmpty() const
It returns true if the collection is empty.
std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
double getDouble(const std::string &value, std::vector< std::string > &sVector)
Definition: Utils.cpp:54
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
te::common::TraverseType getTraverseType() const
It returns the traverse type associated to the dataset.
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
te::da::DataSetType * m_dt
std::auto_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
bool isNull(std::size_t i) const
It checks if the attribute value is NULL.
Geometric property.
std::string getDatasetNameOfProperty(std::size_t i) const
It returns the underlying dataset name of the property at position pos.
VectorDataSet(TeLayer *layer)
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.