~ubuntu-branches/ubuntu/hardy/libterralib/hardy

« back to all changes in this revision

Viewing changes to examples/importShape/importShape.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2005-11-25 22:32:59 UTC
  • Revision ID: james.westby@ubuntu.com-20051125223259-3zubal8ux4ki4fjg
Tags: upstream-3.0.3b2
Import upstream version 3.0.3b2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************************************************
 
2
TerraLib - a library for developing GIS applications.
 
3
Copyright � 2001-2004 INPE and Tecgraf/PUC-Rio.
 
4
 
 
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.
 
10
 
 
11
You should have received a copy of the GNU Lesser General Public
 
12
License along with this library.
 
13
 
 
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
*************************************************************************************/
 
23
/* 
 
24
        This file shows an example of importing a shapefile that will create
 
25
        an attribute and a geometry table in a TerraLib database.
 
26
 
 
27
        Author: Lubia Vinhas  
 
28
*/
 
29
 
 
30
#include <TeImportExport.h>
 
31
#include <TeMySQL.h>
 
32
 
 
33
using namespace std;
 
34
#include <string>
 
35
 
 
36
int main()
 
37
{
 
38
        // Open a connection to the "TerraTeste" TerraLib database
 
39
        // Datatabase server parameters
 
40
        string host = "localhost";
 
41
        string dbname = "TerraTeste";
 
42
        string user = "root";
 
43
        string password = "";
 
44
 
 
45
        TeMySQL* db = new TeMySQL();
 
46
        if (!db->connect(host, user, password, dbname))
 
47
        {
 
48
                cout << "Error: " << db->errorMessage() << endl;
 
49
                cout << "Press Enter\n";
 
50
                getchar();
 
51
                return 1;
 
52
        }
 
53
 
 
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);
 
57
 
 
58
        string layerName = "Brasil";
 
59
 
 
60
        // Check whether there is a layer with this name in the database
 
61
        if (db->layerExist(layerName))
 
62
        {
 
63
                cout << "The database already has an infolayer with the name \"";
 
64
                cout << layerName << "\" !" << endl << endl;
 
65
                db->close();
 
66
                cout << "Press Enter\n";
 
67
                getchar();
 
68
                return 1;
 
69
        }
 
70
 
 
71
        // Create a new layer in the database
 
72
        TeLayer* layer = new TeLayer(layerName, db, proj);
 
73
 
 
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                 
 
77
 
 
78
        if (TeImportShape(layer, filename, tablename, linkcolumn))
 
79
                cout << "The shapefile was imported successfully into the TerraLib database!\n" << endl;
 
80
        else
 
81
                cout << "Error: Fail to import the shapefile!\n" << endl;
 
82
                
 
83
        cout.flush();
 
84
        db->close();
 
85
        cout << "Press Enter\n";
 
86
        getchar();
 
87
        return 0;
 
88
}
 
89
 
 
90