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/stmemory/DataSet.cpp
22 
23  \brief Implementation of a data set in memory that contains spatiotemporal observations indexed
24  by time and space.
25 */
26 
27 // TerraLib
28 #include "../common/STLUtils.h"
29 #include "../dataaccess/dataset/DataSetType.h"
30 #include "../dataaccess/utils/Utils.h"
31 #include "../datatype/ByteArray.h"
32 #include "../datatype/DataType.h"
33 #include "../datatype/Property.h"
34 #include "../datatype/SimpleData.h"
35 #include "../datatype/StringProperty.h"
36 #include "../datatype/Utils.h"
37 #include "../datatype/DateTimeUtils.h"
38 #include "../datatype/TimePeriod.h"
39 #include "../datatype/Date.h"
40 #include "../datatype/Enums.h"
41 #include "../geometry/Envelope.h"
42 #include "../geometry/Geometry.h"
43 #include "../geometry/GeometryProperty.h"
44 #include "../geometry/Utils.h"
45 #include "../memory/DataSetItem.h"
46 #include "../sam/rtree/Index.h"
47 
48 #include "DataSet.h"
49 #include "Exception.h"
50 
51 // STL
52 #include <limits>
53 
55  : m_items(),
56  m_RTree(),
57  m_iterator(),
58  m_beforeFirst(true),
59  m_pnames(),
60  m_ptypes(),
61  m_begTimePropIdx(tpPropIdx),
62  m_endTimePropIdx(-1),
63  m_geomPropIdx(-1)
64 {
66 
67  // Fill char-encodings
68  for(std::size_t i = 0; i < type->size(); ++i)
69  {
70  te::dt::StringProperty* p = dynamic_cast<te::dt::StringProperty*>(type->getProperty(i));
71  if(p != 0)
72  m_encodings[i] = p->getCharEncoding();
73  }
74 
75  //create the internal empty RTree
77 }
78 
79 te::stmem::DataSet::DataSet(const te::da::DataSetType* type, int tpPropIdx, int gmPropIdx)
80  : m_items(),
81  m_RTree(),
82  m_iterator(),
83  m_beforeFirst(true),
84  m_pnames(),
85  m_ptypes(),
86  m_begTimePropIdx(tpPropIdx),
87  m_endTimePropIdx(-1),
88  m_geomPropIdx(gmPropIdx)
89 {
91 
92  // Fill char-encodings
93  for(std::size_t i = 0; i < type->size(); ++i)
94  {
95  te::dt::StringProperty* p = dynamic_cast<te::dt::StringProperty*>(type->getProperty(i));
96  if(p != 0)
97  m_encodings[i] = p->getCharEncoding();
98  }
99 
100  //create the internal empty RTree
102 }
103 
104 te::stmem::DataSet::DataSet( const te::da::DataSetType* type, int begTimePropIdx,
105  int endTimePropIdx, int gmPropIdx)
106  : m_items(),
107  m_RTree(),
108  m_iterator(),
109  m_beforeFirst(true),
110  m_pnames(),
111  m_ptypes(),
112  m_begTimePropIdx(begTimePropIdx),
113  m_endTimePropIdx(endTimePropIdx),
114  m_geomPropIdx(gmPropIdx)
115 {
117 
118  // Fill char-encodings
119  for(std::size_t i = 0; i < type->size(); ++i)
120  {
121  te::dt::StringProperty* p = dynamic_cast<te::dt::StringProperty*>(type->getProperty(i));
122  if(p != 0)
123  m_encodings[i] = p->getCharEncoding();
124  }
125 
126  //create the internal empty RTree
128 }
129 
130 te::stmem::DataSet::DataSet(const std::vector<std::string>& pnames, const std::vector<int>& ptypes, const std::map<int, te::common::CharEncoding>& encodings,
131  int begTimePropIdx, int endTimePropIdx, int gmPropIdx)
132  : m_items(),
133  m_RTree(),
134  m_iterator(),
135  m_beforeFirst(true),
136  m_pnames(pnames),
137  m_ptypes(ptypes),
138  m_encodings(encodings),
139  m_begTimePropIdx(begTimePropIdx),
140  m_endTimePropIdx(endTimePropIdx),
141  m_geomPropIdx(gmPropIdx)
142 {
143  //create the internal empty RTree
145 }
146 
147 te::stmem::DataSet::DataSet(te::da::DataSet* ds, int tpPropIdx, int gmPropIdx, unsigned int limit)
148  : m_items(),
149  m_RTree(),
150  m_iterator(),
151  m_beforeFirst(true),
152  m_pnames(),
153  m_ptypes(),
154  m_begTimePropIdx(tpPropIdx),
155  m_endTimePropIdx(-1),
156  m_geomPropIdx(gmPropIdx)
157 {
159 
160  // Fill char-encodings
161  for(std::size_t i = 0; i < m_ptypes.size(); ++i)
162  if(m_ptypes[i] == te::dt::STRING_TYPE)
164 
165  //create the internal empty RTree
167 
168  //copy the items
169  copy(ds, limit);
170 }
171 
172 te::stmem::DataSet::DataSet(te::da::DataSet* ds, int begTimePropIdx, int endTimePropIdx, int gmPropIdx, unsigned int limit)
173  : m_items(),
174  m_RTree(),
175  m_iterator(),
176  m_beforeFirst(true),
177  m_pnames(),
178  m_ptypes(),
179  m_begTimePropIdx(begTimePropIdx),
180  m_endTimePropIdx(endTimePropIdx),
181  m_geomPropIdx(gmPropIdx)
182 {
184 
185  // Fill char-encodings
186  for(std::size_t i = 0; i < m_ptypes.size(); ++i)
187  if(m_ptypes[i] == te::dt::STRING_TYPE)
189 
190  //create the internal empty RTree
192 
193  //copy the items
194  copy(ds, limit);
195 }
196 
197 te::stmem::DataSet::DataSet(const DataSet& rhs, const bool deepCopy)
198  : m_items(),
199  m_RTree(),
200  m_iterator(),
201  m_beforeFirst(true),
202  m_pnames(rhs.m_pnames),
203  m_ptypes(rhs.m_ptypes),
204  m_encodings(rhs.m_encodings),
205  m_begTimePropIdx(rhs.m_begTimePropIdx),
206  m_endTimePropIdx(rhs.m_endTimePropIdx),
207  m_geomPropIdx(rhs.m_geomPropIdx)
208 {
209  //create the internal empty RTree
211 
212  TimeToDataSetItemMap::const_iterator it = rhs.m_items.begin();
213  while(it != rhs.m_items.end())
214  {
215  if(deepCopy)
216  //clone the DataSetItem
217  add(it->second->clone().release()); //add to m_items and m_RTree
218  else
219  add(*it); //add to m_items and m_RTree
220 
221  ++it;
222  }
223 }
224 
226 {
227  if (this != &other)
228  {
230  m_beforeFirst = true;
231  m_pnames = other.m_pnames;
232  m_ptypes = other.m_ptypes;
233  m_encodings = other.m_encodings;
234  m_begTimePropIdx = other.m_begTimePropIdx;
235  m_endTimePropIdx = other.m_endTimePropIdx;
236  m_geomPropIdx = other.m_geomPropIdx;
237 
238  m_items.clear();
239  TimeToDataSetItemMap::const_iterator it = other.m_items.begin();
240  while(it != other.m_items.end())
241  {
242  add(*it); //add to m_items and m_RTree
243  ++it;
244  }
245  }
246  return *this;
247 }
248 
250 {
251  //TO DO: verificar se está OK!!!
252  TimeToDataSetItemMap::iterator it = m_items.begin();
253  while(it!=m_items.end())
254  {
255  delete it->first; //Só apaga os DateTime
256  ++it;
257  }
258  m_items.clear();
259 }
260 
261 void te::stmem::DataSet::copy(te::da::DataSet* src, unsigned int limit)
262 {
263  std::vector<std::size_t> properties;
264 
265  const std::size_t np = src->getNumProperties();
266 
267  for(std::size_t i = 0; i != np; ++i)
268  properties.push_back(i);
269 
270  copy(src, properties, limit);
271 }
272 
273 void te::stmem::DataSet::copy(te::da::DataSet* src, const std::vector<std::size_t>& properties, unsigned int limit)
274 {
275  bool unlimited = true;
276 
277  if(limit == 0)
278  limit = std::numeric_limits<std::size_t>::max();
279  else
280  unlimited = false;
281 
282  unsigned int i = 0;
283 
284  do
285  {
286  std::auto_ptr<te::mem::DataSetItem> item(new te::mem::DataSetItem(this));
287 
288  for(std::size_t c = 0; c < properties.size(); ++c)
289  {
290  if(!src->isNull(properties[c]))
291  item->setValue(properties[c], src->getValue(properties[c]).release());
292  else
293  item->setValue(properties[c], 0);
294  }
295 
296  add(item.release());
297 
298  ++i;
299  //TODO: Verificar se ele está decrementando o apontador para "item" quando sai do escopo!!!
300  } while(src->moveNext() && (i < limit));
301 
302  if(!unlimited & (i < limit))
303  throw Exception("The source dataset has few items than requested copy limit!");
304 }
305 
307 {
308  return m_items;
309 }
310 
312 {
313  return m_geomPropIdx;
314 }
315 
317 {
318  return m_begTimePropIdx;
319 }
320 
322 {
323  return m_endTimePropIdx;
324 }
325 
326 void te::stmem::DataSet::add(const std::pair<te::dt::DateTime*, DateSetItemShrPtr>& p)
327 {
328  te::dt::DateTime* dt = static_cast<te::dt::DateTime*>(p.first->clone());
329  m_items.insert(std::pair<te::dt::DateTime*, DateSetItemShrPtr>(dt,p.second));
330 
331  //insert into the RTree
332  if(m_geomPropIdx<0)
333  return;
334 
335  std::auto_ptr<te::gm::Geometry> geom(p.second->getGeometry(m_geomPropIdx));
336  if(geom.get()!=0)
337  {
338  const te::gm::Envelope* env = geom->getMBR();
339  m_RTree->insert(*env, p.second.get());
340  }
341  return;
342 }
343 
345 {
346  DateSetItemShrPtr item(dsItem);
347 
348  //Get the phenomemon properties
349  std::auto_ptr<te::dt::DateTime> phBegTime;
350  if(m_begTimePropIdx>=0)
351  phBegTime = item->getDateTime(m_begTimePropIdx);
352 
353  std::auto_ptr<te::dt::DateTime> phEndTime;
354  if(m_endTimePropIdx>=0)
355  phEndTime = item->getDateTime(m_endTimePropIdx);
356 
357  //the phenomenon time is an instant
358  if(phBegTime.get()!=0 && phEndTime.get()==0)
359  {
360  std::pair<te::dt::DateTime*, DateSetItemShrPtr> p(phBegTime.get(),item);
361  add(p);
362  }
363  //the phenomenon time is a period. We have to build a period.
364  else if(phBegTime.get()!=0 && phEndTime.get()!=0)
365  {
366  std::auto_ptr<te::dt::DateTime> aux (te::dt::GetTimePeriod(static_cast<te::dt::DateTimeInstant*>(phBegTime.get()),
367  static_cast<te::dt::DateTimeInstant*>(phEndTime.get())));
368  std::pair<te::dt::DateTime*, DateSetItemShrPtr> p(aux.get(),item);
369  add(p);
370  }
371 
372  return;
373 }
374 
375 std::auto_ptr<te::dt::DateTimePeriod> te::stmem::DataSet::getTemporalExtent() const
376 {
377  if (m_items.empty())
378  {
379  te::dt::Date t(2000, 1, 1);
380  return std::auto_ptr<te::dt::DateTimePeriod>(te::dt::GetTemporalExtent(&t, &t));
381  }
382 
383  const te::dt::DateTime* tbegin = m_items.begin()->first;
384  const te::dt::DateTime* tend = m_items.rbegin()->first;
385  return std::auto_ptr<te::dt::DateTimePeriod>(te::dt::GetTemporalExtent(tbegin, tend));
386 }
387 
388 std::auto_ptr<te::stmem::DataSet> te::stmem::DataSet::clone() const
389 {
390  return std::auto_ptr<DataSet>(new te::stmem::DataSet(*this, true));
391 }
392 
393 std::auto_ptr<te::stmem::DataSet> te::stmem::DataSet::filter(const te::gm::Envelope* e, te::gm::SpatialRelation r) const
394 {
395  if(r!=te::gm::INTERSECTS)
396  return std::auto_ptr<te::stmem::DataSet>(0);
397 
398  std::vector<te::mem::DataSetItem*> report;
399  m_RTree->search(*e, report);
400 
401  std::auto_ptr<te::stmem::DataSet> result(new DataSet(m_pnames, m_ptypes, m_encodings, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
402 
403  for(unsigned int i=0; i<report.size(); ++i)
404  result->add(report[i]->clone().release());
405 
406  return result;
407 }
408 
409 std::auto_ptr<te::stmem::DataSet> te::stmem::DataSet::filter(const te::gm::Geometry* g, te::gm::SpatialRelation r) const
410 {
411  if(r!=te::gm::INTERSECTS)
412  return std::auto_ptr<te::stmem::DataSet>(0);
413 
414  std::vector<te::mem::DataSetItem*> report;
415  m_RTree->search(*g->getMBR(), report);
416 
417  std::auto_ptr<te::stmem::DataSet> result(new DataSet(m_pnames, m_ptypes, m_encodings, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
418 
419  for(unsigned int i=0; i<report.size(); ++i)
420  {
421  std::auto_ptr<te::gm::Geometry> geom(report[i]->getGeometry(m_geomPropIdx));
422  if(geom->intersects(g))
423  result->add(report[i]->clone().release());
424  }
425  return result;
426 }
427 
428 std::auto_ptr<te::stmem::DataSet> te::stmem::DataSet::filter(const te::dt::DateTime* dt, te::dt::TemporalRelation r) const
429 {
430  TimeToDataSetItemMap::const_iterator itb = m_items.end();
431  TimeToDataSetItemMap::const_iterator ite = m_items.end();
432 
433  std::auto_ptr<te::stmem::DataSet> result(new DataSet(m_pnames, m_ptypes, m_encodings, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
434  std::auto_ptr<te::dt::DateTime> dtaux(static_cast<te::dt::DateTime*>(dt->clone()));
435 
436  if(r==te::dt::AFTER) //2
437  {
438  itb = m_items.upper_bound(dtaux.get());
439  }
440  else if(r==(te::dt::AFTER | te::dt::EQUALS)) // 2 OU 8 = 10
441  {
442  itb = m_items.find(dtaux.get());
443  if(itb==m_items.end())
444  itb = m_items.upper_bound(dtaux.get());
445  }
446  else if(r==te::dt::BEFORE) // 1
447  {
448  itb = m_items.begin();
449  ite = m_items.find(dtaux.get());
450  if(ite==m_items.end())
451  ite = m_items.upper_bound(dtaux.get());
452  }
453  else if(r==(te::dt::BEFORE | te::dt::EQUALS)) // 1 OU 8 = 9
454  {
455  itb = m_items.begin();
456  ite = m_items.upper_bound(dtaux.get());
457  }
458  else if(r==te::dt::DURING) //4
459  {
460  std::auto_ptr<te::dt::DateTime> t1(static_cast<te::dt::DateTimePeriod*>(dtaux.get())->getInitialInstant());
461  std::auto_ptr<te::dt::DateTime> t2(static_cast<te::dt::DateTimePeriod*>(dtaux.get())->getFinalInstant());
462  itb = m_items.find(t1.get());
463  if(itb==m_items.end())
464  itb = m_items.upper_bound(t1.get());
465  ite = m_items.upper_bound(t2.get());
466  }
467  else if(r==te::dt::EQUALS) //8
468  {
469  std::pair<TimeToDataSetItemMap::const_iterator, TimeToDataSetItemMap::const_iterator> itPair;
470  itPair = m_items.equal_range(dtaux.get());
471  itb = itPair.first;
472  ite = itPair.second;
473  }
474 
475  while(itb!=ite)
476  {
477  result->add(*itb);
478  ++itb;
479  }
480  return result;
481 }
482 
483 std::auto_ptr<te::stmem::DataSet> te::stmem::DataSet::filter(const te::gm::Envelope* e, te::gm::SpatialRelation r,
484  const te::dt::DateTime* dt, te::dt::TemporalRelation tr) const
485 {
486  std::auto_ptr<te::stmem::DataSet> result1 = filter(e,r);
487  return result1->filter(dt, tr);
488 }
489 
490 std::auto_ptr<te::stmem::DataSet> te::stmem::DataSet::filter(const te::gm::Geometry* g, te::gm::SpatialRelation r,
491  const te::dt::DateTime* dt, te::dt::TemporalRelation tr) const
492 {
493  std::auto_ptr<te::stmem::DataSet> result1 = filter(g,r);
494  return result1->filter(dt, tr);
495 }
496 
497 std::auto_ptr<te::stmem::DataSet> te::stmem::DataSet::nearestObservations(const te::dt::DateTime* time, int n) const
498 {
499  TimeToDataSetItemMap::const_iterator itlower, itupper, itbegin, itend;
500  itbegin = m_items.begin();
501  itend = m_items.end();
502  std::auto_ptr<te::dt::DateTime> dtaux(static_cast<te::dt::DateTime*>(time->clone()));
503  itlower = m_items.lower_bound(dtaux.get());
504  itupper = m_items.upper_bound(dtaux.get());
505 
506  //We get n observations upper and n observations lower with their distance
507  std::multimap<long, TimeToDataSetItemMap::const_iterator> result;
508  int numObs = 0;
509  while(itlower!=itbegin && itlower!=itend && numObs<n)
510  {
511  long dist = GetDistance(itlower->first, time);
512  result.insert(std::pair<long, TimeToDataSetItemMap::const_iterator>(dist, itlower));
513  --itlower;
514  ++numObs;
515  }
516 
517  numObs = 0;
518  while(itupper!=itend && numObs<n)
519  {
520  long dist = GetDistance(itlower->first, time);
521  result.insert(std::pair<long, TimeToDataSetItemMap::const_iterator>(dist, itlower));
522  --itlower;
523  ++numObs;
524  }
525 
526  //After that, we get the first n observation of the result.
527  std::auto_ptr<te::stmem::DataSet> ds(new DataSet(m_pnames, m_ptypes, m_encodings, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
528  std::multimap<long, TimeToDataSetItemMap::const_iterator>::iterator it = result.begin();
529  numObs = 0;
530  while(it != result.end() && numObs<n)
531  {
532  ds->add(*it->second);
533  ++it;
534  ++numObs;
535  }
536 
537  return ds;
538 }
539 
541 {
543 }
544 
546 {
547  return te::common::RWAccess;
548 }
549 
551 {
552  return m_pnames.size();
553 }
554 
555 int te::stmem::DataSet::getPropertyDataType(std::size_t pos) const
556 {
557  return m_ptypes[pos];
558 }
559 
560 std::string te::stmem::DataSet::getPropertyName(std::size_t pos) const
561 {
562  return m_pnames[pos];
563 }
564 
566 {
567  std::map<int, te::common::CharEncoding>::const_iterator it = m_encodings.find(i);
568  assert(it != m_encodings.end());
569 
570  return it->second;
571 }
572 
573 std::string te::stmem::DataSet::getDatasetNameOfProperty(std::size_t /*pos*/) const
574 {
575  return "";
576 }
577 
579 {
580  return m_items.empty();
581 }
582 
584 {
585  return false;
586 }
587 
588 std::size_t te::stmem::DataSet::size() const
589 {
590  return m_items.size();
591 }
592 
593 std::auto_ptr<te::gm::Envelope> te::stmem::DataSet::getExtent(std::size_t i)
594 {
595  if(i==m_geomPropIdx)
596  return std::auto_ptr<te::gm::Envelope>(new te::gm::Envelope(m_RTree->getMBR()));
597 
598  std::auto_ptr<te::gm::Envelope> mbr(new te::gm::Envelope);
599 
600  TimeToDataSetItemMap::const_iterator it = m_items.begin();
601  while(it != m_items.end())
602  {
603  std::auto_ptr<te::gm::Geometry> geom(it->second->getGeometry(i));
604  mbr->Union(*(geom->getMBR()));
605  ++it;
606  }
607 
608  return mbr;
609 }
610 
612 {
613  if(m_beforeFirst)
614  return moveFirst();
615  m_iterator++;
616  return m_iterator != m_items.end();
617 }
618 
620 {
621  if(m_beforeFirst || m_iterator==m_items.begin())
622  return false;
623  --m_iterator;
624  return true;
625 }
626 
628 {
629  m_iterator = m_items.begin();
630  m_beforeFirst = false;
631  return m_iterator!=m_items.end();
632 }
633 
635 {
636  m_beforeFirst=true;
637  return true;
638 }
639 
641 {
642  m_iterator = m_items.end();
643  --m_iterator;
644  m_beforeFirst=false;
645  return true;
646 }
647 
648 bool te::stmem::DataSet::move(std::size_t i)
649 {
650  if(i>=m_items.size())
651  return false;
652 
653  m_iterator = m_items.begin();
654  std::size_t c = 0;
655  while(m_iterator!=m_items.end() && c < i)
656  {
657  ++m_iterator;
658  ++c;
659  }
660  return true;
661 }
662 
664 {
665  return m_iterator == m_items.begin();
666 }
667 
669 {
670  return m_beforeFirst;
671 }
672 
674 {
675  TimeToDataSetItemMap::const_iterator aux = m_items.end();
676  --aux;
677  return m_iterator==aux;
678 }
679 
681 {
682  return m_iterator == m_items.end();
683 }
684 
685 char te::stmem::DataSet::getChar(std::size_t i) const
686 {
687  return m_iterator->second->getChar(i);
688 }
689 
690 void te::stmem::DataSet::setChar(std::size_t i, char value)
691 {
692  m_iterator->second->setChar(i, value);
693 }
694 
695 void te::stmem::DataSet::setChar(const std::string& name, char value)
696 {
697  m_iterator->second->setChar(name, value);
698 }
699 
700 unsigned char te::stmem::DataSet::getUChar(std::size_t i) const
701 {
702  return m_iterator->second->getUChar(i);
703 }
704 
705 void te::stmem::DataSet::setUChar(std::size_t i, unsigned char value)
706 {
707  m_iterator->second->setUChar(i, value);
708 }
709 
710 void te::stmem::DataSet::setUChar(const std::string& name, unsigned char value)
711 {
712  m_iterator->second->setUChar(name, value);
713 }
714 
715 boost::int16_t te::stmem::DataSet::getInt16(std::size_t i) const
716 {
717  return m_iterator->second->getInt16(i);
718 }
719 
720 void te::stmem::DataSet::setInt16(std::size_t i, boost::int16_t value)
721 {
722  m_iterator->second->setInt16(i, value);
723 }
724 
725 void te::stmem::DataSet::setInt16(const std::string& name, boost::int16_t value)
726 {
727  m_iterator->second->setInt16(name, value);
728 }
729 
730 boost::int32_t te::stmem::DataSet::getInt32(std::size_t i) const
731 {
732  return m_iterator->second->getInt32(i);
733 }
734 
735 void te::stmem::DataSet::setInt32(std::size_t i, boost::int32_t value)
736 {
737  m_iterator->second->setInt32(i, value);
738 }
739 
740 void te::stmem::DataSet::setInt32(const std::string& name, boost::int32_t value)
741 {
742  m_iterator->second->setInt32(name, value);
743 }
744 
745 boost::int64_t te::stmem::DataSet::getInt64(std::size_t i) const
746 {
747  return m_iterator->second->getInt64(i);
748 }
749 
750 void te::stmem::DataSet::setInt64(std::size_t i, boost::int64_t value)
751 {
752  m_iterator->second->setInt64(i, value);
753 }
754 
755 void te::stmem::DataSet::setInt64(const std::string& name, boost::int64_t value)
756 {
757  m_iterator->second->setInt64(name, value);
758 }
759 
760 bool te::stmem::DataSet::getBool(std::size_t i) const
761 {
762  return m_iterator->second->getBool(i);
763 }
764 
765 void te::stmem::DataSet::setBool(std::size_t i, bool value)
766 {
767  m_iterator->second->setBool(i, value);
768 }
769 
770 void te::stmem::DataSet::setBool(const std::string& name, bool value)
771 {
772  m_iterator->second->setBool(name, value);
773 }
774 
775 float te::stmem::DataSet::getFloat(std::size_t i) const
776 {
777  return m_iterator->second->getFloat(i);
778 }
779 
780 void te::stmem::DataSet::setFloat(std::size_t i, float value)
781 {
782  m_iterator->second->setFloat(i, value);
783 }
784 
785 double te::stmem::DataSet::getDouble(std::size_t i) const
786 {
787  return m_iterator->second->getDouble(i);
788 }
789 
790 void te::stmem::DataSet::setDouble(std::size_t i, double value)
791 {
792  m_iterator->second->setDouble(i, value);
793 }
794 
795 void te::stmem::DataSet::setDouble(const std::string& name, double value)
796 {
797  m_iterator->second->setDouble(name, value);
798 }
799 
800 std::string te::stmem::DataSet::getNumeric(std::size_t i) const
801 {
802  return m_iterator->second->getNumeric(i);
803 }
804 
805 void te::stmem::DataSet::setNumeric(std::size_t i, const std::string& value)
806 {
807  m_iterator->second->setNumeric(i, value);
808 }
809 
810 void te::stmem::DataSet::setNumeric(const std::string& name, const std::string& value)
811 {
812  m_iterator->second->setNumeric(name, value);
813 }
814 
815 std::string te::stmem::DataSet::getString(std::size_t i) const
816 {
817  return m_iterator->second->getString(i);
818 }
819 
820 void te::stmem::DataSet::setString(std::size_t i, const std::string& value)
821 {
822  m_iterator->second->setString(i, value);
823 }
824 
825 void te::stmem::DataSet::setString(const std::string& name, const std::string& value)
826 {
827  m_iterator->second->setString(name, value);
828 }
829 
830 std::auto_ptr<te::dt::ByteArray> te::stmem::DataSet::getByteArray(std::size_t i) const
831 {
832  return std::auto_ptr<te::dt::ByteArray>(m_iterator->second->getByteArray(i));
833 }
834 
836 {
837  m_iterator->second->setByteArray(i, value);
838 }
839 
840 void te::stmem::DataSet::setByteArray(const std::string& name, te::dt::ByteArray* value)
841 {
842  m_iterator->second->setByteArray(name, value);
843 }
844 
845 std::auto_ptr<te::gm::Geometry> te::stmem::DataSet::getGeometry(std::size_t i) const
846 {
847  return m_iterator->second->getGeometry(i);
848 }
849 
851 {
852  m_iterator->second->setGeometry(i, value);
853 }
854 
855 void te::stmem::DataSet::setGeometry(const std::string& name, te::gm::Geometry* value)
856 {
857  m_iterator->second->setGeometry(name, value);
858 }
859 
860 std::auto_ptr<te::rst::Raster> te::stmem::DataSet::getRaster(std::size_t i) const
861 {
862  return m_iterator->second->getRaster(i);
863 }
864 
866 {
867  m_iterator->second->setRaster(i, value);
868 }
869 
870 void te::stmem::DataSet::setRaster(const std::string& name, te::rst::Raster* value)
871 {
872  m_iterator->second->setRaster(name, value);
873 }
874 
875 std::auto_ptr<te::dt::DateTime> te::stmem::DataSet::getDateTime(std::size_t i) const
876 {
877  return m_iterator->second->getDateTime(i);
878 }
879 
881 {
882  m_iterator->second->setDateTime(i, value);
883 }
884 
885 void te::stmem::DataSet::setDateTime(const std::string& name, te::dt::DateTime* value)
886 {
887  m_iterator->second->setDateTime(name, value);
888 }
889 
890 std::auto_ptr<te::dt::Array> te::stmem::DataSet::getArray(std::size_t i) const
891 {
892  return std::auto_ptr<te::dt::Array>(0);
893 }
894 
895 std::auto_ptr<te::dt::AbstractData> te::stmem::DataSet::getValue(std::size_t i) const
896 {
897  return m_iterator->second->getValue(i);
898 }
899 
901 {
902  m_iterator->second->setValue(i, ad);
903 }
904 
905 void te::stmem::DataSet::setValue(const std::string& name, te::dt::AbstractData* ad)
906 {
907  m_iterator->second->setValue(name, ad);
908 }
909 
910 bool te::stmem::DataSet::isNull(std::size_t i) const
911 {
912  return m_iterator->second->isNull(i);
913 }
914 
915 
916 
917 
918 
919 
Property * getProperty(std::size_t i) const
It returns the i-th property.
void setInt16(std::size_t i, boost::int16_t value)
Definition: DataSet.cpp:720
int getBeginTimePropIdx() const
It returns the index of the property that contains the beginning phenomenon time. ...
Definition: DataSet.cpp:316
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
Definition: DataSet.cpp:648
boost::shared_ptr< te::mem::DataSetItem > DateSetItemShrPtr
Definition: DataSet.h:49
TEDATATYPEEXPORT DateTimePeriod * GetTimePeriod(const DateTimeInstant *t1, const DateTimeInstant *t2)
It creates a time period based on two time instants.
void setByteArray(std::size_t i, te::dt::ByteArray *value)
Definition: DataSet.cpp:835
te::common::CharEncoding getCharEncoding() const
It returns the string property character encoding.
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
Definition: DataSet.cpp:715
CharEncoding
Supported charsets (character encoding).
~DataSet()
Destructor.
Definition: DataSet.cpp:249
te::common::CharEncoding getPropertyCharEncoding(std::size_t i) const
It returns the property character encoding at position pos.
Definition: DataSet.cpp:565
A class that represents an R-tree.
Definition: Index.h:56
A class that models the description of a dataset.
Definition: DataSetType.h:72
void setDouble(std::size_t i, double value)
Definition: DataSet.cpp:790
DataSet()
Default constructor.
Definition: DataSet.h:117
An exception class for the TerraLib ST memory driver.
void setGeometry(std::size_t i, te::gm::Geometry *value)
Definition: DataSet.cpp:850
TemporalRelation
Temporal relations between date and time (Source: Allen, 1991).
Definition: Enums.h:140
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
Definition: DataSet.cpp:673
void setChar(std::size_t i, char value)
Definition: DataSet.cpp:690
bool isNull(std::size_t i) const
It checks if the attribute value is NULL.
Definition: DataSet.cpp:910
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
void setInt64(std::size_t i, boost::int64_t value)
Definition: DataSet.cpp:750
TEDATATYPEEXPORT long GetDistance(const te::dt::DateTime *t1, const te::dt::DateTime *t2)
It returns the distance between two datetime types.
bool isEmpty() const
It returns true if the collection is empty.
Definition: DataSet.cpp:578
std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
Definition: DataSet.cpp:860
int m_endTimePropIdx
The property index of the DataSetType that contains the phenomenon end time.
Definition: DataSet.h:535
void setDateTime(std::size_t i, te::dt::DateTime *value)
Definition: DataSet.cpp:880
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:593
bool moveFirst()
It moves the internal pointer to the first item in the collection.
Definition: DataSet.cpp:627
void setInt32(std::size_t i, boost::int32_t value)
Definition: DataSet.cpp:735
void setValue(std::size_t i, te::dt::AbstractData *value)
Definition: DataSet.cpp:900
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
Definition: DataSet.cpp:830
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
int getPropertyDataType(std::size_t i) const
It returns the underlying data type of the property at position pos.
Definition: DataSet.cpp:555
void setBool(std::size_t i, bool value)
Definition: DataSet.cpp:765
std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
Definition: DataSet.cpp:895
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
A base class for date data types.
Definition: Date.h:53
int getEndTimePropIdx() const
It returns the index of the property that contains the end phenomenon time.
Definition: DataSet.cpp:321
An abstract class for raster data strucutures.
Definition: Raster.h:71
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
Definition: DataSet.cpp:634
std::auto_ptr< DataSet > filter(const te::gm::Envelope *e, te::gm::SpatialRelation r) const
It returns a new DataSet, based on a given spatial filter.
Definition: DataSet.cpp:393
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
virtual te::common::CharEncoding getPropertyCharEncoding(std::size_t i) const =0
It returns the property character encoding at position pos.
std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
Definition: DataSet.cpp:875
std::auto_ptr< te::stmem::DataSet > nearestObservations(const te::dt::DateTime *time, int n) const
It returns the n nearest observations to a given date and time.
Definition: DataSet.cpp:497
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
Definition: DataSet.cpp:583
bool getBool(std::size_t i) const
Method for retrieving a boolean attribute value.
Definition: DataSet.cpp:760
double getDouble(std::size_t i) const
Method for retrieving a double attribute value.
Definition: DataSet.cpp:785
std::multimap< te::dt::DateTime *, DateSetItemShrPtr, te::dt::CompareDateTime > TimeToDataSetItemMap
Definition: DataSet.h:51
std::string getPropertyName(std::size_t i) const
It returns the property name at position pos.
Definition: DataSet.cpp:560
te::common::TraverseType getTraverseType() const
It returns the traverse type associated to the dataset.
Definition: DataSet.cpp:540
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
std::auto_ptr< DataSet > clone() const
It returns a clone of the DataSet.
Definition: DataSet.cpp:388
The type for string types: FIXED_STRING, VAR_STRING or STRING.
char getChar(std::size_t i) const
Method for retrieving a signed character attribute value (1 byte long).
Definition: DataSet.cpp:685
std::size_t size() const
It returns the number of properties of the CompositeProperty.
void add(const std::pair< te::dt::DateTime *, DateSetItemShrPtr > &item)
It adds an existing item to the dataset.
Definition: DataSet.cpp:326
int m_begTimePropIdx
The property index of the DataSetType that contains the phenomenon beginning time.
Definition: DataSet.h:534
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
void setString(std::size_t i, const std::string &value)
Definition: DataSet.cpp:820
std::string getString(std::size_t i) const
Method for retrieving a string value attribute.
Definition: DataSet.cpp:815
std::size_t size() const
It returns the collection size, if it is known.
Definition: DataSet.cpp:588
Implementation of a in-memory data set that contains spatiotemporal observations indexed by time and ...
Definition: DataSet.h:61
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
Definition: DataSetItem.h:56
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
std::auto_ptr< te::dt::DateTimePeriod > getTemporalExtent() const
It returns the temporal extent of the observations.
Definition: DataSet.cpp:375
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
Definition: DataSet.cpp:668
std::vector< int > m_ptypes
The list of property types.
Definition: DataSet.h:532
Implementation of an in-memory data set that contains spatiotemporal observations indexed by time and...
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
Definition: DataSet.cpp:550
boost::int64_t getInt64(std::size_t i) const
Method for retrieving a 64-bit integer attribute value (8 bytes long).
Definition: DataSet.cpp:745
std::map< int, te::common::CharEncoding > m_encodings
The list of string properties char-encoding.
Definition: DataSet.h:533
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.
Definition: DataSet.cpp:640
std::string getNumeric(std::size_t i) const
Method for retrieving a numeric attribute value.
Definition: DataSet.cpp:800
bool moveNext()
It moves the internal pointer to the next item of the collection.
Definition: DataSet.cpp:611
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:680
TimeToDataSetItemMap m_items
The list of dataset items, ordered by time.
Definition: DataSet.h:527
int getGeomPropIdx() const
It returns the index of the property that contains the observed geometries.
Definition: DataSet.cpp:311
std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
Definition: DataSet.cpp:845
DataSet & operator=(const DataSet &rhs)
Assignment operator.
Definition: DataSet.cpp:225
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
Definition: DataSet.cpp:619
int m_geomPropIdx
The property index of the DataSetType that contains geometries.
Definition: DataSet.h:536
TEDATATYPEEXPORT DateTimePeriod * GetTemporalExtent(const DateTime *t1, const DateTime *t2)
It returns the temporal extent of two date and time types.
virtual AbstractData * clone() const =0
It returns a clone of this object.
void setFloat(std::size_t i, float value)
Definition: DataSet.cpp:780
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not...
Definition: DataSet.cpp:663
const TimeToDataSetItemMap & getData() const
It returns a reference to the internal observation set.
Definition: DataSet.cpp:306
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
Definition: DataSet.cpp:730
float getFloat(std::size_t i) const
Method for retrieving a float attribute value.
Definition: DataSet.cpp:775
void setRaster(std::size_t i, te::rst::Raster *value)
Definition: DataSet.cpp:865
void copy(te::da::DataSet *src, unsigned int limit=0)
It copies up to limit items from the source dataset.
Definition: DataSet.cpp:261
std::string getDatasetNameOfProperty(std::size_t i) const
It returns the underlying dataset name of the property at position pos.
Definition: DataSet.cpp:573
void setNumeric(std::size_t i, const std::string &value)
Definition: DataSet.cpp:805
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
Definition: Geometry.cpp:104
std::auto_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
Definition: DataSet.cpp:890
std::auto_ptr< te::sam::rtree::Index< te::mem::DataSetItem * > > m_RTree
A RTree index created over the default geometry property.
Definition: DataSet.h:528
std::vector< std::string > m_pnames
internal control
Definition: DataSet.h:531
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
Definition: DataSet.cpp:545
virtual std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
Definition: DataSet.cpp:151
unsigned char getUChar(std::size_t i) const
Method for retrieving an unsigned character attribute value (1 byte long).
Definition: DataSet.cpp:700
A class for representing binary data.
Definition: ByteArray.h:51
TEDATAACCESSEXPORT void GetPropertyInfo(const DataSetType *const dt, std::vector< std::string > &pnames, std::vector< int > &ptypes)
Definition: Utils.cpp:598
void setUChar(std::size_t i, unsigned char value)
Definition: DataSet.cpp:705