00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "../../src/terralib/kernel/TeSTElementSet.h"
00035 #include "../../src/terralib/kernel/TeSTEFunctionsDB.h"
00036 #include "../../src/terralib/drivers/MySQL/TeMySQL.h"
00037 #include "../../src/terralib/drivers/shapelib/TeDriverSHPDBF.h"
00038
00039
00040 int main()
00041 {
00042
00043 string host = "localhost";
00044 string dbname = "DB320RC1";
00045 string user = "root";
00046 string password = "vinhas";
00047
00048
00049 TeDatabase* db = new TeMySQL();
00050 if (!db->connect(host, user, password, dbname))
00051 {
00052 cout << "Error: " << db->errorMessage() << endl;
00053 cout << endl << "Press Enter\n";
00054 getchar();
00055 return 1;
00056 }
00057 cout << "Connection successful to the database \"" << dbname << "\" on MySQL server \"" << host << "\" !\n";;
00058
00059
00060 string layerName = "EstadosBrasil";
00061 if (!db->layerExist(layerName))
00062 {
00063
00064 TeDatum sad69 = TeDatumFactory::make("SAD69");
00065 TePolyconic* proj = new TePolyconic(sad69, -54);
00066
00067 TeLayer* layer = new TeLayer(layerName, db, proj);
00068 string filename = "../data/EstadosBrasil.shp";
00069 string tablename = "EstadosBrasil";
00070
00071 if (TeImportShape(layer, filename, tablename))
00072 cout << "The shapefile \"EstadosBrasil.shp\" was imported successfully into the TerraLib database!\n" << endl;
00073 else
00074 cout << "Error: Fail to import the shapefile \"EstadosBrasil.shp\"!\n" << endl;
00075
00076 }
00077
00078
00079 TeLayer* estados = new TeLayer("EstadosBrasil");
00080 if (!db->loadLayer(estados))
00081 {
00082 cout << "Fail to load the layer \"EstadosBrasil\": " << db->errorMessage() << endl;
00083 db->close();
00084 cout << endl << "Press Enter\n";
00085 getchar();
00086 return 1;
00087 }
00088
00089
00090 TeSTElementSet steSet (estados);
00091
00092
00093
00094 vector<string> attrs;
00095 attrs.push_back("EstadosBrasil.NOME_UF");
00096 attrs.push_back("EstadosBrasil.CAPITAL");
00097
00098
00099
00100 bool loadGeometries = false;
00101 bool loadAllAttributes = false;
00102 if(!TeSTOSetBuildDB(&steSet, loadGeometries, loadAllAttributes, attrs))
00103 {
00104 cout << "Error! " << endl;
00105 cout << endl << "Press Enter\n";
00106 getchar();
00107 return 1;
00108 }
00109
00110
00111 cout << "Number of elements: " << steSet.numElements() << endl;
00112
00113
00114 TeSTElementSet::iterator it = steSet.begin();
00115 while ( it != steSet.end())
00116 {
00117 TeSTInstance st = (*it);
00118
00119 string desc;
00120
00121 TePropertyVector vectp = st.getPropertyVector();
00122
00123 cout << "Id: " << st.objectId() << " ---------------- " << endl;
00124 for (unsigned int i=0; i<vectp.size(); i++)
00125 {
00126 cout << vectp[i].attr_.rep_.name_ << " = ";
00127 cout << vectp[i].value_ << endl;
00128 }
00129 cout << endl;
00130 ++it;
00131 }
00132
00133 db->close();
00134 cout << endl << "Press Enter\n";
00135 getchar();
00136 return 0;
00137 }