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
*************************************************************************************/
24
This file shows an example of importing a shapefile that will create
25
an attribute and a geometry table in a TerraLib database.
30
#include <TeImportExport.h>
38
// Open a connection to the "TerraTeste" TerraLib database
39
// Datatabase server parameters
40
string host = "localhost";
41
string dbname = "TerraTeste";
45
TeMySQL* db = new TeMySQL();
46
if (!db->connect(host, user, password, dbname))
48
cout << "Error: " << db->errorMessage() << endl;
49
cout << "Press Enter\n";
54
// Define a projection. It cannot be decoded from a shapefile
55
TeDatum sad69 = TeDatumFactory::make("SAD69");
56
TePolyconic* proj = new TePolyconic(sad69, -54.0*TeCDR);
58
string layerName = "Brasil";
60
// Check whether there is a layer with this name in the database
61
if (db->layerExist(layerName))
63
cout << "The database already has an infolayer with the name \"";
64
cout << layerName << "\" !" << endl << endl;
66
cout << "Press Enter\n";
71
// Create a new layer in the database
72
TeLayer* layer = new TeLayer(layerName, db, proj);
74
string filename = "../data/EstadosBrasil.shp"; // Shapefile path
75
string tablename = "BrasilIBGE"; // Name of the attribute table
76
string linkcolumn = "SPRROTULO"; // Column that will link the attributes and geometry tables
78
if (TeImportShape(layer, filename, tablename, linkcolumn))
79
cout << "The shapefile was imported successfully into the TerraLib database!\n" << endl;
81
cout << "Error: Fail to import the shapefile!\n" << endl;
85
cout << "Press Enter\n";