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