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" 
   62     m_begTimePropIdx(tpPropIdx),
 
   69   for(std::size_t i = 0; i < type->
size(); ++i)
 
   87     m_begTimePropIdx(tpPropIdx),
 
   89     m_geomPropIdx(gmPropIdx)
 
   94   for(std::size_t i = 0; i < type->
size(); ++i)
 
  106                              int endTimePropIdx, 
int gmPropIdx)
 
  113     m_begTimePropIdx(begTimePropIdx),
 
  114     m_endTimePropIdx(endTimePropIdx),
 
  115     m_geomPropIdx(gmPropIdx)
 
  120   for(std::size_t i = 0; i < type->
size(); ++i)
 
  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)
 
  139     m_encodings(encodings),
 
  140     m_begTimePropIdx(begTimePropIdx),
 
  141     m_endTimePropIdx(endTimePropIdx),
 
  142     m_geomPropIdx(gmPropIdx)
 
  155     m_begTimePropIdx(tpPropIdx),
 
  156     m_endTimePropIdx(-1),
 
  157     m_geomPropIdx(gmPropIdx)
 
  162   for(std::size_t i = 0; i < 
m_ptypes.size(); ++i)
 
  180     m_begTimePropIdx(begTimePropIdx),
 
  181     m_endTimePropIdx(endTimePropIdx),
 
  182     m_geomPropIdx(gmPropIdx)
 
  187   for(std::size_t i = 0; i < 
m_ptypes.size(); ++i)
 
  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)
 
  213   TimeToDataSetItemMap::const_iterator it = rhs.
m_items.begin();
 
  218       add(it->second->clone().release()); 
 
  231     m_beforeFirst = 
true;
 
  240     TimeToDataSetItemMap::const_iterator it = other.
m_items.begin();
 
  241     while(it != other.
m_items.end())
 
  253   TimeToDataSetItemMap::iterator it = m_items.begin();
 
  254   while(it!=m_items.end())
 
  264   std::vector<std::size_t> properties;
 
  268   for(std::size_t i = 0; i != np; ++i)
 
  269     properties.push_back(i);
 
  271   copy(src, properties, limit);
 
  276   bool unlimited = 
true;
 
  279      limit = std::numeric_limits<std::size_t>::max();
 
  289     for(std::size_t c = 0; c < properties.size(); ++c)
 
  291       if(!src->
isNull(properties[c]))
 
  292         item->setValue(properties[c], src->
getValue(properties[c]).release());
 
  294         item->setValue(properties[c], 0);
 
  301   } 
