| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/functions/TeLayerFunctions.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 *************************************************************************************/
    00026 #ifndef  __TERRALIB_INTERNAL_LAYERFUNCTIONS_H
    00027 #define  __TERRALIB_INTERNAL_LAYERFUNCTIONS_H
    00028
    00029 #include "../kernel/TeLayer.h"
    00030 #include "../kernel/TeVectorRemap.h"
    00031 #include "../kernel/TeTheme.h"
    00032 #include "../kernel/TeDatabase.h"
    00033 #include "../kernel/TeProgress.h"
    00034
    00035 #include "TeFunctionsDefines.h"
    00036
    00045 template <class G>
    00046 bool TeImportGeometriesToLayer(TeLayer* layer, G& geomSet)
    00047 {
    00048            if (!layer)
    00049
    00050                       return false;
    00051
    00052            TeDatabase* db = layer->database();
    00053            int nTab = 0;
    00054            TeAttrTableVector attTables;
    00055            if (layer->getAttrTables(attTables))
    00056                       nTab = attTables.size();
    00057
    00058            string tabName = "AttributeTable_" + Te2String(layer->id()) + "_" + Te2String(nTab);
    00059            TeAttributeList attList;
    00060            TeAttribute at;
    00061            at.rep_.type_ = TeSTRING;
    00062            at.rep_.numChar_ = 16;
    00063            at.rep_.name_ = "object_id";
    00064            at.rep_.isPrimaryKey_ = true;
    00065            attList.push_back(at);
    00066
    00067            TeTable attTable(tabName,attList,"object_id", "object_id",TeAttrStatic);
    00068
    00069            TeTableRow row;
    00070            for (int i=0; i<geomSet.size(); i++)
    00071            {
    00072                       row.clear();
    00073                       string id = geomSet[i].objectId();
    00074                       if (id.empty())
    00075                       {
    00076                                  id = Te2String(i);
    00077                                  geomSet[i].objectId(id);
    00078                       }
    00079                       row.push_back(id);
    00080                       attTable.add(row);
    00081            }
    00082
    00083            if (!layer->addGeometrySet(geomSet))
    00084            {
    00085                       attTable.clear();
    00086                       db->deleteLayer(layer->id());
    00087                       return false;
    00088            }
    00089
    00090            if (!layer->createAttributeTable(attTable))
    00091            {
    00092                       attTable.clear();
    00093                       db->deleteLayer(layer->id());
    00094                       return false;
    00095            }
    00096
    00097            if (!layer->saveAttributeTable(attTable))
    00098            {
    00099                       attTable.clear();
    00100                       db->deleteLayer(layer->id());
    00101                       return false;
    00102            }
    00103
    00104            attTable.clear();
    00105            return true;
    00106 }
    00107
    00114 template<typename GS>
    00115 GS*
    00116 TeCopyPortalGeometriesToLayer(TeDatabasePortal* portal, TeProjection* proj, TeLayer* layer, const string& tName="")
    00117 {
    00118            if (!portal ||!layer)
    00119                       return 0;
    00120
    00121            TeProjection* pfrom = TeProjectionFactory::make(proj->params());
    00122            TeProjection* pto = TeProjectionFactory::make(layer->projection()->params());
    00123            bool doRemap;
    00124            if (!pfrom || !pto || (pfrom->name() == "NoProjection" ||  pto->name() == "NoProjection") &&
    00125                       !(pfrom->name() == pto->name()))
    00126                       doRemap = false;
    00127            else
    00128                       doRemap= !(*pfrom == *pto);
    00129
    00130            if (doRemap)
    00131                       pfrom->setDestinationProjection(pto);
    00132
    00133            if (TeProgress::instance())
    00134                                  TeProgress::instance()->setTotalSteps(portal->numRows());
    00135
    00136            GS set1;
    00137            int n = 1;
    00138            bool flag=false;
    00139            do
    00140            {
    00141                       typename GS::value_type elemI;
    00142                       flag = portal->fetchGeometry(elemI);
    00143                       if (doRemap)
    00144                       {
    00145                                  typename GS::value_type elemO;
    00146                                  TeVectorRemap(elemI,pfrom,elemO,pto);
    00147                                  elemO.objectId(elemI.objectId());
    00148                                  set1.add(elemO);
    00149                       }
    00150                       else
    00151                       {
    00152                                  set1.add(elemI);
    00153                                  set1[set1.size()-1].objectId(elemI.objectId());
    00154                       }
    00155
    00156                       if (((n%100) == 0) || !flag)
    00157                       {
    00158                                  layer->addGeometrySet(set1,tName);
    00159                                  set1.clear();
    00160                                  if(TeProgress::instance())
    00161                                  {
    00162                                             if (TeProgress::instance()->wasCancelled())
    00163                                                        break;
    00164                                             else
    00165                                                        TeProgress::instance()->setProgress(n);
    00166                                  }
    00167                       }
    00168                       n++;
    00169            } while (flag);
    00170            delete pfrom;
    00171            delete pto;
    00172            if (TeProgress::instance())
    00173                       TeProgress::instance()->reset();
    00174
    00175            return 0;
    00176 }
    00177
    00185 TLFUNCTIONS_DLL bool TeCopyThemeToLayer(TeTheme* inTheme, TeLayer* outLayer,
    00186                                                                              int selObj, map<string,string> *txtTable=0);
    00187
    00195 TLFUNCTIONS_DLL bool TeCopyExternThemeToLayer(TeTheme* inTheme, TeLayer* outLayer,
    00196                                                                              int selObj, map<string,string> *txtTable=0);
    00197
    00204 TLFUNCTIONS_DLL bool TeCopyLayerToLayer(TeLayer* inLayer, TeLayer* outLayer, map<string,string> *txtTable=0);
    00205
    00209 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines