createProximityMatrix.cpp File Reference

#include "../../src/terralib/kernel/TeSTElementSet.h"
#include "../../src/terralib/kernel/TeSTEFunctionsDB.h"
#include "../../src/terralib/kernel/TeGeneralizedProxMatrix.h"
#include "../../src/terralib/drivers/MySQL/TeMySQL.h"

Go to the source code of this file.

Functions

int main ()


Function Documentation

int main (  ) 

Definition at line 37 of file createProximityMatrix.cpp.

References TeBaseSTInstanceSet< GeometryType, TimeType, InstanceType >::begin(), TeDatabase::close(), TeDatabase::connect(), TeGeneralizedProxMatrix< Set >::constructMatrix(), db, TeBaseSTInstanceSet< GeometryType, TimeType, InstanceType >::end(), TeDatabase::errorMessage(), TeGeneralizedProxMatrix< Set >::getMapNeighbours(), TeDatabase::loadLayer(), TeBaseSTInstanceSet< GeometryType, TimeType, InstanceType >::numElements(), TePOLYGONS, and TeSTOSetBuildDB().

00038 {       
00039         // Datatabase server parameters
00040         string host = "localhost";
00041         string dbname = "DB320RC1";
00042         string user = "root";
00043         string password = "vinhas";
00044 
00045         // Open a connection to the DB320RC1 MySQL database 
00046         TeDatabase* db = new TeMySQL();
00047         if (!db->connect(host, user, password, dbname))
00048         {
00049                 cout << "Error: " << db->errorMessage() << endl;
00050                 cout << endl << "Press Enter\n";
00051                 getchar();
00052                 return 1;
00053         }
00054         cout << "Connection successful to the database \"" << dbname << "\" on MySQL server \"" << host << "\" !\n";;
00055                 
00056         
00057         // Opens a connection to a TerraLib database 
00058     // Loads a layer named Distritos
00059         TeLayer* DistritosSP =  new TeLayer("Distritos");
00060         if (!db->loadLayer(DistritosSP))
00061         {
00062             cout << "Fail to load the layer!" << db->errorMessage() << endl;
00063                 db->close();
00064                 cout << endl << "Press Enter\n";
00065                 getchar();
00066         return 1;
00067         }
00068 
00069     
00070         // Creates a STElementSet from DistritosSP layer 
00071         TeSTElementSet steSet(DistritosSP);
00072 
00073         // Builds the STElementSet with geometries
00074         vector<string> attrs;
00075         if(!TeSTOSetBuildDB(&steSet, true, false, attrs))
00076         {
00077                 cout << "Error! " << endl;
00078                 cout << endl << "Press Enter\n";
00079                 getchar();
00080                 return 1;
00081         }
00082         
00083         // Shows how many elements the elementSet has
00084         cout << "Number of elements: " <<  steSet.numElements() << endl;
00085 
00086         
00087         //Create prox matrix strategies         
00088         TeProxMatrixLocalDistanceStrategy<TeSTElementSet>   sc_dist (&steSet, TePOLYGONS, 12000.00);
00089         TeGeneralizedProxMatrix<TeSTElementSet> proxMat(&sc_dist); 
00090 
00091         // Builds the proximity matrix
00092         if(!proxMat.constructMatrix())
00093         {
00094                 cout << "Error building proximity matrix! " << endl;
00095                 getchar();
00096                 db->close ();
00097                 return 0;
00098         }
00099 
00100         // Shows the neighbours of each object from proxMat
00101         TeSTElementSet::iterator it = steSet.begin();
00102         while ( it != steSet.end())
00103         {
00104                 cout<< " The neighbours of the element  "<< (*it).objectId() << " are: " << endl;
00105                         
00106                 // Gets the neighbours of an element
00107                 TeNeighboursMap neighbors = proxMat.getMapNeighbours((*it).objectId());
00108                 TeNeighboursMap::iterator itN = neighbors.begin();
00109                 while (itN != neighbors.end())
00110                 {
00111                         cout<< "         "<<(*itN).first << endl;
00112                         ++itN;
00113                 }
00114                 cout << endl;
00115                 ++it;
00116         }
00117 
00118         
00119         db->close();
00120         cout << endl << "Press Enter\n";
00121         getchar();
00122         return 0;
00123 }


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