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