while(src->
moveNext() && (i < limit));
 
  303   if(!unlimited & (i < limit))
 
  304     throw Exception(
"The source dataset has few items than requested copy limit!");
 
  314   return m_geomPropIdx; 
 
  319   return m_begTimePropIdx; 
 
  324   return m_endTimePropIdx; 
 
  330   m_items.insert(std::pair<te::dt::DateTime*, DateSetItemShrPtr>(dt,p.second)); 
 
  336   std::auto_ptr<te::gm::Geometry> geom(p.second->getGeometry(m_geomPropIdx));
 
  340     m_RTree->insert(*env, p.second.get());
 
  350   std::auto_ptr<te::dt::DateTime> phBegTime;
 
  351   if(m_begTimePropIdx>=0)
 
  352     phBegTime = item->getDateTime(m_begTimePropIdx);
 
  354   std::auto_ptr<te::dt::DateTime> phEndTime;
 
  355   if(m_endTimePropIdx>=0)
 
  356     phEndTime = item->getDateTime(m_endTimePropIdx);
 
  359   if(phBegTime.get()!=0 && phEndTime.get()==0)
 
  361     std::pair<te::dt::DateTime*, DateSetItemShrPtr> p(phBegTime.get(),item);
 
  365   else if(phBegTime.get()!=0 && phEndTime.get()!=0)
 
  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);
 
  391     return std::auto_ptr<te::stmem::DataSet>(0);
 
  393   std::vector<te::mem::DataSetItem*> report;
 
  394   m_RTree->search(*e, report);
 
  396   std::auto_ptr<te::stmem::DataSet> result(
new DataSet(m_pnames, m_ptypes, m_encodings, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
 
  398   for(
unsigned int i=0; i<report.size(); ++i)
 
  399     result->add(report[i]->clone().release());
 
  407     return std::auto_ptr<te::stmem::DataSet>(0);
 
  409   std::vector<te::mem::DataSetItem*> report;
 
  410   m_RTree->search(*g->
getMBR(), report);
 
  412   std::auto_ptr<te::stmem::DataSet> result(
new DataSet(m_pnames, m_ptypes, m_encodings, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
 
  414   for(
unsigned int i=0; i<report.size(); ++i)
 
  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());
 
  425   TimeToDataSetItemMap::const_iterator itb = m_items.end();
 
  426   TimeToDataSetItemMap::const_iterator ite = m_items.end();
 
  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()));
 
  433     itb = m_items.upper_bound(dtaux.get());
 
  437     itb = m_items.find(dtaux.get());
 
  438     if(itb==m_items.end())
 
  439       itb = m_items.upper_bound(dtaux.get());
 
  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());
 
  450     itb = m_items.begin();
 
  451     ite = m_items.upper_bound(dtaux.get());   
 
  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()); 
 
  464     std::pair<TimeToDataSetItemMap::const_iterator, TimeToDataSetItemMap::const_iterator> itPair;
 
  465     itPair = m_items.equal_range(dtaux.get());
 
  481   std::auto_ptr<te::stmem::DataSet> result1 = filter(e,r);
 
  482   return result1->filter(dt, tr);
 
  488   std::auto_ptr<te::stmem::DataSet> result1 = filter(g,r);
 
  489   return result1->filter(dt, tr);
 
  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());
 
  502   std::multimap<long, TimeToDataSetItemMap::const_iterator> result;
 
  504   while(itlower!=itbegin && itlower!=itend && numObs<n)
 
  507     result.insert(std::pair<long, TimeToDataSetItemMap::const_iterator>(dist, itlower));
 
  513   while(itupper!=itend && numObs<n)
 
  516     result.insert(std::pair<long, TimeToDataSetItemMap::const_iterator>(dist, itlower));
 
  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();
 
  525   while(it != result.end() && numObs<n)
 
  527     ds->add(*it->second);
 
  547   return m_pnames.size();
 
  552   return m_ptypes[pos];
 
  557   return m_pnames[pos];
 
  562   std::map<int, te::common::CharEncoding>::const_iterator it = m_encodings.find(i);
 
  563   assert(it != m_encodings.end());
 
  575   return m_items.empty();
 
  585   return m_items.size();
 
  591     return std::auto_ptr<te::gm::Envelope>(
new te::gm::Envelope(m_RTree->getMBR()));
 
  595   TimeToDataSetItemMap::const_iterator it = m_items.begin();
 
  596   while(it != m_items.end())
 
  598     std::auto_ptr<te::gm::Geometry> geom(it->second->getGeometry(i));
 
  599     mbr->Union(*(geom->getMBR()));
 
  611   return m_iterator != m_items.end();
 
  616   if(m_beforeFirst || m_iterator==m_items.begin())
 
  624   m_iterator = m_items.begin();
 
  625   m_beforeFirst = 
