1
/************************************************************************************
2
TerraLib - a library for developing GIS applications.
3
Copyright � 2001-2004 INPE and Tecgraf/PUC-Rio.
5
This code is part of the TerraLib library.
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
You should have received a copy of the GNU Lesser General Public
12
License along with this library.
14
The authors reassure the license terms regarding the warranties.
15
They specifically disclaim any warranties, including, but not limited to,
16
the implied warranties of merchantability and fitness for a particular purpose.
17
The library provided hereunder is on an "as is" basis, and the authors have no
18
obligation to provide maintenance, support, updates, enhancements, or modifications.
19
In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
20
indirect, special, incidental, or consequential damages arising out of the use
21
of this library and its documentation.
22
*************************************************************************************/
25
This file shows an example of how to import, to a TerraLib database, a raster data:
26
a binary raw grid data. Each point of the grid is a float value that represents the
27
elevation over an area
32
#include <TeDatabase.h>
34
#include <TeInitRasterDecoders.h>
35
#include <TeImportRaster.h>
39
// Initialize the raster decoder tool
40
TeInitRasterDecoders();
42
TeRasterParams parRaw;
44
parRaw.setDataType(TeFLOAT);
45
parRaw.fileName_ = "../data/elevation.raw";
47
TeProjection* proj = new TeNoProjection();
48
parRaw.projection(proj);
49
parRaw.lowerLeftResolutionSize(183557.0,8246277.0,30,30,382,422,false);
52
TeRaster elev(parRaw);
55
cout << "Cannot access input grid!" << endl << endl;
56
cout << "Press Enter\n";
61
// Datatabase server parameters
62
string host = "localhost";
63
string dbname = "TerraTeste";
66
TeDatabase* db = new TeMySQL();
67
if (!db->connect(host, user, password, dbname))
70
cout << "Error: " << db->errorMessage() << endl << endl;
71
cout << "Press Enter\n";
76
string layerName = "Elevation";
78
// Check whether there is a layer with this name in the database
79
if (db->layerExist(layerName))
81
cout << "The database already has an infolayer with the name \"";
82
cout << layerName << "\"!" << endl << endl;
84
cout << "Press Enter\n";
89
// Create a layer to receive the raster geometry (same projection as raster data)
90
TeLayer* layer = new TeLayer(layerName, db, elev.projection());
95
cout << "The destination layer could not be created!\n" << db->errorMessage() << endl << endl;
96
cout << "Press Enter\n";
101
// Import raster to the layer
102
if (!TeImportRaster(layer, &elev, parRaw.ncols_, 2))
106
cout << "Fail to import grid!\n" << endl;
107
cout << "Press Enter\n";
114
cout << "The GRID data was imported successfully into the TerraLib database!\n\n";
115
cout << "Press Enter\n";