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" 55 : m_beforeFirst(true),
57 m_begTimePropIdx(static_cast<
int>(tpPropIdx)),
82 size_t begTimePropIdx,
size_t endTimePropIdx,
97 const std::vector<int>& ptypes,
98 size_t begTimePropIdx,
size_t endTimePropIdx,
112 size_t gmPropIdx,
unsigned int limit)
129 size_t endTimePropIdx,
size_t gmPropIdx,
157 TimeToDataSetItemMap::const_iterator it = rhs.
m_items.begin();
162 add(it->second->clone().release());
183 TimeToDataSetItemMap::const_iterator it = other.
m_items.begin();
184 while(it != other.
m_items.end())
196 TimeToDataSetItemMap::iterator it =
m_items.begin();
207 std::vector<std::size_t> properties;
211 for(std::size_t i = 0; i != np; ++i)
212 properties.push_back(i);
214 copy(src, properties, limit);
219 bool unlimited =
true;
222 limit =
static_cast<unsigned int>(std::numeric_limits<std::size_t>::max());
232 for(std::size_t c = 0; c < properties.size(); ++c)
234 if(!src->
isNull(properties[c]))
235 item->setValue(properties[c], src->
getValue(properties[c]).release());
237 item->setValue(properties[c],
nullptr);
244 }
while(src->
moveNext() && (i < limit));
246 if(!unlimited & (i < limit))
247 throw Exception(
"The source dataset has few items than requested copy limit!");
273 m_items.insert(std::pair<te::dt::DateTime*, DateSetItemShrPtr>(dt,p.second));
279 std::unique_ptr<te::gm::Geometry> geom(p.second->getGeometry(static_cast<size_t>(
m_geomPropIdx)));
280 if(geom.get()!=
nullptr)
283 m_RTree->insert(*env, p.second.get());
293 std::unique_ptr<te::dt::DateTime> phBegTime;
297 std::unique_ptr<te::dt::DateTime> phEndTime;
302 if(phBegTime.get()!=
nullptr && phEndTime.get()==
nullptr)
304 std::pair<te::dt::DateTime*, DateSetItemShrPtr>
p(phBegTime.get(),item);
308 else if(phBegTime.get()!=
nullptr && phEndTime.get()!=
nullptr)
310 std::unique_ptr<te::dt::DateTime> aux (
te::dt::GetTimePeriod(static_cast<te::dt::DateTimeInstant*>(phBegTime.get()),
311 static_cast<te::dt::DateTimeInstant*>(phEndTime.get())));
312 std::pair<te::dt::DateTime*, DateSetItemShrPtr>
p(aux.get(),item);
340 return std::unique_ptr<te::stmem::DataSet>();
342 std::vector<te::mem::DataSetItem*> report;
348 for(
unsigned int i=0; i<report.size(); ++i)
349 result->add(report[i]->clone().release());
357 return std::unique_ptr<te::stmem::DataSet>();
359 std::vector<te::mem::DataSetItem*> report;
365 for(
unsigned int i=0; i<report.size(); ++i)
368 if(geom->intersects(g))
369 result->add(report[i]->clone().release());
376 TimeToDataSetItemMap::const_iterator itb =
m_items.end();
377 TimeToDataSetItemMap::const_iterator ite =
m_items.end();
381 std::unique_ptr<te::dt::DateTime> dtaux(static_cast<te::dt::DateTime*>(dt->
clone()));
385 itb =
m_items.upper_bound(dtaux.get());
389 itb =
m_items.find(dtaux.get());
391 itb =
m_items.upper_bound(dtaux.get());
396 ite =
m_items.find(dtaux.get());
398 ite =
m_items.upper_bound(dtaux.get());
403 ite =
m_items.upper_bound(dtaux.get());
407 std::unique_ptr<te::dt::DateTime> t1(static_cast<te::dt::DateTimePeriod*>(dtaux.get())->getInitialInstant());
408 std::unique_ptr<te::dt::DateTime> t2(static_cast<te::dt::DateTimePeriod*>(dtaux.get())->getFinalInstant());
411 itb =
m_items.upper_bound(t1.get());
412 ite =
m_items.upper_bound(t2.get());
416 std::pair<TimeToDataSetItemMap::const_iterator, TimeToDataSetItemMap::const_iterator> itPair;
417 itPair =
m_items.equal_range(dtaux.get());
433 std::unique_ptr<te::stmem::DataSet> result1 =
filter(e,r);
434 return result1->filter(dt, tr);
440 std::unique_ptr<te::stmem::DataSet> result1 =
filter(g,r);
441 return result1->filter(dt, tr);
446 TimeToDataSetItemMap::const_iterator itlower, itupper, itbegin, itend;
449 std::unique_ptr<te::dt::DateTime> dtaux(static_cast<te::dt::DateTime*>(time->
clone()));
450 itlower =
m_items.lower_bound(dtaux.get());
451 itupper =
m_items.upper_bound(dtaux.get());
454 std::multimap<long, TimeToDataSetItemMap::const_iterator> result;
456 while(itlower!=itbegin && itlower!=itend && numObs<n)
459 result.insert(std::pair<long, TimeToDataSetItemMap::const_iterator>(dist, itlower));
465 while(itupper!=itend && numObs<n)
468 result.insert(std::pair<long, TimeToDataSetItemMap::const_iterator>(dist, itlower));
476 std::multimap<long, TimeToDataSetItemMap::const_iterator>::iterator it = result.begin();
478 while(it != result.end() && numObs<n)
480 ds->add(*it->second);
540 TimeToDataSetItemMap::const_iterator it =
m_items.begin();
543 std::unique_ptr<te::gm::Geometry> geom(it->second->getGeometry(i));
544 mbr->Union(*(geom->getMBR()));
615 TimeToDataSetItemMap::const_iterator aux =
m_items.end();
777 return std::unique_ptr<te::dt::ByteArray>(
m_iterator->second->getByteArray(i));
787 m_iterator->second->setByteArray(name, value);
837 return std::unique_ptr<te::dt::Array>();
std::unique_ptr< DataSet > clone() const
It returns a clone of the DataSet.
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. ...
std::unique_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
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)
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
A class that represents an R-tree.
std::unique_ptr< te::dt::DateTimePeriod > getTemporalExtent() const
It returns the temporal extent of the observations.
Base exception class for plugin module.
A class that models the description of a dataset.
void setDouble(std::size_t i, double value)
DataSet()
Default constructor.
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.
static te::dt::Date ds(2010, 01, 01)
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::unique_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
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.
std::unique_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
AccessPolicy
Supported data access policies (can be used as bitfield).
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)
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
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::unique_ptr< te::sam::rtree::Index< te::mem::DataSetItem * > > m_RTree
A RTree index created over the default geometry property.
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::unique_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
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.
virtual AbstractData * clone() const =0
It returns a clone of this object.
A base class for values that can be retrieved from the data access module.
char getChar(std::size_t i) const
Method for retrieving a signed character attribute value (1 byte long).
void add(const std::pair< te::dt::DateTime *, DateSetItemShrPtr > &item)
It adds an existing item to the dataset.
std::unique_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
int m_begTimePropIdx
The property index of the DataSetType that contains the phenomenon beginning time.
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)
TimeToDataSetItemMap::const_iterator m_iterator
The pointer to the current item.
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.
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...
virtual std::unique_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 exception class for the TerraLib ST memory driver.
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).
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::unique_ptr< DataSet > filter(const te::gm::Envelope *e, te::gm::SpatialRelation r) const
It returns a new DataSet, based on a given spatial filter.
bool isPositionValid() const
It tells if the dataset internal pointer is on a valid position.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
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.
std::unique_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.
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
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)
std::unique_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
std::vector< std::string > m_pnames
internal control
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
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)