false;
 
  626   return m_iterator!=m_items.end();
 
  637   m_iterator = m_items.end();
 
  645   if(i>=m_items.size())
 
  648   m_iterator = m_items.begin();
 
  650   while(m_iterator!=m_items.end() && c < i)
 
  660   return m_iterator == m_items.begin();
 
  665   return m_beforeFirst;
 
  670   TimeToDataSetItemMap::const_iterator aux = m_items.end();
 
  672   return m_iterator==aux;
 
  677   return m_iterator == m_items.end();
 
  682   return m_iterator->second->getChar(i);
 
  687   m_iterator->second->setChar(i, value);
 
  692   m_iterator->second->setChar(name, value);
 
  697   return m_iterator->second->getUChar(i);
 
  702   m_iterator->second->setUChar(i, value);
 
  707   m_iterator->second->setUChar(name, value);
 
  712   return m_iterator->second->getInt16(i);
 
  717   m_iterator->second->setInt16(i, value);
 
  722   m_iterator->second->setInt16(name, value);
 
  727   return m_iterator->second->getInt32(i);
 
  732   m_iterator->second->setInt32(i, value);
 
  737   m_iterator->second->setInt32(name, value);
 
  742   return m_iterator->second->getInt64(i);
 
  747   m_iterator->second->setInt64(i, value);
 
  752   m_iterator->second->setInt64(name, value);
 
  757   return m_iterator->second->getBool(i);
 
  762   m_iterator->second->setBool(i, value);
 
  767   m_iterator->second->setBool(name, value);
 
  772   return m_iterator->second->getFloat(i);
 
  777   m_iterator->second->setFloat(i, value);
 
  782   return m_iterator->second->getDouble(i);
 
  787   m_iterator->second->setDouble(i, value);
 
  792   m_iterator->second->setDouble(name, value);
 
  797   return m_iterator->second->getNumeric(i);
 
  802   m_iterator->second->setNumeric(i, value);
 
  807   m_iterator->second->setNumeric(name, value);
 
  812   return m_iterator->second->getString(i);
 
  817   m_iterator->second->setString(i, value);
 
  822   m_iterator->second->setString(name, value);
 
  827   return std::auto_ptr<te::dt::ByteArray>(m_iterator->second->getByteArray(i));
 
  832   m_iterator->second->setByteArray(i, value);
 
  837   m_iterator->second->setByteArray(name, value);
 
  842   return m_iterator->second->getGeometry(i);
 
  847   m_iterator->second->setGeometry(i, value);
 
  852   m_iterator->second->setGeometry(name, value);
 
  857   return m_iterator->second->getRaster(i);
 
  862   m_iterator->second->setRaster(i, value);
 
  867   m_iterator->second->setRaster(name, value);
 
  872   return m_iterator->second->getDateTime(i);
 
  877   m_iterator->second->setDateTime(i, value);
 
  882   m_iterator->second->setDateTime(name, value);
 
  887   return std::auto_ptr<te::dt::Array>(0);
 
  892   return m_iterator->second->getValue(i);
 
  897   m_iterator->second->setValue(i, ad);
 
  902   m_iterator->second->setValue(name, ad);
 
  907   return m_iterator->second->isNull(i);
 
Property * getProperty(std::size_t i) const 
It returns the i-th property. 
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. ...
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)
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). 
CharEncoding
Supported charsets (character encoding). 
te::common::CharEncoding getPropertyCharEncoding(std::size_t i) const 
It returns the property character encoding at position pos. 
A class that represents an R-tree. 
A class that models the description of a dataset. 
void setDouble(std::size_t i, double value)
DataSet()
Default constructor. 
An exception class for the TerraLib ST memory driver. 
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. 
std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const 
Method for retrieving a raster attribute value. 
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::auto_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset. 
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. 
AccessPolicy
Supported data access policies (can be used as bitfield). 
std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const 
Method for retrieving a byte array. 
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)
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. 
An Envelope defines a 2D rectangular region. 
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::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. 
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. 
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. 
bool isConnected() const 
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
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::common::TraverseType getTraverseType() const 
It returns the traverse type associated to the dataset. 
A base class for values that can be retrieved from the data access module. 
std::auto_ptr< DataSet > clone() const 
It returns a clone of the DataSet. 
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). 
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. 
int m_begTimePropIdx
The property index of the DataSetType that contains the phenomenon beginning time. 
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. 
void setString(std::size_t i, const std::string &value)
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. 
std::auto_ptr< te::dt::DateTimePeriod > getTemporalExtent() const 
It returns the temporal extent of the observations. 
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...
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). 
std::map< int, te::common::CharEncoding > m_encodings
The list of string properties char-encoding. 
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::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const 
Method for retrieving a geometric attribute value. 
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. 
virtual AbstractData * clone() const =0
It returns a clone of this object. 
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)
const Envelope * getMBR() const 
It returns the minimum bounding rectangle for the geometry in an internal representation. 
std::auto_ptr< te::dt::Array > getArray(std::size_t i) const 
Method for retrieving an array. 
std::auto_ptr< te::sam::rtree::Index< te::mem::DataSetItem * > > m_RTree
A RTree index created over the default geometry property. 
std::vector< std::string > m_pnames
internal control 
te::common::AccessPolicy getAccessPolicy() const 
It returns the read and write permission associated to the dataset. 
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. 
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. 
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)