TeLayer.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 TeLayer.h
00024     \brief This file contains structures and definitions to deal with a layer
00025 */
00026 #ifndef __TERRALIB_INTERNAL_LAYER_H
00027 #define __TERRALIB_INTERNAL_LAYER_H
00028 
00029 #include "TeGeometry.h"
00030 #include "TeDataTypes.h"
00031 #include "TeTable.h"
00032 #include "TeRepresentation.h"
00033 
00034 #include <string>
00035 #include <list>
00036 #include <map>
00037 
00038 class TeRaster;
00039 class TeDatabase;
00040 class TeRasterParams;
00041 class TeProjection;
00042 
00043 //!  A class for supporting a layer. 
00044 /*!  
00045          In TerraLib, a layer is a collection of geometries that share the same 
00046      geographical projection, and are related in some way (e.g. a shapefile).
00047          A layer has a pointer to a database that effectively stores its atributes
00048          and geometries.
00049          
00050         \sa
00051      TeGeometry, TeProjection, TeBox, TeDatabase, TeTheme, TeTable
00052 */
00053 class TL_DLL TeLayer {
00054 
00055 public:
00056 
00057         //! Empty constructor
00058         TeLayer():
00059                 id_(-1),
00060                 db_(0),
00061                 projection_ ( 0 ),
00062                 raster_(0)
00063                 { }
00064 
00065                 
00066         //! Constructor with parameters
00067         /* 
00068                 \param name layer name (should be unique)
00069                 \param db a TerraLib database connection w
00070                 \param proj layer projection
00071                 \note 
00072                         \par If no database is informed, layer will exist only in memory.
00073                         \par If a layer with this name doesn´t exist a layer will be 
00074                          created and stored. If no projection is informed a default TeNoProjection
00075                          will be used as layer projection.
00076             \par If a layer with this name already exists it will be retrieved
00077         */       
00078         TeLayer(const string& name, TeDatabase* db=0, TeProjection* proj=0);
00079 
00080         //! Constructor with parameters
00081         /* 
00082                 \param name layer name (should be unique)
00083                 \param db TerraLib database connection where layer will be stored
00084                 \param box layer bounding box
00085                 \param proj layer projection
00086                 \note 
00087                         \par If no database is informed, layer will exist only in memory.
00088                         \par If a layer with this name doesn´t exist a layer will be 
00089                          created and stored. If no projection is informed a default TeNoProjection
00090                          will be used as layer projection.
00091             \par If a layer with this name already exists it will be retrieved
00092         */
00093         TeLayer(const string& name, TeDatabase* db, TeBox& box, TeProjection* proj = 0);
00094 
00095         //! Destructor
00096         virtual ~TeLayer();
00097 
00098         //! Copy Constructor
00099         TeLayer ( const TeLayer& other );
00100 
00101         //! Operator =
00102         TeLayer& operator= ( const TeLayer& other );
00103         
00104         //! Retrieves the database associated to this layer
00105         virtual TeDatabase* const database() 
00106         { return db_; }
00107 
00108         //! Sets the layer database
00109         virtual void setDatabase(TeDatabase* db)
00110         { db_ = db; }
00111 
00112         //! Returns the layer id
00113         virtual int id()
00114         { return id_; } 
00115 
00116         //! Sets the layer id
00117         virtual void id(int id)
00118         { id_ = id; } 
00119 
00120         //! Returns the layer name
00121         virtual string name()
00122         { return name_; }
00123 
00124         //! Sets the layer name
00125         virtual void name(const string &name)
00126         {  name_ = name; }
00127 
00128         //! Sets the  layer projection
00129         virtual void  setProjection ( TeProjection* proj );
00130 
00131         //! Retrieves the layer projection
00132         virtual TeProjection* projection()
00133         {       return projection_; }
00134 
00135         //! Returns the layer bounding box
00136         virtual TeBox&  box()
00137         {       return box_; }
00138 
00139         //! Sets the  bounding box of a layer
00140         virtual void setLayerBox ( const TeBox& box );
00141 
00142         //! Updates the bounding box of a layer
00143         virtual void updateLayerBox(const TeBox& box);
00144 
00145         //! Refreshes the bounding box of a layer according to its representation
00146         virtual void updateLayerBox();
00147 
00148         //! Returns a possible new object id based on the objects stored in database
00149         virtual int getNewObjectId();
00150 
00151         /** @name Attribute Tables
00152         *  Methods to deal with the attribute tables of the layer
00153         */
00154         //@{
00155 
00156         //! Returns the number of distinct objects in the layer
00157         virtual int nObjects(const string& tName);
00158 
00159         //! Returns a vector with the definition of all attribute tables associated to layer
00160         virtual TeAttrTableVector& attrTables () 
00161         { return attTables_; }
00162 
00163   //! Returns a vector with the definition of all attribute tables associated to layer
00164         virtual const TeAttrTableVector& attrTables () const
00165         { return attTables_; }
00166 
00167         //! Creates a new attribute table for the layer
00168         virtual bool createAttributeTable(TeTable& table);
00169 
00170     //! Adds an attribute table definition to layer vector of attribute tables (in memory)
00171         virtual bool addAttributeTable(TeTable& table);
00172 
00173     //! Remove an attribute table definition to layer vector of attribute tables (in memory)
00174         virtual bool removeAttributeTable(string tableName);
00175 
00176      //! Update an attribute table definition to layer vector of attribute tables (in memory)
00177         virtual void updateAttributeTable(TeTable& table);
00178 
00179         //! Reload the tables definition from database to memory
00180         virtual bool loadLayerTables();
00181 
00182         //! Saves an attribute table into the database where layer is stored 
00183         virtual bool saveAttributeTable(TeTable& table);
00184 
00185         //! Gets all attribute tables associated to this layer that are of a certain type
00186         virtual bool getAttrTables(TeAttrTableVector& atts, TeAttrTableType attType = TeAllAttrTypes);
00187 
00188         //! Gets a set of attribute table specifications associated to this layer that are of a certain type
00189         /*
00190                 \param tableNames a vector that contains the name of the tables that are being searched
00191                 \param attType type of table that is being searched
00192                 \param atts returns a vector of tables found
00193                 \return true if at least one table was found and false otherwise
00194         */
00195         virtual bool getAttrTablesByName(vector<string> &tableNames, TeAttrTableVector& atts, TeAttrTableType attType = TeAllAttrTypes);
00196 
00197         //! Gets an attribute table associated to a layer
00198         /*
00199                 \param tableName name of the table being searched
00200                 \param attType type of table being searched
00201                 \param table returns the table found
00202                 \return true if table was found and false otherwise
00203         */
00204         virtual bool getAttrTablesByName(const string& tableName, TeTable& table, TeAttrTableType attType = TeAllAttrTypes);
00205 
00206         //! Gets the name of the media table associated to layer
00207         virtual string mediaTable();
00208 
00209         //! Sets the name of the media table associated to layer
00210         virtual void mediaTable(const string& name);
00211         //@}
00212 
00213         /** @name Geometries
00214         *  Methods to deal with the geometries of the objects of a layer
00215         */
00216         //! Returns a pointer to the raster geometry associated to an object of this layer
00217         /*!
00218                 \param objectId unique identification of the object (if empty it will look
00219                 for the first raster geometry found)
00220                 \param mode permission access ('r', 'w')
00221         */
00222         virtual TeRaster* raster(const string& objectId="",const char& mode = 'r');
00223 
00224         //! Sets the pointer to the raster representation
00225         virtual void raster( TeRaster* raster);
00226 
00227         //! Retrieves a polygon set given a selection criteria, expressed as a where clause 
00228         virtual bool getPolygons(TePolygonSet &ps, const string& whereClause = "");
00229 
00230         //! Retrieves a line set given a selection criteria, expressed as a where clause 
00231         virtual bool getLines(TeLineSet &ls, const string& whereClause = "");
00232 
00233         //! Retrieves a point set given a selection criteria, expressed as a where clause 
00234         virtual bool getPoints(TePointSet &ps, const string& whereClause = "");
00235 
00236         //! Retrieve a point set given a selection criteria, expressed as a where clause
00237         virtual bool getText(TeTextSet &ts, const string& whereClause = "");
00238 
00239         //! Retrieve a cell set given a selection criteria, expressed as a where clause
00240         virtual bool getCells(TeCellSet &cs, const string& whereClause = "");
00241 
00242         //! Locates a polygon that cointains a certain coordinate
00243         virtual bool locatePolygon(TeCoord2D &pt, TePolygon &polygon, const double& tol = 0.0);
00244         
00245         //! Locates a line that cointains a certain coordinate
00246         virtual bool locateLine(TeCoord2D &pt, TeLine2D &line, const double& tol = 0.0);
00247 
00248         //! Retrieves a point that cointains a certain coordinate
00249         virtual bool locatePoint(TeCoord2D &pt, TePoint &point, const double& tol = 0.0);
00250 
00251         //! Retrieves a TeText that cointains a certain coordinate
00252         virtual bool locateText(TeCoord2D &pt, TeText &text, const double& tol = 0.0);
00253 
00254         //! Retrieves a point that cointains a certain coordinate
00255         virtual bool locateCell(TeCoord2D &pt, TeCell &cell, const double& tol = 0.0);
00256 
00257         //! Retrieves the set of polygons with a certain geoid
00258         virtual bool loadGeometrySet    (const string& geoid, TePolygonSet &ps);
00259 
00260         //! Retrieves the set of lines with a certain geoid
00261         virtual bool loadGeometrySet (const string& geoid, TeLineSet &ls);
00262 
00263         //! Retrieves the set of points with a certain geoid
00264         virtual bool loadGeometrySet (const string& geoid, TePointSet &ps);
00265 
00266         //! Retrieves the set of points with a certain geoid
00267         virtual bool loadGeometrySet (const string& geoid, TeCellSet &cs);
00268 
00269         //! Retrieves the set of texts with a certain geoid
00270         virtual bool loadGeometrySet (const string& geoid, TeTextSet &cs);
00271         
00272         //! Adds a set of polygons to a layer
00273         virtual bool addGeometrySet(TePolygonSet& polySet, const string& /* tName */ = "")
00274         { return addPolygons(polySet); }
00275 
00276         //! Adds a set of lines to a layer
00277         virtual bool addGeometrySet(TeLineSet& lineSet, const string& /* tName */ = "")
00278         { return addLines(lineSet); }
00279 
00280         //! Adds a set of points to a layer
00281         virtual bool addGeometrySet(TePointSet& pointSet, const string& /* tName */ = "")
00282         { return addPoints(pointSet); }
00283 
00284         //! Adds a set of text to a layer
00285         virtual bool addGeometrySet(TeTextSet& textSet, const string& tName = "")
00286         { return addText(textSet,tName); }
00287         
00288         //! Adds a set of cells to a layer
00289         virtual bool addGeometrySet(TeCellSet& cellSet, const string& /* tName */ = "")
00290         { return addCells(cellSet); }
00291 
00292         //! Adds a set of polygons to a layer
00293         virtual bool addPolygons(TePolygonSet& polySet);
00294 
00295         //! Adds a set of lines to a layer
00296         virtual bool addLines (TeLineSet& lineSet);
00297 
00298         //! Adds a set of points to a layer
00299         virtual bool addPoints (TePointSet& pointSet);
00300 
00301         //! Adds a set of text to a layer
00302         virtual bool addText (TeTextSet& textSet,const string& tName);
00303         
00304         //! Adds a set of cells to a layer
00305         virtual bool addCells(TeCellSet& cellSet);
00306 
00307         //! Updates a set of polygons to a layer
00308         virtual bool updatePolygons(TePolygonSet& polySet);
00309 
00310         //! Updates a set of lines to a layer
00311         virtual bool updateLines (TeLineSet& lineSet);
00312 
00313         //! Updates a set of points to a layer
00314         virtual bool updatePoints (TePointSet& pointSet);
00315 
00316         //! Updates a set of text to a layer
00317         virtual bool updateText (TeTextSet& textSet,const string& tName);
00318         
00319         //! Updates a set of cells to a layer
00320         virtual bool updateCells(TeCellSet& cellSet);
00321 
00322         //! Removes the geometries from the layer
00323         virtual bool removeGeometries(const std::vector<int>& vecGeomIds, const TeGeomRep& rep);
00324 
00325         //@}
00326 
00327         /** @name Geometries
00328         *  Methods to deal with geometrical representations of a layer
00329         */
00330         //! Removes a geometry from layer
00331         virtual bool removeGeometry (TeGeomRep repType, const string& tName="");
00332 
00333         //! Indicates if layer has a geometry representation
00334         virtual bool hasGeometry (TeGeomRep rep);
00335 
00336     //! Retrieves the table name associated to a geometry representation
00337         /*! \param rep geometrical representation
00338                 \note When there is more than one representation of a given type
00339                  returns the table name associated to the first one encountered
00340         */
00341         virtual string tableName(TeGeomRep rep); 
00342 
00343         //! Retrieves the number of geometries of a type
00344         /*! 
00345                 \param rep geometrical representation
00346         */      
00347         virtual int nGeometries(TeGeomRep rep);
00348 
00349         //! Gets all information about a representation
00350         virtual bool getRepresentation(TeGeomRep repType, TeRepresPointerVector& result);
00351 
00352         //! Gets an specific representation
00353         /*! 
00354                 \param repType the geometrical representation being searched
00355                 \param tableName the table associated to this representation
00356                 \return the representation associated to a geometry with the given table name
00357                 \note if no table name is specified the first found is returned
00358         */
00359         virtual TeRepresentation* getRepresentation(TeGeomRep repType, const string& tableName="");
00360     
00361         //! Creates a new geometry representation to a layer
00362         /*
00363                 \param repType the geometrical representation being searched
00364                 \param tableName name of the table that will stored the geometries
00365                 \param desc description of the representation
00366                 \return true if success and false otherwise
00367         */
00368         virtual bool addGeometry ( TeGeomRep repType, const string& tableName="", const string& desc = "");
00369 
00370         //! Creates a new raster geometry to a layer
00371         /*
00372                 \param par raster parameters
00373                 \param objectId identifier of the object that has the raster geometry
00374                 \param tableName name of the table that will stored the geometries
00375                 \param desc description of the representation
00376                 \return true if success and false otherwise
00377         */
00378         virtual bool addRasterGeometry(TeRasterParams& par, const string& objectId, 
00379                                                    const string& tableName="", const string& desc="");
00380 
00381         //! Inserts a raster as a geometry of an object of the layer
00382         /*
00383                 \param raster a pointer to a raster object
00384                 \param objectId identifier of the object that has the raster geometry
00385                 \param tableName the name of the table that will store the geometry (optional)
00386                 \return true if success and false otherwise
00387                 \note if there is already raster geometry associated to the object with id
00388                 object id, this reference is deleted.
00389         */      
00390         bool addRasterGeometry(TeRaster* raster, const string& objectId="");
00391 
00392         //! Inserts a reference to a raster file as a raster geometry of an object of the layer
00393         /*
00394                 \param raster a pointer to a raster object
00395                 \param objectId identifier of the object that has the raster geometry
00396                 \param desc the description of the geometry (optional)
00397                 \return true if success and false otherwise
00398                 \note if there is already raster geometry associated to the object with id
00399                 object id, this reference is deleted.
00400         */      
00401         bool addRasterFileGeometry(TeRaster* raster, const string& objectId="", const string& desc="");
00402 
00403 
00404         //! Returns a vector with the identification of all objects of the layer that has a raster representation
00405         /*
00406                 \param objectIds a vector to return the identification of the objects with a raster representation
00407                 \param tilingType used to express that only some types of representations are looked for: 
00408                            0 any kind, 1 only the expansible and 2 only the non-expansible
00409                 \param box box spatial restriction
00410                 \return true if layer has at least one raster object and false otherwise
00411         */
00412         virtual bool getRasterGeometries(vector<string>& objectIds, unsigned int tilingType=0, const TeBox& box = TeBox());
00413 
00414         //! Returns a combination of all representations in the layer
00415         virtual int geomRep();
00416 
00417         //! Adds a representation to vector of representation of the layer
00418         virtual void addVectRepres(TeRepresentation* rep)
00419         {       repVector_.push_back(rep); }
00420 
00421         //! Returns a vector with all representations in the layer
00422         virtual TeRepresPointerVector& vectRepres()
00423         {       return repVector_; }
00424 
00425   virtual const TeRepresPointerVector& vectRepres() const
00426         {       return repVector_; }
00427 
00428         //!< Returns the dateTime that the layer was last edited.
00429         virtual TeTime getEditionTime() const;
00430 
00431         //!< Sets in memory the edition time of the layer
00432         virtual void setEditionTime(const TeTime& editionTime);
00433 
00434         //!< Updates the layer last edition time in memory and in the database
00435         virtual bool updateLayerEditionTime(const bool& setEditionToNow = true);
00436 
00437         //!< Reloads the edition time from the database 
00438         virtual bool reloadLayerEditionTime();
00439 
00440         //@}
00441 
00442 private:
00443 
00444 // -- Members
00445 
00446 // -- General Description of a layer
00447 
00448         string          name_;                                  //!< layer name
00449         int                     id_;                                    //!< layer unique identification
00450         TeDatabase*     db_;                                    //!< database connection to this layer
00451         TeProjection*   projection_;            //!< layer projection
00452         TeBox           box_;                                   //!< layer bounding box
00453         TeRaster*       raster_;                                //!< layer raster representation
00454 
00455         TeAttrTableVector       attTables_;     //!< Attributes associated to a layer
00456         TeRepresPointerVector repVector_;       //!< vector of representations associated to this layer
00457         TeTime          editionTime_;                   //!< Stores the last time that the layer was edited. 
00458 };
00459 
00460 //! A map from a integer unique identifier to a pointer to layer
00461 typedef map<int,TeLayer*> TeLayerMap;
00462 
00463 /** \example createLayer.cpp
00464         Shows how to create a layer in a TerraLib database, and insert some vectorial data in this new layer
00465  */
00466 
00467 /** \example addGeomRepresentation.cpp
00468         Shows how to create a point representation (centroid of polygons) to a layer in a TerraLib database.
00469  */
00470 #endif
00471 
00472 
00473 
00474 /*! \mainpage Terralib
00475  * <CENTER>
00476  * <H3> Instituto Nacional de Pesquisas Espaciais (INPE)</H3>
00477  * http://www.dpi.inpe.br/ \n
00478  * </CENTER>
00479  *
00480  * \section over Overview
00481  * \par
00482  * < Add here an overview of Terralib >
00483  * \par
00484  * < add here a description > 
00485  * \par
00486  * 
00487  * \section author Author
00488  * \par
00489  * DPI (Image Processing Division) at INPE (National Institute for Space Research)\n 
00490  * Tecgraf the Computer Graphics Technology Group of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro in Brazil) \n 
00491  * FUNCATE (Foundation for the Space Science, Applied Research and Technology). 
00492  * 
00493  *
00494  * \section copyright Copyright Notice
00495 \verbatim
00496 
00497 ****************************************************************************
00498 < add here the copyrights >
00499   
00500 ****************************************************************************
00501 \endverbatim
00502  */

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