TeBaseSTInstanceSet.h

Go to the documentation of this file.
00001 /************************************************************************************
00002 TerraLib - a library for developing GIS applications.
00003 Copyright  2001-2007 INPE and Tecgraf/PUC-Rio.
00004 
00005 This code is part of the TerraLib library.
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Lesser General Public
00008 License as published by the Free Software Foundation; either
00009 version 2.1 of the License, or (at your option) any later version.
00010 
00011 You should have received a copy of the GNU Lesser General Public
00012 License along with this library.
00013 
00014 The authors reassure the license terms regarding the warranties.
00015 They specifically disclaim any warranties, including, but not limited to,
00016 the implied warranties of merchantability and fitness for a particular purpose.
00017 The library provided hereunder is on an "as is" basis, and the authors have no
00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
00020 indirect, special, incidental, or consequential damages arising out of the use
00021 of this library and its documentation.
00022 *************************************************************************************/
00023 /*! \file TeBaseSTInstanceSet.h
00024         \brief This file contains structures to deal with a set of spatio-temporal 
00025         instances. These instances can belong to a specific layer or theme.
00026 */
00027 
00028 #ifndef  __TERRALIB_INTERNAL_STINSTANCESET_H
00029 #define  __TERRALIB_INTERNAL_STINSTANCESET_H
00030 
00031 #include "TeBaseSTInstance.h"
00032 #include "TeRTree.h"
00033 #include "TeTheme.h"
00034 #include "TeLayer.h"
00035 #include "TeQuerierParams.h"
00036 #include "TeQuerier.h"
00037 #include "TeSharedPtr.h"
00038 
00039 /*! \class TeBaseSTInstanceSet
00040         \brief A abstract class that represents a set of spatial temporal instances.
00041 
00042         This abstract class implements a generic spatio-temporal instance set. It must 
00043         be specialized according to the instance type (its geometry type, its time type
00044         and its own type). 
00045 
00046         \sa TeBaseSTInstance TeTheme TeLayer
00047         
00048 */
00049 template< typename GeometryType, typename TimeType, typename InstanceType >
00050 class TeBaseSTInstanceSet  
00051 {
00052 
00053 protected:
00054 
00055         //! Set of spatio temporal instances
00056         vector<InstanceType>    instances_;             
00057 
00058         //! Minimal time associated to spatial temporal instances
00059         TimeType                                minTime_;
00060         //! Maximal time associated to spatial temporal instances
00061         TimeType                                maxTime_;
00062 
00063         //! Description of all attributes 
00064         TeSharedPtr<TeAttributeList>    attrList_;
00065 
00066         //! A pointer to a theme
00067         TeTheme*                                theme_;
00068         //! A pointer to a layer
00069         TeLayer*                                layer_; 
00070         //! A bounding box that contains all geometries of the spatial temporal instances
00071         TeBox                                   box_;
00072         
00073         //! A map from object identity to its associated instances in the set 
00074         map<string, vector<int> >               objectIdToInstances_;
00075         //! A map from time to its associated instances in the set
00076         map<TimeType, vector<int> >             timeToInstances_;
00077         //! A map from slice to its associated instances in the set
00078         map<int, vector<int> >                  sliceToInstances_;
00079         //! A struture to index the geometries: RTree
00080         TeSAM::TeRTree<int>*                    rTree_;         
00081 
00082         //! Builds the set using a given querier and a specific slice
00083         virtual bool buildImpl(TeQuerier* querier, const int& slide = -1) = 0;
00084 
00085 public:
00086 
00087         //! An iterator that traverse each instance in the set
00088         typedef typename vector<InstanceType>::iterator iterator;
00089         
00090         //! Constructor. It does not initialize the rTree. 
00091         TeBaseSTInstanceSet(); 
00092 
00093         //! Constructor. It initializes the rTree based on theme box.
00094         TeBaseSTInstanceSet(TeTheme* theme, const TeAttributeList& attrList = TeAttributeList()); 
00095 
00096         //! Constructor. It initializes the rTree based on layer box.
00097         TeBaseSTInstanceSet(TeLayer* layer, const TeAttributeList& attrList = TeAttributeList());  
00098 
00099         //! Constructor. It initializes the rTree based on the given box. 
00100         TeBaseSTInstanceSet(const TeBox& box, const TeAttributeList& attrList = TeAttributeList());
00101 
00102         //! Copy constructor
00103         TeBaseSTInstanceSet (const TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>& other); 
00104 
00105         //! Destructor
00106         virtual ~TeBaseSTInstanceSet();  
00107         
00108         //! Assignment operator
00109         virtual TeBaseSTInstanceSet& operator= (const TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>& other);
00110 
00111         //! Gets minimal time
00112         virtual TimeType getMinTime()
00113         { return minTime_; }
00114 
00115         //! Sets minimal time
00116         virtual void setMinTime(TimeType& t)
00117         { minTime_ = t; } 
00118 
00119         //! Gets maximal time
00120         virtual TimeType getMaxTime()
00121         { return maxTime_; }
00122 
00123         //! Sets maximal time
00124         virtual void setMaxTime(TimeType& t)
00125         { maxTime_ = t; } 
00126 
00127         //! Gets the attribute list, that is, the description of all attributes
00128         virtual TeAttributeList& getAttributeList()
00129         {       return (*attrList_);  }
00130 
00131         //! Sets the attribute list, that is, the description of all attributes
00132         virtual void setAttributeList(const TeAttributeList& attrs);
00133 
00134         //! Returns the index of an attribute named "attrName"
00135         virtual int getAttributeIndex(const string& attrName);
00136 
00137         //! Gets theme pointer
00138         virtual TeTheme* getTheme()
00139         {       return theme_;  }
00140 
00141         //! Sets theme pointer
00142         virtual void setTheme(TeTheme* t)
00143         {       theme_ = t; }
00144 
00145         //! Deprecated: Returns a theme pointer
00146         TeTheme* theme()
00147         {       return getTheme(); }
00148 
00149         //! Gets layer pointer 
00150         virtual TeLayer* getLayer()
00151         {       return layer_;  }
00152 
00153         //! Sets layer pointer
00154         virtual void setLayer(TeLayer* l)
00155         {       layer_ = l; }
00156         
00157         //! Gets a reference to the instance set 
00158         virtual vector<InstanceType>& getSTInstances()
00159         {       return instances_; }
00160 
00161         //! Gets a pointer to the index-th ST instance
00162         virtual InstanceType* getSTInstance(const unsigned int& index);
00163 
00164         //! Gets a pointer to a ST instance of an object in a specific slice  
00165         virtual InstanceType* getSTInstance(const string& objectId, const int& slice = -1);
00166 
00167         //! Gets a pointer to a ST instance of an object in a specific time and slice
00168         virtual InstanceType* getSTInstance(const string& objectId, TimeType& time, const int& slice = -1);
00169 
00170         //! Gets pointers to all ST instances of a specific object in a specific slice
00171         virtual void getSTInstances(vector<InstanceType*>& set, const string& objectId, const int& slice = -1);
00172 
00173         //! Gets pointers to all ST instances of a specific object in a specific time and slice
00174         virtual void getSTInstances(vector<InstanceType*>& set, const string& objectId, TimeType& time, const int& slice = -1);
00175         
00176         ///! Gets pointers to all ST instances of a specific time
00177         virtual void getSTInstances(vector<InstanceType*>& set, TimeType& time, const int& slice = -1);
00178 
00179         //! Gets pointers to all ST instances of a specific slice
00180         virtual void getSTInstances(vector<InstanceType*>& set, const int& slice);
00181 
00182         //! Inserts a new ST instance in the set 
00183         virtual bool insertSTInstance (InstanceType& object);
00184                 
00185         //! Returns the number of instances 
00186         virtual int numSTInstance(); 
00187         
00188         //! Returns the number of instances of an object or element
00189         virtual int numSTInstance(const string& objectId); 
00190 
00191         //! Returns the number of instances in a specific slice
00192         virtual int numSTInstance(const int& slice);
00193 
00194         //! Returns the number of instances in a specific time
00195         virtual int numSTInstance(TimeType& time);
00196 
00197         //! Returns the number of elements or objects in the set
00198         virtual int numElements()
00199         {       return objectIdToInstances_.size(); }
00200 
00201         //! Sets a geometry of an object in a specific slice
00202         virtual bool setGeometry(const string& object_id, GeometryType& geom, const int& slice = -1);
00203 
00204         //! Sets a geometry of an object in a specific time and slice
00205         virtual bool setGeometry(const string& object_id, GeometryType& geom, TimeType& time,  const int& slice = -1);
00206 
00207         //! Gets the geometry of an object in a specific slice 
00208         virtual bool getGeometry(const string& object_id, GeometryType& geom, const int& slice = -1);
00209 
00210         //! Gets the geometry of an object in a specific time and slice
00211         virtual bool getGeometry(const string& object_id, GeometryType& geom, TimeType& time, const int& slice = -1);
00212 
00213         //! Gets a vector of attributes or properties of a object that is valid in a slice 
00214         virtual bool getPropertyVector (const string& object_id, TePropertyVector& propVec, const int& slice = -1);
00215 
00216         //! Gets a vector of attributes or properties of a object that is valid in a time and slice
00217         virtual bool getPropertyVector (const string& object_id, TePropertyVector& propVec, TimeType& time, const int& slice = -1);
00218 
00219         //! Sets a vector of attribute values of a object that is valid in a slice 
00220         virtual bool setProperties (const string& object_id, const vector<string>& values, const int& slice = -1);
00221 
00222         //! Sets a vector of attribute values of a object that is valid in a time and slice
00223         virtual bool setProperties (const string& object_id, const vector<string>& values, TimeType& time, const int& slice = -1);
00224         
00225         //! Gets a vector of attribute values of a object that is valid in a slice 
00226         virtual bool getProperties (const string& object_id, vector<string>& values, const int& slice = -1);
00227 
00228         //! Gets a vector of attribute values of a object that is valid in a time and slice
00229         virtual bool getProperties (const string& object_id, vector<string>& values, TimeType& time, const int& slice = -1);
00230 
00231         //! Sets the value of the attribute named "attr_name" of an object that is valid in a slice 
00232         virtual bool setAttributeValue (const string& object_id, const string& attr_name,  const string& val, const int& slice = -1);
00233 
00234         //! Sets the value of the attribute named "attr_name" of an object that is valid in a time and slice
00235         virtual bool setAttributeValue (const string& object_id, const string& attr_name,  const string& val, TimeType& time, const int& slice = -1);
00236 
00237         //! Sets the value of the i-th attribute of an object that is valid in a slice 
00238         virtual bool setAttributeValue (const string& object_id, const int& i, const string& val, const int& slice = -1); 
00239 
00240         //! Sets the value of the i-th attribute of an object that is valid in a time and slice
00241         virtual bool setAttributeValue (const string& object_id, const int& i, const string& val, TimeType& time, const int& slice = -1); 
00242         
00243         //! Get the value of the attribute named "attr_name" of an object that is valid in a slice 
00244         virtual bool getAttributeValue (const string& object_id, const string& attr_name,  string& val, const int& slice = -1);
00245 
00246         //! Get the value of the attribute named "attr_name" of an object that is valid in a time and slice
00247         virtual bool getAttributeValue (const string& object_id, const string& attr_name,  string& val, TimeType& time, const int& slice = -1);
00248 
00249         //! Gets the value of the i-th attribute of an object that is valid in a slice 
00250         virtual bool getAttributeValue (const string& object_id, const int& i, string& val, const int& slice = -1); 
00251 
00252         //! Gets the value of the i-th attribute of an object that is valid in a time and slice
00253         virtual bool getAttributeValue (const string& object_id, const int& i, string& val, TimeType& time, const int& slice = -1); 
00254 
00255         //! Adds a new attribute in the attribute list and adds it in all instances in the set using a default value
00256         virtual bool addProperty(TeAttributeRep& attr, const string& defaultValue);
00257 
00258         //! Adds a new attribute only in the attribute list
00259         virtual bool addProperty(TeAttribute& attr);
00260 
00261         /*!
00262                 \brief Adds the property or sets its value in the object in a valid slice.
00263 
00264                 If there is already the property in the attribute list, sets the value of the instances of an object  
00265                 valid in a specific slice. If there is no this property in the attribute list, adds it in the attribute
00266                 list and in all instances in the set. After that, sets the value of the instances of an object  
00267                 valid in a specific slice.
00268         */
00269         virtual bool addProperty(const string& object_id, TeProperty& prop, const int& slice=-1);
00270 
00271         /*!
00272                 \brief Adds the property or sets its value in the object in a valid time and slice.
00273 
00274                 If there is already the property in the attribute list, sets the value of the instances of an object  
00275                 valid in a specific time and slice. If there is no this property in the attribute list, adds it in the attribute
00276                 list and in all instances in the set. After that, sets the value of the instances of an object  
00277                 valid in a specific time and slice.
00278         */
00279         virtual bool addProperty(const string& object_id, TeProperty& prop, TimeType& time, const int& slice = -1);
00280 
00281         //! Removes an attribute of the attribute list and removes it of all instances in the set 
00282         virtual void removeProperty(TeAttributeRep& attr);
00283 
00284         //! Calculates the bounding box of all instances of all objects included in the set
00285         virtual TeBox& getBox();
00286 
00287         //! Sets the bounding box of all instances of all objects included in the set
00288         virtual void setBox(const TeBox& b)
00289         {       box_ = b; }
00290 
00291         //! Clears the set 
00292         virtual void clear();  
00293 
00294         void clearInstances();
00295                 
00296         //! Returns an iterator to the first element of the set
00297         virtual iterator begin()
00298         {       return instances_.begin(); }
00299         
00300         //! Returns an iterator to the one past last element of the set
00301         virtual iterator end()
00302         {       return instances_.end(); }
00303 
00304         //! Searchs the instances which bounding boxes intersect a specific bounding box, using the R Tree.
00305         virtual bool search(const TeBox& b, vector<InstanceType* >& result);
00306 
00307         //! Fills the ST instance set from a layer or theme, using the given filled parameters
00308         virtual bool build(bool loadGeometries=false, bool loadAllAttributes=true, vector<string> attrNames=vector<string>(), int slide=-1); 
00309 
00310         //! Fills the ST instance set from a layer or theme, using the given filled parameters
00311         virtual bool build(TeGroupingAttr& groupAttr, bool loadGeometries=false, int slide=-1); 
00312 
00313         
00314         /*! \class propertyIterator
00315                 \brief This class implements an iterator concept over the instance set.
00316                 
00317                 A structure that allows the traversal ST element set
00318                 in a similar way as the STL iterators. This iterator passes over each 
00319                 ST instance of the ST element set and returns a specific numerical property.
00320         */
00321         class propertyIterator
00322         {
00323                 public:
00324                         //! Constructor
00325                         propertyIterator (TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>* setIt,
00326                                 typename std::vector<InstanceType>::iterator it,  
00327                                 const string& attrName):
00328                                 attrName_(attrName), attrIndex_(-1), it_(it), setIt_(setIt)
00329                                 {
00330                                         attrIndex_ = setIt_->getAttributeIndex(attrName);
00331                                 }
00332 
00333                         //! Constructor
00334                         propertyIterator (TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>* setIt,
00335                                 typename std::vector<InstanceType>::iterator it,
00336                                 const int& attrIndex):
00337                                 attrName_ (""), attrIndex_(attrIndex), it_(it), setIt_(setIt)
00338                                 { }
00339 
00340                         //! Constructor
00341                         propertyIterator (typename vector<InstanceType>::iterator it,
00342                                 const int& attrIndex):
00343                                 attrName_ (""), attrIndex_(attrIndex), it_(it)
00344                                 {}
00345                 
00346                         //! Moves to the next attribute in the set
00347                         propertyIterator& operator++()
00348                         {       
00349                                 ++it_;
00350                                 return (*this);
00351                         }
00352 
00353                         //! Returns the current attribute as double
00354                         double operator*()
00355                         {       return (*it_)[attrIndex_];      }
00356                         
00357                         //! Sets a new value to the attrIndex_-th attribute of the element pointed by the iterator
00358                         void setValue(const double& val)
00359                         {       it_->setPropertyValue(attrIndex_, Te2String(val)); }
00360 
00361                         //! Returns a pointer to the instance set 
00362                         TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>* elemSet()
00363                         {       return setIt_;  }
00364 
00365                         //! Equal operator
00366                         bool operator==(const propertyIterator& rhs) const
00367                         {       return (this->attrIndex_ == rhs.attrIndex_ && this->it_== rhs.it_); }
00368 
00369                         //! Unequal operator
00370                         bool operator!=(const propertyIterator& rhs) const
00371                         {       return (this->attrIndex_ != rhs.attrIndex_ || this->it_!= rhs.it_);     }
00372 
00373                         //! Deprecated: Returns the numerical property of the current instance.
00374                         bool getProperty(TeProperty& prop)
00375                         {       return (*it_).getProperty(prop, attrIndex_); }
00376                                 
00377                 protected:
00378                         string                                                                          attrName_;      //<! the numerical property name
00379                         int                                                                                     attrIndex_;     //<! the numerical property index
00380                         typename vector<InstanceType>::iterator         it_; 
00381                         TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>* setIt_; 
00382 
00383         };
00384 
00385         //! Returns a property iterator to the attribute named "attName" of the first instance in the set.
00386         propertyIterator begin(const string& attName)
00387         {
00388                 return propertyIterator(this, instances_.begin(), attName); 
00389         }
00390 
00391         //! Returns a property iterator to the attIndex-th attribute of the first instance in the set.
00392         propertyIterator begin(const int& attIndex)
00393         {
00394                 return propertyIterator(this, instances_.begin(), attIndex); 
00395         }
00396 
00397         //! Returns a property iterator to the attribute named "attName" of the one past last element of the set
00398         propertyIterator end(const string& attName)
00399         {
00400                 return propertyIterator(this, instances_.end(), attName); 
00401         }
00402 
00403         //! Returns a property iterator to the attIndex-th attribute of the one past last element of the set
00404         propertyIterator end(const int& attIndex)
00405         {
00406                 return propertyIterator(this, instances_.end(), attIndex); 
00407         }
00408 };
00409 
00410 template<typename GeometryType, typename TimeType, typename InstanceType>
00411 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::TeBaseSTInstanceSet() :
00412           theme_(0),  layer_(0), rTree_(0)
00413 { 
00414         TeAttributeList* att = new TeAttributeList();
00415         attrList_ = TeSharedPtr<TeAttributeList>(att);
00416 }
00417 
00418 
00419 template<typename GeometryType, typename TimeType, typename InstanceType>
00420 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::TeBaseSTInstanceSet(TeTheme* theme, const TeAttributeList& attrList) 
00421 {
00422         layer_ = 0;
00423         theme_ = 0;
00424         rTree_ = 0;
00425         TeAttributeList* att = new TeAttributeList(attrList);
00426         attrList_ = TeSharedPtr<TeAttributeList>(att);
00427         if(!theme)
00428                 return;
00429         theme_ = theme;
00430         rTree_ = new TeSAM::TeRTree<int>(theme_->box());
00431 }
00432 
00433 template<typename GeometryType, typename TimeType, typename InstanceType>
00434 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::TeBaseSTInstanceSet(TeLayer* layer, const TeAttributeList& attrList) 
00435 {
00436         layer_ = 0;
00437         theme_ = 0;
00438         rTree_ = 0;
00439         TeAttributeList* att = new TeAttributeList(attrList);
00440         attrList_ = TeSharedPtr<TeAttributeList>(att);
00441         if(!layer)
00442                 return;
00443         layer_ = layer;
00444         rTree_ = new TeSAM::TeRTree<int>(layer_->box());
00445 }
00446 
00447 
00448 template<typename GeometryType, typename TimeType, typename InstanceType>
00449 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::TeBaseSTInstanceSet(const TeBox& box, const TeAttributeList& attrList)
00450 {
00451         layer_ = 0;
00452         theme_ = 0;
00453         rTree_ = 0;
00454         box_ = box;
00455         TeAttributeList* att = new TeAttributeList(attrList);
00456         attrList_ = TeSharedPtr< TeAttributeList >(att);
00457         if(!box_.isValid())
00458                 return;
00459         rTree_ = new TeSAM::TeRTree<int>(box);
00460 }
00461 
00462 template<typename GeometryType, typename TimeType, typename InstanceType>
00463 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::TeBaseSTInstanceSet(const TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>& other) 
00464 {
00465         instances_ = other.instances_;          
00466         minTime_ = other.minTime_;
00467         maxTime_ = other.maxTime_;
00468         attrList_ = other.attrList_;
00469         theme_ = other.theme_;  
00470         layer_ = other.layer_;  
00471         box_ = other.box_;
00472         objectIdToInstances_ = other.objectIdToInstances_;
00473         timeToInstances_ = other.timeToInstances_;
00474         sliceToInstances_ = other.sliceToInstances_;
00475         rTree_ = 0;
00476                 
00477         if(other.rTree_)
00478         {
00479                 //Operador de copia nao implementado!
00480                 //rTree_ = new TeSAM::TeRTree<int>(other.rTree_->getBox());
00481                 //*rTree_ = *other.rTree_; 
00482         }
00483 }
00484 
00485 template<typename GeometryType, typename TimeType, typename InstanceType>
00486 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::~TeBaseSTInstanceSet() 
00487 {
00488         if(rTree_)
00489                 delete rTree_;
00490 }
00491 
00492 template<typename GeometryType, typename TimeType, typename InstanceType> TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>& 
00493 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::operator= (const TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>& other)
00494 {
00495         if ( this != &other )
00496         {
00497                 instances_ = other.instances_;          
00498                 minTime_ = other.minTime_;
00499                 maxTime_ = other.maxTime_;
00500                 attrList_ = other.attrList_;
00501                 theme_ = other.theme_;  
00502                 layer_ = other.layer_;  
00503                 box_ = other.box_;
00504                 objectIdToInstances_ = other.objectIdToInstances_;
00505                 timeToInstances_ = other.timeToInstances_;
00506                 sliceToInstances_ = other.sliceToInstances_;
00507                 if(rTree_)
00508                         delete rTree_;
00509                 rTree_ = 0;
00510                 
00511                 if(other.rTree_)
00512                 {
00513                         //Operador de copia nao implementado!
00514                         //rTree_ = new TeSAM::TeRTree<int>(other.rTree_->getBox());
00515                         //*rTree_ = *other.rTree_; 
00516                 }
00517         }
00518         return *this;
00519 }
00520 
00521 template<typename GeometryType, typename TimeType, typename InstanceType> void 
00522 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::setAttributeList(const TeAttributeList& attrs)
00523 {       
00524         if(!attrList_.isActive())
00525                 return;
00526         
00527         attrList_->clear();
00528         TeAttributeList::const_iterator it = attrs.begin();
00529         while(it!=attrs.end())
00530         {
00531                 attrList_->push_back(*it);
00532                 ++it;
00533         }
00534 }
00535 
00536 template<typename GeometryType, typename TimeType, typename InstanceType> int
00537 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getAttributeIndex(const string& attrName) 
00538 {
00539         string newName = TeConvertToUpperCase(attrName); 
00540         size_t pos = newName.find(".", 0, 1);
00541         if (pos != string::npos)
00542                 newName = TeConvertToUpperCase(attrName.substr(pos+1));
00543         
00544         for(unsigned int i=0; i<attrList_->size(); ++i)
00545         {
00546                 string s = TeConvertToUpperCase((*attrList_)[i].rep_.name_); 
00547                 if((s == TeConvertToUpperCase(attrName)) || (s == newName))
00548                         return i;
00549         }
00550         return -1;
00551 }
00552 
00553 
00554 
00555 template<typename GeometryType, typename TimeType, typename InstanceType> InstanceType* 
00556 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getSTInstance(const unsigned int& index)
00557 {
00558         if(index<instances_.size())
00559                 return &(instances_[index]);
00560 
00561         return 0;
00562 }
00563 
00564 template<typename GeometryType, typename TimeType, typename InstanceType> InstanceType* 
00565 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getSTInstance(const string& objectId, const int& slice)
00566 {
00567         map<string, vector<int> >::iterator itObj = objectIdToInstances_.find(objectId);
00568         if(itObj==objectIdToInstances_.end())
00569                 return 0;
00570 
00571         if(slice<0)
00572         {
00573                 //The slice is not considered
00574                 vector<int>::iterator it = itObj->second.begin();
00575                 if(it==itObj->second.end())
00576                         return 0;
00577                 return getSTInstance(*it);
00578         }
00579 
00580         map<int, vector<int> >::iterator itSlice = sliceToInstances_.find(slice);
00581         if(itSlice==sliceToInstances_.end())
00582                 return 0;
00583 
00584         vector<int>::iterator it = itObj->second.begin();
00585         while(it != itObj->second.end())
00586         {
00587                 vector<int>::iterator it2;
00588                 it2 = find(itSlice->second.begin(), itSlice->second.end(), *it);
00589                 if(it2!=itSlice->second.end())
00590                         return getSTInstance(*it2);
00591                 ++it;
00592         }
00593         return 0;               
00594 }
00595 
00596 template<typename GeometryType, typename TimeType, typename InstanceType> InstanceType* 
00597 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getSTInstance(const string& objectId, TimeType& time, const int& slice)
00598 {
00599         map<string, vector<int> >::iterator itObj = objectIdToInstances_.find(objectId);
00600         if(itObj==objectIdToInstances_.end())
00601                 return 0;
00602 
00603         typename map<TimeType, vector<int> >::iterator itTime = timeToInstances_.find(time);
00604         if(itTime==timeToInstances_.end())
00605                 return 0;
00606         
00607         if(slice<0)
00608         {
00609                 //The slice is not considered
00610                 vector<int>::iterator it = itObj->second.begin();
00611                 while(it != itObj->second.end())
00612                 {
00613                         vector<int>::iterator it2;
00614                         it2 = find(itTime->second.begin(), itTime->second.end(), *it);
00615                         if(it2!=itTime->second.end())
00616                                 return getSTInstance(*it2);
00617                         ++it;
00618                 }
00619                 return 0;
00620         }
00621         
00622         map<int, vector<int> >::iterator itSlice = sliceToInstances_.find(slice);
00623         if(itSlice==sliceToInstances_.end())
00624                 return 0;
00625 
00626         vector<int>::iterator it = itObj->second.begin();
00627         while(it != itObj->second.end())
00628         {
00629                 vector<int>::iterator it2, it3;
00630                 it2 = find(itTime->second.begin(), itTime->second.end(), *it);
00631                 it3 = find(itSlice->second.begin(), itSlice->second.end(), *it);
00632                 if((it2!=itTime->second.end()) && (it3!=itSlice->second.end()))
00633                         return getSTInstance(*it2);
00634                 ++it;
00635         }
00636         return 0;
00637 }
00638 
00639 template<typename GeometryType, typename TimeType, typename InstanceType> void
00640 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getSTInstances(vector<InstanceType* >& set, const string& objectId, const int& slice)
00641 {
00642         set.clear();
00643         map<string, vector<int> >::iterator itObj = objectIdToInstances_.find(objectId);
00644         if(itObj==objectIdToInstances_.end())
00645                 return;
00646 
00647         vector<int>::iterator it = itObj->second.begin();
00648         while(it != itObj->second.end())
00649         {
00650                 InstanceType* inst = getSTInstance(*it);
00651                 if((slice<0) || (inst->getSlice()==slice))
00652                         set.push_back(inst);
00653                 ++it;
00654         }
00655         return;
00656 }
00657 
00658 template<typename GeometryType, typename TimeType, typename InstanceType> void
00659 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getSTInstances(vector<InstanceType* >& set, const string& objectId, TimeType& time, const int& slice)
00660 {
00661         set.clear();
00662         map<string, vector<int> >::iterator itObj = objectIdToInstances_.find(objectId);
00663         if(itObj==objectIdToInstances_.end())
00664                 return;
00665 
00666         vector<int>::iterator it = itObj->second.begin();
00667         while(it != itObj->second.end())
00668         {
00669                 InstanceType* inst = getSTInstance(*it);
00670                 if(((slice<0) || (inst->getSlice()==slice)) && (inst->getTime()== time))
00671                         set.push_back(inst);
00672                 ++it;
00673         }
00674         return;
00675 }
00676         
00677 template<typename GeometryType, typename TimeType, typename InstanceType> void
00678 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getSTInstances(vector<InstanceType* >& set, TimeType& time, const int& slice)
00679 {
00680         set.clear();
00681         typename map<TimeType, vector<int> >::iterator itTime = timeToInstances_.find(time);
00682         if(itTime==timeToInstances_.end())
00683                 return;
00684 
00685         vector<int>::iterator it = itTime->second.begin();
00686         while(it != itTime->second.end())
00687         {
00688                 InstanceType* inst = getSTInstance(*it);
00689                 if((slice<0) || (inst->getSlice()==slice))
00690                         set.push_back(inst);
00691                 ++it;
00692         }
00693         return;
00694 
00695 }
00696 
00697 template<typename GeometryType, typename TimeType, typename InstanceType> void
00698 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getSTInstances(vector<InstanceType* >& set, const int& slice)
00699 {
00700         set.clear();
00701         map<int, vector<int> >::iterator itSlice = sliceToInstances_.find(slice);
00702         if(itSlice==sliceToInstances_.end())
00703                 return;
00704 
00705         vector<int>::iterator it = itSlice->second.begin();
00706         while(it != itSlice->second.end())
00707         {
00708                 set.push_back(getSTInstance(*it));
00709                 ++it;
00710         }
00711         return;
00712 }
00713 
00714 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00715 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::insertSTInstance (InstanceType& inst)
00716 {
00717         inst.setAttrList(attrList_);
00718         instances_.push_back(inst);
00719         int index = (instances_.size()-1);
00720         vector<int> aux;
00721         aux.push_back(index);
00722         
00723         //object identity information
00724         map<string, vector<int> >::iterator itObj = objectIdToInstances_.find(inst.getObjectId());
00725         if(itObj!=objectIdToInstances_.end())
00726                 itObj->second.push_back(index);
00727         else
00728                 objectIdToInstances_[inst.getObjectId()] = aux;
00729 
00730         //time information
00731         if(inst.isTimeValid())
00732         {
00733                 typename map<TimeType, vector<int> >::iterator itTime = timeToInstances_.find(inst.getTime());
00734                 if(itTime!=timeToInstances_.end())
00735                         itTime->second.push_back(index);
00736                 else
00737                         timeToInstances_[inst.getTime()] = aux;
00738         }
00739 
00740         //slice information
00741         if(inst.getSlice()>=0)
00742         {
00743                 map<int, vector<int> >::iterator itSlice = sliceToInstances_.find(inst.getSlice());
00744                 if(itSlice!=sliceToInstances_.end())
00745                         itSlice->second.push_back(index);
00746                 else
00747                         sliceToInstances_[inst.getSlice()] = aux;
00748         }
00749         
00750         //insert in the RTree
00751         TeBox b = inst.getGeometries().box();
00752         if(b.isValid())
00753         {
00754                 if(rTree_)
00755                         rTree_->insert(b, index);
00756                 updateBox(box_, b);
00757         }
00758         return true;
00759 }
00760 
00761 template<typename GeometryType, typename TimeType, typename InstanceType> int 
00762 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::numSTInstance()
00763 {
00764         return instances_.size();
00765 }
00766                 
00767 template<typename GeometryType, typename TimeType, typename InstanceType> int 
00768 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::numSTInstance(const string& objectId)
00769 {
00770         map<string, vector<int> >::iterator it = objectIdToInstances_.find(objectId);
00771         if(it==objectIdToInstances_.end())
00772                 return 0;
00773         return it->second.size();
00774 
00775 }
00776 
00777 template<typename GeometryType, typename TimeType, typename InstanceType> int 
00778 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::numSTInstance(const int& slice)
00779 {
00780         map<int, vector<int> >::iterator it = sliceToInstances_.find(slice);
00781         if(it==sliceToInstances_.end())
00782                 return 0;
00783         return it->second.size();
00784 }
00785 
00786 template<typename GeometryType, typename TimeType, typename InstanceType> int 
00787 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::numSTInstance(TimeType& time)
00788 {
00789         typename map<TimeType, vector<int> >::iterator it = timeToInstances_.find(time);
00790         if(it==timeToInstances_.end())
00791                 return 0;
00792         return it->second.size();
00793 }
00794 
00795 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00796 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::setGeometry(const string& object_id, GeometryType& geom, const int& slice)
00797 {
00798         InstanceType* aux = this->getSTInstance(object_id, slice);
00799         if(!aux)
00800                 return false;
00801         aux->setGeometry(geom);
00802         return true;
00803 }
00804 
00805 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00806 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::setGeometry(const string& object_id, GeometryType& geom, TimeType& time, const int& slice)
00807 {
00808         InstanceType* aux = this->getSTInstance(object_id, time, slice);
00809         if(!aux)
00810                 return false;
00811         aux->setGeometry(geom);
00812         return true;
00813 }
00814 
00815 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00816 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getGeometry(const string& object_id, GeometryType& geom, const int& slice)
00817 {
00818         InstanceType* aux = this->getSTInstance(object_id, slice);
00819         if(!aux)
00820                 return false;
00821         geom = aux->getGeometries(); 
00822         return true;
00823 
00824 }
00825 
00826 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00827 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getGeometry(const string& object_id, GeometryType& geom, TimeType& time, const int& slice)
00828 {
00829         InstanceType* aux = this->getSTInstance(object_id, time, slice);
00830         if(!aux)
00831                 return false;
00832         geom = aux->getGeometries(); 
00833         return true;
00834 }
00835 
00836 
00837 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00838 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getPropertyVector (const string& object_id, TePropertyVector& propVec, const int& slice)
00839 {
00840         propVec.clear();
00841         InstanceType* aux = this->getSTInstance(object_id, slice);
00842         if(!aux)
00843                 return false;
00844         
00845         for(unsigned int i=0; i<aux->getProperties().size(); ++i)
00846         {
00847                 TeProperty prop;
00848                 prop.value_ = aux->getProperties()[i];
00849                 if(i<attrList_->size())
00850                         prop.attr_ = (*attrList_)[i];
00851                 propVec.push_back(prop);
00852         }
00853         return true;
00854 }
00855 
00856 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00857 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getPropertyVector (const string& object_id, 
00858         TePropertyVector& propVec, TimeType& time, const int& slice)
00859 {
00860         propVec.clear();
00861         InstanceType* aux = this->getSTInstance(object_id, time, slice);
00862         if(!aux)
00863                 return false;
00864         
00865         for(unsigned int i=0; i<aux->getProperties().size(); ++i)
00866         {
00867                 TeProperty prop;
00868                 prop.value_ = aux->getProperties()[i];
00869                 if(i<attrList_->size())
00870                         prop.attr_ = (*attrList_)[i];
00871                 propVec.push_back(prop);
00872         }
00873         return true;
00874 
00875 }
00876 
00877 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00878 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::setProperties (const string& object_id, const vector<string>& values, const int& slice)
00879 {
00880         //the number of attributes in each instance must be equal to the number of attibutes
00881         //in the attribute list. 
00882         if(values.size() != attrList_->size())
00883                 return false;
00884 
00885         InstanceType* aux = this->getSTInstance(object_id, slice);
00886         if(!aux)
00887                 return false;
00888         aux->setProperties(values);
00889         return true;
00890 }
00891 
00892 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00893 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::setProperties (const string& object_id, const vector<string>& values, TimeType& time, const int& slice)
00894 {
00895         //the number of attributes in each instance must be equal to the number of attibutes
00896         //in the attribute list. 
00897         if(values.size() != attrList_->size())
00898                 return false;
00899 
00900         InstanceType* aux = this->getSTInstance(object_id, time, slice);
00901         if(!aux)
00902                 return false;
00903         aux->setProperties(values);
00904         return true;
00905 }
00906 
00907 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00908 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getProperties (const string& object_id, vector<string>& values, const int& slice)
00909 {
00910         values.clear();
00911         InstanceType* aux = this->getSTInstance(object_id, slice);
00912         if(!aux)
00913                 return false;
00914         values = aux->getProperties();
00915         return true;
00916 }
00917 
00918 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00919 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getProperties (const string& object_id, vector<string>& values, TimeType& time, const int& slice)
00920 {
00921         values.clear();
00922         InstanceType* aux = this->getSTInstance(object_id, time, slice);
00923         if(!aux)
00924                 return false;
00925         values = aux->getProperties();
00926         return true;
00927 }
00928 
00929 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00930 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::setAttributeValue (const string& object_id, const string& attr_name,  const string& val, const int& slice)
00931 {
00932         int index = this->getAttributeIndex(attr_name);
00933         return this->setAttributeValue(object_id, index, val, slice);
00934 }
00935 
00936 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00937 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::setAttributeValue (const string& object_id, const string& attr_name, const string& val, TimeType& time, const int& slice)
00938 {
00939         int index = this->getAttributeIndex(attr_name);
00940         return this->setAttributeValue(object_id, index, val, time, slice);
00941 }
00942 
00943 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00944 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::setAttributeValue (const string& object_id, const int& i, const string& val, const int& slice)
00945 {
00946         if(i<0 || i>=(int)attrList_->size()) //if there is not this attribute, return false 
00947                 return false;
00948         InstanceType* aux = this->getSTInstance(object_id, slice);
00949         if(!aux)
00950                 return false;
00951         aux->setPropertyValue(i, val); 
00952         return true;
00953 }
00954 
00955 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00956 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::setAttributeValue (const string& object_id, const int& i, const string& val, TimeType& time, const int& slice)
00957 {
00958         if(i<0 || i>=(int)attrList_->size()) //if there is not this attribute, return false 
00959                 return false;
00960         InstanceType* aux = this->getSTInstance(object_id, time, slice);
00961         if(!aux)
00962                 return false;
00963         aux->setPropertyValue(i, val); 
00964         return true;
00965 }
00966 
00967 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00968 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getAttributeValue (const string& object_id, const string& attr_name,  string& val, const int& slice)
00969 {
00970         int index = this->getAttributeIndex(attr_name);
00971         return this->getAttributeValue(object_id, index, val, slice);
00972 }
00973 
00974 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00975 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getAttributeValue (const string& object_id, const string& attr_name,  string& val, TimeType& time, const int& slice)
00976 {
00977         int index = this->getAttributeIndex(attr_name);
00978         return this->getAttributeValue(object_id, index, val, time, slice);
00979 }
00980 
00981 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00982 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getAttributeValue (const string& object_id, const int& i, string& val, const int& slice)
00983 {
00984         if(i<0 || i>=(int)attrList_->size())
00985                 return false;
00986         InstanceType* aux = this->getSTInstance(object_id, slice);
00987         if(!aux)
00988                 return false;
00989         val = aux->getProperties()[i];
00990         return true;
00991 }
00992 
00993 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
00994 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getAttributeValue (const string& object_id, const int& i, string& val, TimeType& time, const int& slice)
00995 {
00996         if(i<0 || i>=(int)attrList_->size())
00997                 return false;
00998         InstanceType* aux = this->getSTInstance(object_id, time, slice);
00999         if(!aux)
01000                 return false;
01001         val = aux->getProperties()[i];
01002         return true;
01003 }
01004 
01005 template<typename GeometryType, typename TimeType, typename InstanceType> bool
01006 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::addProperty(TeAttributeRep& attr, const string& defaultValue)
01007 {
01008         //verify if there is this attribute
01009         if(getAttributeIndex(attr.name_)>=0) 
01010                 return true;
01011 
01012         TeAttribute at;
01013         at.rep_ = attr;
01014         attrList_->push_back(at);
01015         typename vector<InstanceType>::iterator it = instances_.begin();        
01016         
01017         //the number of attributes in each instance must be equal to the number of attibutes
01018         //in the attribute list.
01019         if((attrList_->size()-1) != it->getProperties().size())
01020                 return false;
01021         while(it!=instances_.end())
01022         {       
01023                 it->addPropertyValue(defaultValue);
01024                 ++it;
01025         }
01026         return true;
01027 }
01028 
01029 template<typename GeometryType, typename TimeType, typename InstanceType> bool
01030 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::addProperty(TeAttribute& attr)
01031 {
01032         //verify if there is this attribute
01033         if(getAttributeIndex(attr.rep_.name_)<0) 
01034                 attrList_->push_back(attr);
01035         return true;
01036 }
01037 
01038 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
01039 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::addProperty(const string& object_id, TeProperty& prop, const int& slice)
01040 {
01041         int index = this->getAttributeIndex(prop.attr_.rep_.name_); 
01042         if(index<0)
01043         {
01044                 //adds this new attribute in the attr list and in all instances
01045                 attrList_->push_back(prop.attr_);
01046                 typename vector<InstanceType>::iterator it =    instances_.begin();             
01047                 while(it!=instances_.end())
01048                 {
01049                         if( (object_id == it->getObjectId()) && ((slice<0) || (slice==it->getSlice())))  
01050                                 it->addPropertyValue(prop.value_);
01051                         else
01052                                 it->addPropertyValue(string(""));
01053                         ++it;
01054                 }
01055                 return true;
01056         }
01057         
01058         //Sets this attribute value
01059         typename vector<InstanceType>::iterator it =    instances_.begin();             
01060         while(it!=instances_.end())
01061         {
01062                 if( (object_id == it->getObjectId()) && ((slice<0) || (slice==it->getSlice())))  
01063                         it->setPropertyValue(index, prop.value_);
01064                 ++it;
01065         }
01066         return true;
01067 }
01068 
01069 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
01070 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::addProperty(const string& object_id, TeProperty& prop, TimeType& time, const int& slice)
01071 {
01072         int index = this->getAttributeIndex(prop.attr_.rep_.name_); 
01073         if(index<0)
01074         {
01075                 //adds this new attribute in the attr list and in all instances
01076                 attrList_->push_back(prop.attr_);
01077                 typename vector<InstanceType>::iterator it =    instances_.begin();             
01078                 while(it!=instances_.end())
01079                 {
01080                         if( (object_id == it->getObjectId()) && 
01081                                 (time == it->getTime()) && 
01082                                 ((slice<0) || (slice==it->getSlice())))  
01083                                 it->addPropertyValue(prop.value_);
01084                         else
01085                                 it->addPropertyValue(string(""));
01086                         ++it;
01087                 }
01088                 return true;
01089         }
01090         
01091         //Sets this attribute value
01092         typename vector<InstanceType>::iterator it =    instances_.begin();             
01093         while(it!=instances_.end())
01094         {
01095                 if( (object_id == it->getObjectId()) && 
01096                         (time == it->getTime()) && 
01097                         ((slice<0) || (slice==it->getSlice())))  
01098                         it->setPropertyValue(index, prop.value_);
01099                 ++it;
01100         }
01101         return true;
01102 }
01103 
01104 template<typename GeometryType, typename TimeType, typename InstanceType> void
01105 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::removeProperty(TeAttributeRep& attr)
01106 {
01107         //Remove of the attribute list
01108         string newName = TeConvertToUpperCase(attr.name_); 
01109         size_t pos = attr.name_.find(".", 0, 1);
01110         if (pos != string::npos)
01111                 newName = TeConvertToUpperCase(attr.name_.substr(pos+1));
01112         
01113         unsigned int index = 0;
01114         TeAttributeList::iterator it = attrList_->begin();
01115         while(it!=attrList_->end())
01116         {
01117                 string s = TeConvertToUpperCase(it->rep_.name_); 
01118                 if((s == TeConvertToUpperCase(attr.name_)) || (s == newName))
01119                 {
01120                         attrList_->erase(it);
01121                         break;
01122                 }
01123                 ++it;
01124                 ++index;
01125         }
01126 
01127         //Remove of all instances
01128         typename vector<InstanceType>::iterator it2 = instances_.begin();               
01129         while(it2!=instances_.end())
01130         {
01131                 it2->removePropertyValue(index);
01132                 ++it2;
01133         }
01134 }
01135 
01136 template<typename GeometryType, typename TimeType, typename InstanceType> TeBox& 
01137 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::getBox()
01138 {
01139         if(box_.isValid())
01140                 return box_;
01141 
01142         if (instances_.size() <= 0)
01143                 return box_;
01144 
01145         typename TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::iterator it = this->begin();
01146         
01147         while (it != this->end())
01148         {
01149                 updateBox(box_,it->getGeometries().box());
01150                 ++it;
01151         }
01152         return box_;
01153 }
01154 
01155 template<typename GeometryType, typename TimeType, typename InstanceType> void 
01156 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::clear()
01157 {
01158         instances_.clear();
01159         attrList_->clear();
01160         objectIdToInstances_.clear();
01161         timeToInstances_.clear();
01162         sliceToInstances_.clear();
01163         if(rTree_)
01164                 rTree_->clear(); 
01165 }
01166 
01167 template<typename GeometryType, typename TimeType, typename InstanceType> void 
01168 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::clearInstances()
01169 {
01170         instances_.clear();
01171 }
01172 
01173 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
01174 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::search(const TeBox& b, vector<InstanceType* >& result)
01175 {
01176         if(!rTree_ )
01177                 return false;
01178 
01179         vector<int> intResult;
01180         rTree_->search(b, intResult);
01181         for(unsigned int i=0; i<intResult.size(); ++i)
01182                 result.push_back(getSTInstance(intResult[i])); 
01183         return true;
01184 }
01185 
01186 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
01187 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::build(bool loadGeometries, bool loadAllAttributes, vector<string> attrNames, int slide)
01188 {
01189         TeQuerierParams param;
01190         if(theme_)
01191                 param.setParams(theme_);
01192         else if(layer_)
01193                 param.setParams(layer_);
01194         else
01195                 return false;
01196 
01197         param.setFillParams(loadGeometries, loadAllAttributes, attrNames);
01198         TeQuerier querier(param);
01199         return(buildImpl(&querier, slide));
01200 }
01201 
01202 template<typename GeometryType, typename TimeType, typename InstanceType> bool 
01203 TeBaseSTInstanceSet<GeometryType, TimeType, InstanceType>::build(TeGroupingAttr& groupAttr, bool loadGeometries, int slide)
01204 {
01205         TeQuerierParams param;
01206         if(theme_)
01207                 param.setParams(theme_);
01208         else if(layer_)
01209                 param.setParams(layer_);
01210         else
01211                 return false;
01212 
01213         param.setFillParams(loadGeometries, groupAttr);
01214         TeQuerier querier(param);
01215         return(buildImpl(&querier, slide));
01216 }
01217 
01218 
01219 #endif
01220 

Generated on Sun Jul 29 04:01:19 2012 for TerraLib - Development Source by  doxygen 1.5.3