Orfeo Toolbox  3.16
otbPostGISCreateTableTransactor.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
19 #include <sstream>
20 #include <cassert>
21 
22 #include "otbMacro.h"
23 
24 namespace otb
25 {
26 
28 {
29  m_RemoveExistingTable = false;
30 }
31 
34 {
35  m_TableName = pgt.GetTableName();
36  m_SRID = pgt.GetSRID();
37  m_Dimension = pgt.GetDimension();
39 }
40 
42 throw()
43 {
44  m_TableName = pgt.GetTableName();
45  m_SRID = pgt.GetSRID();
46  m_Dimension = pgt.GetDimension();
47  m_RemoveExistingTable = pgt.GetRemoveExistingTable();
48  return *this;
49 }
50 
51 void PostGISCreateTableTransactor::operator ()(pqxx::nontransaction& T)
52 {
53 
55  {
56  std::stringstream dropCommand;
57 
58  //dropCommand << "DROP TABLE " << m_TableName;
59  dropCommand << "DROP TABLE IF EXISTS " << m_TableName << " CASCADE";
60 
61  otbGenericMsgDebugMacro(<< "Drop Command " << dropCommand.str());
62 
63  m_Result = T.exec(dropCommand.str());
64  }
65 
66  std::stringstream createCommand;
67 
68  createCommand << "CREATE TABLE " << m_TableName
69  << " (id serial PRIMARY KEY, genre TEXT);";
70 
71  otbGenericMsgDebugMacro(<< "Create Command " << createCommand.str());
72  m_Result = T.exec(createCommand.str());
73 
74  std::stringstream addGeometryCommand;
75 
76  addGeometryCommand << "SELECT AddGeometryColumn( '" << m_TableName <<
77  "', 'the_geom', " << m_SRID << ", 'GEOMETRY'," << m_Dimension << " );";
78 
79  m_Result = T.exec(addGeometryCommand.str());
80 
81 
83  //FIXME not working yet
84 // std::stringstream addGISTIndexCommand;
85 //
86 // addGISTIndexCommand << "CREATE INDEX idx_" << m_TableName << "_the_geom ON " << m_TableName <<
87 // " USING gist( the_geom );";
88 //
89 // otbGenericMsgDebugMacro(<< "Create Command " << addGISTIndexCommand.str());
90 //
91 // m_Result = T.exec(addGISTIndexCommand.str());
92 }
93 
95 {
96  otbMsgDevMacro( "\t Table is created \t" );
97  //T.exec
98 }
99 
101 {
102  return m_TableName;
103 }
104 
105 void PostGISCreateTableTransactor::SetTableName(const std::string& aName)
106 {
107  m_TableName = aName;
108 }
109 
111 {
112  return m_SRID;
113 }
114 
116 {
117  m_SRID = aSRID;
118 }
119 
121 {
122  return m_Dimension;
123 }
124 
126 {
127  m_Dimension = aDim;
128 }
129 
131 {
132  m_RemoveExistingTable = val;
133 }
134 
136 {
137  return m_RemoveExistingTable;
138 }
139 
141 {
142  return m_Result;
143 }
144 
146 {
147  /*
148  std::stringstream addGISTIndexCmd;
149 
150  addGISTIndexCmd << "CREATE INDEX idx_" << m_TableName << "_the_geom ON " << m_TableName << " USING gist( the_geom );";
151 
152  otbGenericMsgDebugMacro(<<"Create Command " << addGISTIndexCmd.str());
153  T.exec(addGISTIndexCmd.str());
154  */
155  assert(0);
156 }
157 
158 } // end namespace otb

Generated at Sun Feb 3 2013 00:42:26 for Orfeo Toolbox with doxygen 1.8.1.1