Orfeo Toolbox  4.0
otbVectorDataToGISTableFilter.txx
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 =========================================================================*/
18 #ifndef __otbVectorDataToGISTableFilter_txx
19 #define __otbVectorDataToGISTableFilter_txx
20 
22 #include "itkProgressReporter.h"
23 
24 namespace otb {
25 
26 template<class TVectorData, class TGISTable>
29 {
30  m_InputGISConnection = InputGISConnectionType::New();
31  m_DropExistingGISTable = false;
32  m_GISTableName = "vectordata_to_gis";
33 }
34 
35 template<class TVectorData, class TGISTable>
36 void
39 {
40 // Process object is not const-correct so the const_cast is required here
42  const_cast<InputVectorDataType *>(input));
43 }
44 
45 template<class TVectorData, class TGISTable>
46 void
48 ::SetInput(unsigned int idx, const InputVectorDataType *input)
49 {
50  // Process object is not const-correct so the const_cast is required here
52  const_cast<InputVectorDataType *>(input));
53 }
54 
55 template<class TVectorData, class TGISTable>
59 {
60  if (this->GetNumberOfInputs() < 1)
61  {
62  return 0;
63  }
64 
65  return static_cast<const TVectorData *>
67 }
68 
69 template<class TVectorData, class TGISTable>
72 ::GetInput(unsigned int idx)
73 {
74  return static_cast<const TVectorData *>
75  (this->itk::ProcessObject::GetInput(idx));
76 }
77 
78 template<class TVectorData, class TGISTable>
79 void
82 { /*
83  // call the superclass' implementation of this method
84  Superclass::GenerateInputRequestedRegion();
85 
86  // We need all the input.
87  InputImagePointer input = const_cast<InputImageType *>(this->GetInput());
88  if ( !input )
89  { return; }
90  input->SetRequestedRegion( input->GetLargestPossibleRegion() ); */
91 }
92 
93 /*
94 template<class TInputImage, class TVectorData >
95 void
96 LabelMapToVectorDataFilter<TInputImage, TVectorData>
97 ::EnlargeOutputRequestedRegion(DataObject *)
98 {
99  this->GetOutput()
100  ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() );
101 }
102 */
103 
104 template<class TVectorData, class TGISTable>
105 void
108 {
109 
111  this->AllocateOutputs();
112 
113  OutputGISTableType * output = this->GetOutput();
114 
115  const InputVectorDataType * input = this->GetInput();
116 
118  output->SetConnection (this->GetInputGISConnection ());
119 
121  output->SetProjectionRef(input->GetProjectionRef());
122 
124  output->GetConnection()->ConnectToDB();
125 
127 // output->SetTableName ("vector_data_to_gis");
128 //output->SetTableName (this->GetGISTableName());
129  output->SetTableName ("");
131  //output->CreateTable(m_DropExistingGISTable);
132 
134  for (unsigned int idx = 0; idx < this->GetNumberOfInputs(); ++idx)
135  {
136  if (this->GetInput(idx))
137  {
138  InputVectorDataConstPointer input = this->GetInput(idx);
139  InternalTreeNodeType * inputRoot = const_cast<InternalTreeNodeType *>(input->GetDataTree()->GetRoot());
140 
141  //Old methods for processing translation to GIS table
142  //ProcessNode(inputRoot);
144  OGRVectorDataIOPointerType gisWriter = OGRVectorDataIOType::New();
145 
147  const std::string outputOGRConnStr = output->GetOGRStrConnection();
148 
150  if (gisWriter->CanWriteFile(outputOGRConnStr.data()))
151  {
152  //Write VectorData to the GIS Table using OGR translation
153  gisWriter->SetFileName(outputOGRConnStr);
154  otbGenericMsgDebugMacro(<< "Write vector data to GIS table " << outputOGRConnStr);
155 
156  //Write with overwrite =true option
157  std::string overStr("OVERWRITE=yes");
158  char *overOptions[] = { const_cast <char *> (overStr.c_str()) };
159 // std::cout << *overOptions << std::endl;
160  gisWriter->Write(input, overOptions);
161 
162  output->SetTableName (inputRoot->Get()->GetNodeId());
163  otbMsgDevMacro( "tablename " << output->GetTableName() );
164  }
165  else
166  {
167  itkGenericExceptionMacro(<< "Not valid connection string (PG:*) " << outputOGRConnStr);
168  }
169  }
170  }
171 
172 }
173 
174 template<class TVectorData, class TGISTable>
175 void
177 ::PrintSelf(std::ostream& os, itk::Indent indent) const
178 {
179  Superclass::PrintSelf(os, indent);
180 }
181 } // end namespace otb
182 #endif

Generated at Sat Mar 8 2014 16:24:33 for Orfeo Toolbox with doxygen 1.8.3.1