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"
61 m_begTimePropIdx(tpPropIdx),
78 m_begTimePropIdx(tpPropIdx),
80 m_geomPropIdx(gmPropIdx)
89 int endTimePropIdx,
int gmPropIdx)
96 m_begTimePropIdx(begTimePropIdx),
97 m_endTimePropIdx(endTimePropIdx),
98 m_geomPropIdx(gmPropIdx)
107 int begTimePropIdx,
int endTimePropIdx,
int gmPropIdx)
114 m_begTimePropIdx(begTimePropIdx),
115 m_endTimePropIdx(endTimePropIdx),
116 m_geomPropIdx(gmPropIdx)
129 m_begTimePropIdx(tpPropIdx),
130 m_endTimePropIdx(-1),
131 m_geomPropIdx(gmPropIdx)
149 m_begTimePropIdx(begTimePropIdx),
150 m_endTimePropIdx(endTimePropIdx),
151 m_geomPropIdx(gmPropIdx)
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)
176 TimeToDataSetItemMap::const_iterator it = rhs.
m_items.begin();
181 add(it->second->clone().release());
194 m_beforeFirst =
true;
202 TimeToDataSetItemMap::const_iterator it = other.
m_items.begin();
203 while(it != other.
m_items.end())
215 TimeToDataSetItemMap::iterator it = m_items.begin();
216 while(it!=m_items.end())
226 std::vector<std::size_t> properties;
230 for(std::size_t i = 0; i != np; ++i)
231 properties.push_back(i);
233 copy(src, properties, limit);
238 bool unlimited =
true;
241 limit = std::numeric_limits<std::size_t>::max();
251 for(std::size_t c = 0; c < properties.size(); ++c)
253 if(!src->
isNull(properties[c]))
254 item->setValue(properties[c], src->
getValue(properties[c]).release());
256 item->setValue(properties[c], 0);
263 }
while(src->
moveNext() && (i < limit));
265 if(!unlimited & (i < limit))
266 throw Exception(
"The source dataset has few items than requested copy limit!");
276 return m_geomPropIdx;
281 return m_begTimePropIdx;
286 return m_endTimePropIdx;
292 m_items.insert(std::pair<te::dt::DateTime*, DateSetItemShrPtr>(dt,p.second));
298 std::auto_ptr<te::gm::Geometry> geom(p.second->getGeometry(m_geomPropIdx));
302 m_RTree->insert(*env, p.second.get());
312 std::auto_ptr<te::dt::DateTime> phBegTime;
313 if(m_begTimePropIdx>=0)
314 phBegTime = item->getDateTime(m_begTimePropIdx);
316 std::auto_ptr<te::dt::DateTime> phEndTime;
317 if(m_endTimePropIdx>=0)
318 phEndTime = item->getDateTime(m_endTimePropIdx);
321 if(phBegTime.get()!=0 && phEndTime.get()==0)
323 std::pair<te::dt::DateTime*, DateSetItemShrPtr> p(phBegTime.get(),item);
327 else if(phBegTime.get()!=0 && phEndTime.get()!=0)
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);
353 return std::auto_ptr<te::stmem::DataSet>(0);
355 std::vector<te::mem::DataSetItem*> report;
356 m_RTree->search(*e, report);
358 std::auto_ptr<te::stmem::DataSet> result(
new DataSet(m_pnames, m_ptypes, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
360 for(
unsigned int i=0; i<report.size(); ++i)
361 result->add(report[i]->clone().release());
369 return std::auto_ptr<te::stmem::DataSet>(0);
371 std::vector<te::mem::DataSetItem*> report;
372 m_RTree->search(*g->
getMBR(), report);
374 std::auto_ptr<te::stmem::DataSet> result(
new DataSet(m_pnames, m_ptypes, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
376 for(
unsigned int i=0; i<report.size(); ++i)
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());
387 TimeToDataSetItemMap::const_iterator itb = m_items.end();
388 TimeToDataSetItemMap::const_iterator ite = m_items.end();
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()));
395 itb = m_items.upper_bound(dtaux.get());
399 itb = m_items.find(dtaux.get());
400 if(itb==m_items.end())
401 itb = m_items.upper_bound(dtaux.get());
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());
412 itb = m_items.begin();
413 ite = m_items.upper_bound(dtaux.get());
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());
426 std::pair<TimeToDataSetItemMap::const_iterator, TimeToDataSetItemMap::const_iterator> itPair;
427 itPair = m_items.equal_range(dtaux.get());
443 std::auto_ptr<te::stmem::DataSet> result1 = filter(e,r);
444 return result1->filter(dt, tr);
450 std::auto_ptr<te::stmem::DataSet> result1 = filter(g,r);
451 return result1->filter(dt, tr);
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());
464 std::multimap<long, TimeToDataSetItemMap::const_iterator> result;
466 while(itlower!=itbegin && itlower!=itend && numObs<n)
469 result.insert(std::pair<long, TimeToDataSetItemMap::const_iterator>(dist, itlower));
475 while(itupper!=itend && numObs<n)
478 result.insert(std::pair<long, TimeToDataSetItemMap::const_iterator>(dist, itlower));
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();
487 while(it != result.end() && numObs<n)
489 ds->add(*it->second);
509 return m_pnames.size();
514 return m_ptypes[pos];
519 return m_pnames[pos];
529 return m_items.empty();
539 return m_items.size();
545 return std::auto_ptr<te::gm::Envelope>(
new te::gm::Envelope(m_RTree->getMBR()));
549 TimeToDataSetItemMap::const_iterator it = m_items.begin();
550 while(it != m_items.end())
552 std::auto_ptr<te::gm::Geometry> geom(it->second->getGeometry(i));
553 mbr->Union(*(geom->getMBR()));
565 return m_iterator != m_items.end();
570 if(m_beforeFirst || m_iterator==m_items.begin())
578 m_iterator = m_items.begin();
579 m_beforeFirst =
false;
580 return m_iterator!=m_items.end();
591 m_iterator = m_items.end();
599 if(i>=m_items.size())
602 m_iterator = m_items.begin();
604 while(m_iterator!=m_items.end() && c < i)
614 return m_iterator == m_items.begin();
619 return m_beforeFirst;
624 TimeToDataSetItemMap::const_iterator aux = m_items.end();
626 return m_iterator==aux;
631 return m_iterator == m_items.end();
636 return m_iterator->second->getChar(i);
641 m_iterator->second->setChar(i, value);
646 m_iterator->second->setChar(name, value);
651 return m_iterator->second->getUChar(i);
656 m_iterator->second->setUChar(i, value);
661 m_iterator->second->setUChar(name, value);
666 return m_iterator->second->getInt16(i);
671 m_iterator->second->setInt16(i, value);
676 m_iterator->second->setInt16(name, value);
681 return m_iterator->second->getInt32(i);
686 m_iterator->second->setInt32(i, value);
691 m_iterator->second->setInt32(name, value);
696 return m_iterator->second->getInt64(i);
701 m_iterator->second->setInt64(i, value);
706 m_iterator->second->setInt64(name, value);
711 return m_iterator->second->getBool(i);
716 m_iterator->second->setBool(i, value);
721 m_iterator->second->setBool(name, value);
726 return m_iterator->second->getFloat(i);
731 m_iterator->second->setFloat(i, value);
736 return m_iterator->second->getDouble(i);
741 m_iterator->second->setDouble(i, value);
746 m_iterator->second->setDouble(name, value);
751 return m_iterator->second->getNumeric(i);
756 m_iterator->second->setNumeric(i, value);
761 m_iterator->second->setNumeric(name, value);
766 return m_iterator->second->getString(i);
771 m_iterator->second->setString(i, value);
776 m_iterator->second->setString(name, value);
781 return std::auto_ptr<te::dt::ByteArray>(m_iterator->second->getByteArray(i));
786 m_iterator->second->setByteArray(i, value);
791 m_iterator->second->setByteArray(name, value);
796 return m_iterator->second->getGeometry(i);
801 m_iterator->second->setGeometry(i, value);
806 m_iterator->second->setGeometry(name, value);
811 return m_iterator->second->getRaster(i);
816 m_iterator->second->setRaster(i, value);
821 m_iterator->second->setRaster(name, value);
826 return m_iterator->second->getDateTime(i);
831 m_iterator->second->setDateTime(i, value);
836 m_iterator->second->setDateTime(name, value);
841 return std::auto_ptr<te::dt::Array>(0);
846 return m_iterator->second->getValue(i);
851 m_iterator->second->setValue(i, ad);
856 m_iterator->second->setValue(name, ad);
861 return m_iterator->second->isNull(i);
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.
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.
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not...
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.
TimeToDataSetItemMap m_items
The list of dataset items, ordered by time.
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
std::auto_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
int getBeginTimePropIdx() const
It returns the index of the property that contains the beginning phenomenon time. ...
void setNumeric(std::size_t i, const std::string &value)
Implementation of a in-memory data set that contains spatiotemporal observations indexed by time and ...
int getGeomPropIdx() const
It returns the index of the property that contains the observed geometries.
int getPropertyDataType(std::size_t i) const
It returns the underlying data type of the property at position pos.
std::auto_ptr< DataSet > clone() const
It returns a clone of the DataSet.
void setDouble(std::size_t i, double value)
void setRaster(std::size_t i, te::rst::Raster *value)
DataSet()
Default constructor.
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...
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.
std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
A class that represents an R-tree.
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
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).
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.
SpatialRelation
Spatial relations between geometric objects.
TEDATAACCESSEXPORT void GetPropertyInfo(const DataSetType *const dt, std::vector< std::string > &pnames, std::vector< int > &ptypes)
std::auto_ptr< te::sam::rtree::Index< te::mem::DataSetItem * > > m_RTree
A RTree index created over the default geometry property.
void setChar(std::size_t i, char value)
char getChar(std::size_t i) const
Method for retrieving a signed character attribute value (1 byte long).
AccessPolicy
Supported data access policies (can be used as bitfield).
bool isEmpty() const
It returns true if the collection is empty.
std::multimap< te::dt::DateTime *, DateSetItemShrPtr, te::dt::CompareDateTime > TimeToDataSetItemMap
void setInt16(std::size_t i, boost::int16_t value)
std::vector< std::string > m_pnames
internal control
void setGeometry(std::size_t i, te::gm::Geometry *value)
void setDateTime(std::size_t i, te::dt::DateTime *value)
DataSet & operator=(const DataSet &rhs)
Assignment operator.
std::auto_ptr< te::dt::DateTimePeriod > getTemporalExtent() const
It returns the temporal extent of the observations.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster 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.
const TimeToDataSetItemMap & getData() const
It returns a reference to the internal observation set.
TemporalRelation
Temporal relations between date and time (Source: Allen, 1991).
void setString(std::size_t i, const std::string &value)
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.
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
TraverseType
A dataset can be traversed in two ways:
void setBool(std::size_t i, bool value)
std::string getDatasetNameOfProperty(std::size_t i) const
It returns the underlying dataset name of the property at position pos.
int m_geomPropIdx
The property index of the DataSetType that contains geometries.
A base class for values that can be retrieved from the data access module.
bool moveNext()
It moves the internal pointer to the next item of the collection.
void add(const std::pair< te::dt::DateTime *, DateSetItemShrPtr > &item)
It adds an existing item to the dataset.
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
int m_begTimePropIdx
The property index of the DataSetType that contains the phenomenon beginning time.
void setInt32(std::size_t i, boost::int32_t value)
A class that models the description of a dataset.
std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
bool getBool(std::size_t i) const
Method for retrieving a boolean attribute value.
void setUChar(std::size_t i, unsigned char value)
void setInt64(std::size_t i, boost::int64_t value)
te::common::TraverseType getTraverseType() const
It returns the traverse type associated to the dataset.
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
float getFloat(std::size_t i) const
Method for retrieving a float attribute value.
void setByteArray(std::size_t i, te::dt::ByteArray *value)
std::string getString(std::size_t i) const
Method for retrieving a string value attribute.
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
An abstract class for raster data strucutures.
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.
int m_endTimePropIdx
The property index of the DataSetType that contains the phenomenon end time.
std::string getPropertyName(std::size_t i) const
It returns the property name at position pos.
std::size_t size() const
It returns the collection size, if it is known.
std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
boost::shared_ptr< te::mem::DataSetItem > DateSetItemShrPtr
void copy(te::da::DataSet *src, unsigned int limit=0)
It copies up to limit items from the source dataset.
void setFloat(std::size_t i, float value)
An Envelope defines a 2D rectangular region.
A class for representing binary data.
int getEndTimePropIdx() const
It returns the index of the property that contains the end phenomenon time.
boost::int64_t getInt64(std::size_t i) const
Method for retrieving a 64-bit integer attribute value (8 bytes long).
A dataset is the unit of information manipulated by the data access module of TerraLib.
std::string getNumeric(std::size_t i) const
Method for retrieving a numeric attribute value.
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.
bool isAfterEnd() const
It tells if the dataset internal pointer is on the sentinel position after the last element of the co...
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
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.
void setValue(std::size_t i, te::dt::AbstractData *value)
bool moveFirst()
It moves the internal pointer to the first item in the collection.