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 #include "../../src/terralib/kernel/TeDatabase.h"
00033 #include "../../src/terralib/drivers/MySQL/TeMySQL.h"
00034 #include "../../src/terralib/kernel/TeDecoderMemoryMap.h"
00035 #include "../../src/terralib/kernel/TeImportRaster.h"
00036
00037 int main()
00038 {
00039
00040 static TeDecoderMemoryMapFactory theDecoderMemoryMapFactory("MEMMAP");
00041 TeDecoderFactory::instanceName2Dec()["raw"] = "MEMMAP";
00042 TeDecoderFactory::instanceName2Dec()["RAW"] = "MEMMAP";
00043
00044 TeRasterParams parRaw;
00045 parRaw.nBands(1);
00046 parRaw.setDataType(TeFLOAT);
00047 parRaw.fileName_ = "../data/elevation.raw";
00048 parRaw.mode_ = 'r';
00049 TeProjection* proj = new TeNoProjection();
00050 parRaw.projection(proj);
00051 parRaw.lowerLeftResolutionSize(183557.0,8246277.0,30,30,382,422,false);
00052
00053
00054 TeRaster elev(parRaw);
00055 if (!elev.init())
00056 {
00057 cout << "Cannot access input grid!" << endl << endl;
00058 cout << "Press Enter\n";
00059 getchar();
00060 return 1;
00061 }
00062
00063
00064 string host = "localhost";
00065 string dbname = "DB320RC1";
00066 string user = "root";
00067 string password = "vinhas";
00068 TeDatabase* db = new TeMySQL();
00069 if (!db->connect(host, user, password, dbname))
00070 {
00071 elev.clear();
00072 cout << "Error: " << db->errorMessage() << endl << endl;
00073 cout << "Press Enter\n";
00074 getchar();
00075 return 1;
00076 }
00077
00078 string layerName = "Elevation";
00079
00080
00081 if (db->layerExist(layerName))
00082 {
00083 cout << "The database already has an infolayer with the name \"";
00084 cout << layerName << "\"!" << endl << endl;
00085 db->close();
00086 delete db;
00087 cout << "Press Enter\n";
00088 getchar();
00089 return 1;
00090 }
00091
00092
00093 TeLayer* layer = new TeLayer(layerName, db, elev.projection());
00094 if (layer->id() <= 0)
00095 {
00096 elev.clear();
00097 db->close();
00098 delete db;
00099 cout << "The destination layer could not be created!\n" << db->errorMessage() << endl << endl;
00100 cout << "Press Enter\n";
00101 getchar();
00102 return 1;
00103 }
00104
00105
00106 if (!TeImportRaster(layer, &elev, parRaw.ncols_, 2))
00107 {
00108 elev.clear();
00109 db->close();
00110 delete db;
00111 cout << "Fail to import grid!\n" << endl;
00112 cout << "Press Enter\n";
00113 getchar();
00114 return 1;
00115 }
00116
00117
00118 db->close();
00119 delete db;
00120 cout << "The GRID data was imported successfully into the TerraLib database!\n\n";
00121 cout << "Press Enter\n";
00122 getchar();
00123 return 0;
00124 }
00125