28 #include "../common/STLUtils.h"
29 #include "../dataaccess/dataset/DataSetType.h"
30 #include "../dataaccess/utils/Utils.h"
31 #include "../datatype/ByteArray.h"
32 #include "../datatype/DataType.h"
33 #include "../datatype/Property.h"
34 #include "../datatype/SimpleData.h"
35 #include "../datatype/StringProperty.h"
36 #include "../datatype/Utils.h"
37 #include "../datatype/DateTimeUtils.h"
38 #include "../datatype/TimePeriod.h"
39 #include "../datatype/Date.h"
40 #include "../datatype/Enums.h"
41 #include "../geometry/Envelope.h"
42 #include "../geometry/Geometry.h"
43 #include "../geometry/GeometryProperty.h"
44 #include "../geometry/Utils.h"
45 #include "../memory/DataSetItem.h"
46 #include "../sam/rtree/Index.h"
61 m_begTimePropIdx(tpPropIdx),
68 for(std::size_t i = 0; i < type->
size(); ++i)
86 m_begTimePropIdx(tpPropIdx),
88 m_geomPropIdx(gmPropIdx)
93 for(std::size_t i = 0; i < type->
size(); ++i)
105 int endTimePropIdx,
int gmPropIdx)
112 m_begTimePropIdx(begTimePropIdx),
113 m_endTimePropIdx(endTimePropIdx),
114 m_geomPropIdx(gmPropIdx)
119 for(std::size_t i = 0; i < type->
size(); ++i)
130 te::stmem::DataSet::DataSet(
const std::vector<std::string>& pnames,
const std::vector<int>& ptypes,
const std::map<int, te::common::CharEncoding>& encodings,
131 int begTimePropIdx,
int endTimePropIdx,
int gmPropIdx)
138 m_encodings(encodings),
139 m_begTimePropIdx(begTimePropIdx),
140 m_endTimePropIdx(endTimePropIdx),
141 m_geomPropIdx(gmPropIdx)
154 m_begTimePropIdx(tpPropIdx),
155 m_endTimePropIdx(-1),
156 m_geomPropIdx(gmPropIdx)
161 for(std::size_t i = 0; i <
m_ptypes.size(); ++i)
179 m_begTimePropIdx(begTimePropIdx),
180 m_endTimePropIdx(endTimePropIdx),
181 m_geomPropIdx(gmPropIdx)
186 for(std::size_t i = 0; i <
m_ptypes.size(); ++i)
202 m_pnames(rhs.m_pnames),
203 m_ptypes(rhs.m_ptypes),
204 m_encodings(rhs.m_encodings),
205 m_begTimePropIdx(rhs.m_begTimePropIdx),
206 m_endTimePropIdx(rhs.m_endTimePropIdx),
207 m_geomPropIdx(rhs.m_geomPropIdx)
212 TimeToDataSetItemMap::const_iterator it = rhs.
m_items.begin();
217 add(it->second->clone().release());
230 m_beforeFirst =
true;
239 TimeToDataSetItemMap::const_iterator it = other.
m_items.begin();
240 while(it != other.
m_items.end())
252 TimeToDataSetItemMap::iterator it = m_items.begin();
253 while(it!=m_items.end())
263 std::vector<std::size_t> properties;
267 for(std::size_t i = 0; i != np; ++i)
268 properties.push_back(i);
270 copy(src, properties, limit);
275 bool unlimited =
true;
278 limit = std::numeric_limits<std::size_t>::max();
288 for(std::size_t c = 0; c < properties.size(); ++c)
290 if(!src->
isNull(properties[c]))
291 item->setValue(properties[c], src->
getValue(properties[c]).release());
293 item->setValue(properties[c], 0);
300 }
while(src->
moveNext() && (i < limit));
302 if(!unlimited & (i < limit))
303 throw Exception(
"The source dataset has few items than requested copy limit!");
313 return m_geomPropIdx;
318 return m_begTimePropIdx;
323 return m_endTimePropIdx;
329 m_items.insert(std::pair<te::dt::DateTime*, DateSetItemShrPtr>(dt,p.second));
335 std::auto_ptr<te::gm::Geometry> geom(p.second->getGeometry(m_geomPropIdx));
339 m_RTree->insert(*env, p.second.get());
349 std::auto_ptr<te::dt::DateTime> phBegTime;
350 if(m_begTimePropIdx>=0)
351 phBegTime = item->getDateTime(m_begTimePropIdx);
353 std::auto_ptr<te::dt::DateTime> phEndTime;
354 if(m_endTimePropIdx>=0)
355 phEndTime = item->getDateTime(m_endTimePropIdx);
358 if(phBegTime.get()!=0 && phEndTime.get()==0)
360 std::pair<te::dt::DateTime*, DateSetItemShrPtr> p(phBegTime.get(),item);
364 else if(phBegTime.get()!=0 && phEndTime.get()!=0)
366 std::auto_ptr<te::dt::DateTime> aux (
te::dt::GetTimePeriod(static_cast<te::dt::DateTimeInstant*>(phBegTime.get()),
367 static_cast<te::dt::DateTimeInstant*>(phEndTime.get())));
368 std::pair<te::dt::DateTime*, DateSetItemShrPtr> p(aux.get(),item);
396 return std::auto_ptr<te::stmem::DataSet>(0);
398 std::vector<te::mem::DataSetItem*> report;
399 m_RTree->search(*e, report);
401 std::auto_ptr<te::stmem::DataSet> result(
new DataSet(m_pnames, m_ptypes, m_encodings, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
403 for(
unsigned int i=0; i<report.size(); ++i)
404 result->add(report[i]->clone().release());
412 return std::auto_ptr<te::stmem::DataSet>(0);
414 std::vector<te::mem::DataSetItem*> report;
415 m_RTree->search(*g->
getMBR(), report);
417 std::auto_ptr<te::stmem::DataSet> result(
new DataSet(m_pnames, m_ptypes, m_encodings, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
419 for(
unsigned int i=0; i<report.size(); ++i)
421 std::auto_ptr<te::gm::Geometry> geom(report[i]->getGeometry(m_geomPropIdx));
422 if(geom->intersects(g))
423 result->add(report[i]->clone().release());
430 TimeToDataSetItemMap::const_iterator itb = m_items.end();
431 TimeToDataSetItemMap::const_iterator ite = m_items.end();
433 std::auto_ptr<te::stmem::DataSet> result(
new DataSet(m_pnames, m_ptypes, m_encodings, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
434 std::auto_ptr<te::dt::DateTime> dtaux(static_cast<te::dt::DateTime*>(dt->
clone()));
438 itb = m_items.upper_bound(dtaux.get());
442 itb = m_items.find(dtaux.get());
443 if(itb==m_items.end())
444 itb = m_items.upper_bound(dtaux.get());
448 itb = m_items.begin();
449 ite = m_items.find(dtaux.get());
450 if(ite==m_items.end())
451 ite = m_items.upper_bound(dtaux.get());
455 itb = m_items.begin();
456 ite = m_items.upper_bound(dtaux.get());
460 std::auto_ptr<te::dt::DateTime> t1(static_cast<te::dt::DateTimePeriod*>(dtaux.get())->getInitialInstant());
461 std::auto_ptr<te::dt::DateTime> t2(static_cast<te::dt::DateTimePeriod*>(dtaux.get())->getFinalInstant());
462 itb = m_items.find(t1.get());
463 if(itb==m_items.end())
464 itb = m_items.upper_bound(t1.get());
465 ite = m_items.upper_bound(t2.get());
469 std::pair<TimeToDataSetItemMap::const_iterator, TimeToDataSetItemMap::const_iterator> itPair;
470 itPair = m_items.equal_range(dtaux.get());
486 std::auto_ptr<te::stmem::DataSet> result1 = filter(e,r);
487 return result1->filter(dt, tr);
493 std::auto_ptr<te::stmem::DataSet> result1 = filter(g,r);
494 return result1->filter(dt, tr);
499 TimeToDataSetItemMap::const_iterator itlower, itupper, itbegin, itend;
500 itbegin = m_items.begin();
501 itend = m_items.end();
502 std::auto_ptr<te::dt::DateTime> dtaux(static_cast<te::dt::DateTime*>(time->
clone()));
503 itlower = m_items.lower_bound(dtaux.get());
504 itupper = m_items.upper_bound(dtaux.get());
507 std::multimap<long, TimeToDataSetItemMap::const_iterator> result;
509 while(itlower!=itbegin && itlower!=itend && numObs<n)
512 result.insert(std::pair<long, TimeToDataSetItemMap::const_iterator>(dist, itlower));
518 while(itupper!=itend && numObs<n)
521 result.insert(std::pair<long, TimeToDataSetItemMap::const_iterator>(dist, itlower));
527 std::auto_ptr<te::stmem::DataSet> ds(
new DataSet(m_pnames, m_ptypes, m_encodings, m_begTimePropIdx, m_endTimePropIdx, m_geomPropIdx));
528 std::multimap<long, TimeToDataSetItemMap::const_iterator>::iterator it = result.begin();
530 while(it != result.end() && numObs<n)
532 ds->add(*it->second);
552 return m_pnames.size();
557 return m_ptypes[pos];
562 return m_pnames[pos];
567 std::map<int, te::common::CharEncoding>::const_iterator it = m_encodings.find(i);
568 assert(it != m_encodings.end());
580 return m_items.empty();
590 return m_items.size();
596 return std::auto_ptr<te::gm::Envelope>(
new te::gm::Envelope(m_RTree->getMBR()));
600 TimeToDataSetItemMap::const_iterator it = m_items.begin();
601 while(it != m_items.end())
603 std::auto_ptr<te::gm::Geometry> geom(it->second->getGeometry(i));
604 mbr->Union(*(geom->getMBR()));
616 return m_iterator != m_items.end();
621 if(m_beforeFirst || m_iterator==m_items.begin())
629 m_iterator = m_items.begin();
630 m_beforeFirst =
false;
631 return m_iterator!=m_items.end();
642 m_iterator = m_items.end();
650 if(i>=m_items.size())
653 m_iterator = m_items.begin();
655 while(m_iterator!=m_items.end() && c < i)
665 return m_iterator == m_items.begin();
670 return m_beforeFirst;
675 TimeToDataSetItemMap::const_iterator aux = m_items.end();
677 return m_iterator==aux;
682 return m_iterator == m_items.end();
687 return m_iterator->second->getChar(i);
692 m_iterator->second->setChar(i, value);
697 m_iterator->second->setChar(name, value);
702 return m_iterator->second->getUChar(i);
707 m_iterator->second->setUChar(i, value);
712 m_iterator->second->setUChar(name, value);
717 return m_iterator->second->getInt16(i);
722 m_iterator->second->setInt16(i, value);
727 m_iterator->second->setInt16(name, value);
732 return m_iterator->second->getInt32(i);
737 m_iterator->second->setInt32(i, value);
742 m_iterator->second->setInt32(name, value);
747 return m_iterator->second->getInt64(i);
752 m_iterator->second->setInt64(i, value);
757 m_iterator->second->setInt64(name, value);
762 return m_iterator->second->getBool(i);
767 m_iterator->second->setBool(i, value);
772 m_iterator->second->setBool(name, value);
777 return m_iterator->second->getFloat(i);
782 m_iterator->second->setFloat(i, value);
787 return m_iterator->second->getDouble(i);
792 m_iterator->second->setDouble(i, value);
797 m_iterator->second->setDouble(name, value);
802 return m_iterator->second->getNumeric(i);
807 m_iterator->second->setNumeric(i, value);
812 m_iterator->second->setNumeric(name, value);
817 return m_iterator->second->getString(i);
822 m_iterator->second->setString(i, value);
827 m_iterator->second->setString(name, value);
832 return std::auto_ptr<te::dt::ByteArray>(m_iterator->second->getByteArray(i));
837 m_iterator->second->setByteArray(i, value);
842 m_iterator->second->setByteArray(name, value);
847 return m_iterator->second->getGeometry(i);
852 m_iterator->second->setGeometry(i, value);
857 m_iterator->second->setGeometry(name, value);
862 return m_iterator->second->getRaster(i);
867 m_iterator->second->setRaster(i, value);
872 m_iterator->second->setRaster(name, value);
877 return m_iterator->second->getDateTime(i);
882 m_iterator->second->setDateTime(i, value);
887 m_iterator->second->setDateTime(name, value);
892 return std::auto_ptr<te::dt::Array>(0);
897 return m_iterator->second->getValue(i);
902 m_iterator->second->setValue(i, ad);
907 m_iterator->second->setValue(name, ad);
912 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.
A base class for date data types.
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)