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