| 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/drivers/qt/TeApplicationUtils.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_APPLICATIONUTILS_H
    00027 #define  __TERRALIB_INTERNAL_APPLICATIONUTILS_H
    00028
    00029 #include "TeAppTheme.h"
    00030 #include "../../kernel/TeVisual.h"
    00031 #include "../../kernel/TeDatabase.h"
    00032 #include "../../kernel/TeGeneralizedProxMatrix.h"
    00033
    00034 #include "../../kernel/TeDefines.h"
    00035
    00036 #include <string>
    00037 #include <vector>
    00038 #include <set>
    00039 using namespace std;
    00040
    00041 struct TeKernelParams;
    00042
    00043
    00044 struct TL_DLL ObjectInfo
    00045 {
    00046            int        status_;                                                          // collection: c_object_status
    00047            map<string, int> uniqueMap_;     // uniqueId to grid status (collection: grid_status)
    00048 };
    00049
    00062 TL_DLL bool createAppThemeTable(TeDatabase* db, bool integrity=false, const string& tableName="te_theme_application");
    00063
    00068 TL_DLL bool populateAppThemeTable(TeDatabase* db, const string& tableName="te_theme_application");
    00069
    00070
    00077 TL_DLL bool deleteAppTheme (TeDatabase* db, TeAbstractTheme* theme, const string& tableName="te_theme_application");
    00078
    00090 TL_DLL bool createMediaTable(TeDatabase* db, const string& tname);
    00091
    00097 TL_DLL bool createLayerMediaTable(TeDatabase* db, int layerId, const string& tname);
    00098
    00107 TL_DLL bool insertMedia(TeDatabase* db, const string& tableName, string& fileName, const string& description, const string& type, bool blob=true);
    00108
    00116 TL_DLL bool insertMediaObjLayer (TeDatabase* db, TeLayer* layer, const string& objectId, const string& mediaName, const string& mediaTable);
    00117
    00125 TL_DLL bool setDefaultMedia(TeDatabase* db, TeLayer* layer, const string& objectId, const string& mediaName, const string& mediaTable);
    00126
    00133 TL_DLL bool updateMediaDescription(TeDatabase* db, const string& mediaName, const string& mediaTable, const string& desc);
    00134
    00136 /*
    00137            \param db                        pointer do a TerraLib database
    00138            \param layerId                   if < 0 it is database information, else it is layer information
    00139            \param tableName      table name
    00140            \param fileName                  name of the file that contains the media information
    00141            \param type                                 file type. It can be ".TXT", ".DOC", ".MP3", etc. If URL it should be ".URL"
    00142 */
    00143 TL_DLL bool insertInfo2Blob(TeDatabase* db, int layerId, const string& tableName,  const string& fileName,  const string& type);
    00144
    00146 /*
    00147            \param db                        pointer do a TerraLib database
    00148            \param layerId                   if < 0 it is database information, else it is layer information
    00149            \param tableName      table name
    00150            \param type                                 file type. It can be ".TXT", ".DOC", ".MP3", etc. If URL it should be ".URL"
    00151            \return the temporary file that contains the blob
    00152 */
    00153 TL_DLL string getInfoBlob2TemporaryFile(TeDatabase* db, int layerId, const string& tableName, string& type);
    00166 TL_DLL bool createChartParamsTable(TeDatabase* db, bool integrity=false);
    00167
    00174 TL_DLL bool updateGridColor(TeDatabase* db, int themeId, TeObjectSelectionMode sel, TeColor& color);
    00186 TL_DLL bool createKernelMetadataTable(TeDatabase* db);
    00187
    00192 TL_DLL bool insertKernelMetadata(TeDatabase* db, TeKernelParams& kernelPar);
    00193
    00198 TL_DLL bool updateKernelMetadata(TeDatabase* db, TeKernelParams& kernelPar);
    00199
    00207 TL_DLL bool loadKernelParams (TeDatabase* db, int supThemeId, const string& supTableName, const string& supAttrName, TeKernelParams& KernelPar);
    00208
    00214 TL_DLL bool loadKernelParams (TeDatabase* db, int LayerId, TeKernelParams& KernelPar);
    00226 TL_DLL int createTeLayerMetadata(TeDatabase* db);
    00227
    00232 TL_DLL int createTeTableMetadata(TeDatabase* db);
    00239 TL_DLL bool deleteTextVisual(TeLayer* layer);
    00240
    00241
    00247 TL_DLL string deletePointedObjects(TeTheme* theme, TeBox& box);
    00248
    00255 TL_DLL string insertObjectIntoCollection(TeTheme* theme, TeCoord2D p, string newId, string newTId = "");
    00268 TL_DLL bool createGPMMetadataTable(TeDatabase* db, const bool& integrity=true);
    00269
    00274 TL_DLL bool createNeighbourhoodTable(TeDatabase* db, const string& tableName);
    00275
    00281 template<typename set>
    00282 bool insertGPM(TeDatabase* db, TeGeneralizedProxMatrix<set>* gpm, vector<string>& objs);
    00283
    00289 template<typename set>
    00290 bool loadDefaultGPM(TeDatabase* db, const int& themeId, TeGeneralizedProxMatrix<set>* &gpm);
    00291
    00297 TL_DLL bool deleteGPMTable(TeDatabase* db, const int& themeId, const int& gpmId=-1); // end of group  DatabaseUtils
    00301
    00302
    00308 TL_DLL bool loadAppTheme (TeDatabase* db, TeAppTheme *theme, const string& tableName="te_theme_application");
    00309
    00315 TL_DLL bool insertAppTheme (TeDatabase* db, TeAppTheme *theme, const string& tableName="te_theme_application");
    00316
    00322 TL_DLL bool updateAppTheme (TeDatabase* db, TeAppTheme *theme, const string& tableName="te_theme_application");
    00323
    00328 TL_DLL bool insertChartParams(TeDatabase* db, TeAppTheme *theme);
    00329
    00334 TL_DLL bool deleteChartParams (TeDatabase* db, TeAppTheme *theme);
    00335
    00342 TL_DLL bool locatePieBar (TeDatabase* db, TeAppTheme* theme, TeCoord2D pt, double delta);
    00343
    00348 TL_DLL bool loadChartParams (TeDatabase* db, TeAppTheme *theme);
    00349
    00355 TL_DLL bool updatePieBarLocation (TeDatabase* db, TeAppTheme* theme, TeCoord2D pt);
    00356
    00362 TL_DLL bool updatePointLocation (TeDatabase* db, TeAppTheme* theme, TeCoord2D pt);
    00363
    00364
    00366 TL_DLL bool generateCountLegends(TeAppTheme* theme, string table, string field);
    00367
    00368 TL_DLL void changeObjectStatus(ObjectInfo& info, string& uniqueId, string mode, int pointed = 1);
    00369
    00370 TL_DLL bool saveObjectStatus(TeAppTheme *theme, set<string>& objectSet, map<string, ObjectInfo>& objectMap);
    00371
    00372 TL_DLL TeStatisticType getStatisticFromString(const string& s);
    00373
    00374
    00375 TL_DLL void getVisual(TeAppTheme* theme, TeGeomRep geomRep,
    00376                                     map<string, TeVisual>& objVisualMap, set<string>& oidSet, bool allObjects);
    00377
    00378
    00379 // Implementation of the template functions
    00380 template<typename set>
    00381 bool insertGPM(TeDatabase* db, TeGeneralizedProxMatrix<set>* gpm, vector<string>& objs)
    00382 {
    00383            if(!db)
    00384                       return false;
    00385
    00386            TeProxMatrixConstructionParams* cParams = gpm->getConstructionParams();
    00387            TeProxMatrixSlicingParams*       sParams = gpm->getSlicingParams();
    00388            TeProxMatrixWeightsParams*   wParams = gpm->getWeightsParams();
    00389
    00390            if((!cParams) || (!sParams) || (!wParams))
    00391                       return false;
    00392
    00393            //update todas as gpms desse tema para default igual a zero
    00394            string up =  " UPDATE te_gpm SET gpm_default = 0 WHERE theme_id1 = "+ Te2String(cParams->theme_id1_);
    00395            db->execute (up);
    00396
    00397            // ----- progress bar
    00398            int step = 0;
    00399            if(TeProgress::instance())
    00400                       TeProgress::instance()->setTotalSteps(objs.size());
    00401            // -----
    00402
    00403            //insere na tabela de metadados
    00404            string ins = " INSERT INTO te_gpm (gpm_default, theme_id1, geom_rep1, theme_id2, ";
    00405            ins += " geom_rep2, neighbours_table, construction_date, construction_strategy, ";
    00406            ins += " const_max_distance, const_num_neighbours, const_max_net_distance, ";
    00407            ins += " const_max_con_distance, slicing_strategy, slicing_zone_dist, ";
    00408            ins += " slicing_zone_local, weight_strategy, weight_norm, weight_a, ";
    00409            ins += " weight_b, weight_c, weight_factor, weight_dist_raio, weigth_max_local_dist ) ";
    00410            ins += " VALUES ( ";
    00411            ins += " 1 ";
    00412            ins += ", "+ Te2String(cParams->theme_id1_);
    00413            ins += ", "+ Te2String((int)cParams->geom_rep1_);
    00414
    00415            if(cParams->theme_id2_<0)
    00416                       ins += ", NULL ";
    00417            else
    00418         ins += ", "+ Te2String(cParams->theme_id2_);
    00419
    00420            ins += ", "+ Te2String((int)cParams->geom_rep2_);
    00421            ins += ", '"+ gpm->neighbourhood_table_ +"'";
    00422            ins += ", NULL ";
    00423            ins += ", "+ Te2String((int)cParams->strategy_);
    00424            ins += ", "+ Te2String(cParams->max_distance_, 8);
    00425            ins += ", "+ Te2String(cParams->num_neighbours_);
    00426            ins += ", "+ Te2String(cParams->max_net_distance_, 8);
    00427            ins += ", "+ Te2String(cParams->max_connection_distance_, 8);
    00428            ins += ", "+ Te2String((int)sParams->strategy_);
    00429            ins += ", "+ Te2String(sParams->zone_dist_, 8);
    00430            ins += ", "+ Te2String((int)sParams->zone_local_);
    00431            ins += ", "+ Te2String((int)wParams->strategy_);
    00432            ins += ", "+ Te2String((int)wParams->norm_);
    00433            ins += ", "+ Te2String(wParams->a_, 8);
    00434            ins += ", "+ Te2String(wParams->b_, 8);
    00435            ins += ", "+ Te2String(wParams->c_, 8);
    00436            ins += ", "+ Te2String(wParams->factor_, 8);
    00437            ins += ", "+ Te2String(wParams->dist_ratio_, 8);
    00438            ins += ", "+ Te2String(wParams->max_local_dist_, 8);
    00439            ins += " )";
    00440
    00441            if(!db->execute (ins))
    00442            {
    00443                       if (TeProgress::instance())
    00444                                  TeProgress::instance()->reset();
    00445                       return false;
    00446            }
    00447
    00448            //insere na tabela de vizinhos
    00449            ins = " INSERT INTO "+ gpm->neighbourhood_table_;
    00450            ins += " (object_id1, object_id2, centroid_distance, weight, ";
    00451            ins += " slice, order_neig, borders_length, net_objects_distance, ";
    00452            ins += " net_minimum_path ) VALUES ( ";
    00453
    00454            vector<string>::iterator it = objs.begin();
    00455            while(it != objs.end())
    00456            {
    00457                       string objId1 = (*it);
    00458
    00459                       //get the neighbours
    00460                       TeNeighboursMap neigs = gpm->getMapNeighbours(objId1);
    00461                       TeNeighboursMap::iterator itNeig = neigs.begin();
    00462                       while(itNeig != neigs.end())
    00463                       {
    00464                                  string objId2 = itNeig->first;
    00465                                  TeProxMatrixAttributes attributes = itNeig->second;
    00466                                  //sql
    00467                                  string sql = "'"+ objId1 +"'";
    00468                                  sql += ", '"+ objId2 +"'";
    00469                                  sql += ", "+ Te2String(attributes.CentroidDistance(), 8);
    00470                                  sql += ", "+ Te2String(attributes.Weight(), 8);
    00471                                  sql += ", "+ Te2String(attributes.Slice());
    00472                                  sql += ", "+ Te2String(attributes.Order());
    00473                                  sql += ", "+ Te2String(attributes.BorderLength(), 8);
    00474                                  sql += ", "+ Te2String(attributes.NetworkObjectsDistance(), 8);
    00475                                  sql += ", "+ Te2String(attributes.NetworkMinimumPath(), 8);
    00476                                  sql += " )";
    00477
    00478                                  if(!db->execute(ins + sql))
    00479                                  {
    00480                                             if (TeProgress::instance())
    00481                                                        TeProgress::instance()->reset();
    00482                                             return false;
    00483                                  }
    00484                                  ++itNeig;
    00485                       }
    00486
    00487                       //progress bar
    00488                       if(TeProgress::instance())
    00489                       {
    00490                                  if (TeProgress::instance()->wasCancelled())
    00491                                  {
    00492                                             TeProgress::instance()->reset();
    00493                                             return false;
    00494                                  }
    00495                                  else
    00496                                             TeProgress::instance()->setProgress(step);
    00497                       }
    00498                       ++step;
    00499                       ++it;
    00500            }
    00501            if (TeProgress::instance())
    00502                       TeProgress::instance()->reset();
    00503            return true;
    00504 }
    00505
    00506 template<typename set>
    00507 bool loadDefaultGPM(TeDatabase* db, const int& themeId, TeGeneralizedProxMatrix<set>* &gpm)
    00508 {
    00509            if(!db)
    00510                       return false;
    00511
    00512            TeDatabasePortal* portal = db->getPortal();
    00513            if(!portal)
    00514                       return false;
    00515
    00516            //load the table name
    00517            string sql = " SELECT gpm_id, neighbours_table, weight_strategy, weight_norm, ";
    00518            sql += " weight_a, weight_b, weight_c, weight_factor, weight_dist_raio, ";
    00519            sql += " weigth_max_local_dist FROM te_gpm ";
    00520            sql += " WHERE theme_id1 = "+ Te2String(themeId) +" AND gpm_default = 1";
    00521            if(!portal->query(sql) || !portal->fetchRow())
    00522            {
    00523                       delete portal;
    00524                       return false;
    00525            }
    00526
    00527            string table = portal->getData(1);
    00528            int gpmId = portal->getInt(0);
    00529            int weightStrategy = portal->getInt(2);
    00530
    00531            //load weight strategy
    00532            TeProxMatrixWeightsStrategy* ws = 0;
    00533            if((TeGPMWeightsStrategy)weightStrategy==TeNoWeightsStrategy)
    00534                       ws = new TeProxMatrixNoWeightsStrategy((bool)portal->getInt(3));
    00535
    00536            else if((TeGPMWeightsStrategy)weightStrategy==TeInverseDistanceStrategy)
    00537                       ws = new TeProxMatrixInverseDistanceStrategy (portal->getDouble(4), portal->getDouble(5),
    00538                                             portal->getDouble(6), portal->getDouble(7), (bool)portal->getInt(3));
    00539
    00540            else if((TeGPMWeightsStrategy)weightStrategy==TeSquaredInverseDistStrategy)
    00541                       ws = new TeProxMatrixSquaredInverseDistanceStrategy (portal->getDouble(4), portal->getDouble(5),
    00542                                             portal->getDouble(6), portal->getDouble(7), (bool)portal->getInt(3));
    00543
    00544            else if((TeGPMWeightsStrategy)weightStrategy==TeConnectionStrenghtStrategy)
    00545                       ws = new TeProxMatrixConnectionStrenghtStrategy(portal->getDouble(8), portal->getDouble(9),
    00546                                             portal->getDouble(7),(bool)portal->getInt(3));
    00547
    00548            portal->freeResult();
    00549
    00550            sql= " SELECT count(*) FROM "+ table;
    00551            if(!portal->query(sql))
    00552            {
    00553                       delete portal;
    00554                       return false;
    00555            }
    00556            int numSteps = atoi(portal->getData(0));
    00557            int step = 0;
    00558            if(TeProgress::instance())
    00559                       TeProgress::instance()->setTotalSteps(numSteps);
    00560
    00561            portal->freeResult();
    00562
    00563            sql= " SELECT object_id1, object_id2, centroid_distance, weight, ";
    00564            sql += " slice, order_neig, borders_length, net_objects_distance, ";
    00565            sql += " net_minimum_path FROM "+ table;
    00566            if(!portal->query(sql))
    00567            {
    00568                       delete portal;
    00569                       return false;
    00570            }
    00571
    00572            TeProxMatrixImplementation* impl = TeProxMatrixAbstractFactory::MakeConcreteImplementation();
    00573            while(portal->fetchRow())
    00574            {
    00575                       TeProxMatrixAttributes attr(portal->getDouble(3), portal->getInt(4),
    00576                                  portal->getInt(5),  portal->getDouble(2), portal->getDouble(6),
    00577                                  portal->getDouble(7), portal->getDouble(8));
    00578
    00579                       impl->connectObjects (string(portal->getData(0)), string(portal->getData(1)), attr);
    00580
    00581                       if(TeProgress::instance())
    00582                       {
    00583                                  if (TeProgress::instance()->wasCancelled())
    00584                                  {
    00585                                             TeProgress::instance()->reset();
    00586                                             delete portal;
    00587                                             return false;
    00588                                  }
    00589                                  else
    00590                                             TeProgress::instance()->setProgress(step);
    00591                       }
    00592                       ++step;
    00593            }
    00594            if (TeProgress::instance())
    00595                       TeProgress::instance()->reset();
    00596
    00597            gpm = new TeGeneralizedProxMatrix<set>(gpmId, table, impl, ws);
    00598
    00599            delete portal;
    00600            return true;
    00601 }
    00602
    00603 template<typename T1>
    00604 TeCoord2D calculateLabelPosition(const T1& geomSet)
    00605 {
    00606            return TeCoord2D(0., 0.);
    00607 };
    00608
    00609 template<> TeCoord2D calculateLabelPosition(const TePolygonSet& geomSet);
    00610
    00611 template<> TeCoord2D calculateLabelPosition(const TeLine2D& geomSet);
    00612
    00615 TL_DLL bool getNextObject(TeDatabasePortal* portal, TePolygonSet& polys, TePolygon& nextPoly);
    00616
    00639 TL_DLL bool generateTextUsingCentroid(TeTheme* theme, const std::string& objectId = "");
    00640
    00641 #endif
    00642
    00643
    00644

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines