OTB  10.0.0
Orfeo Toolbox
otbGeometriesToGeometriesFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbGeometriesToGeometriesFilter_h
22 #define otbGeometriesToGeometriesFilter_h
23 
32 #include "otbGeometriesSource.h"
33 #include <map>
34 #include <boost/mpl/assert.hpp>
35 #include <boost/type_traits/is_same.hpp>
36 #include "otbOGRLayerWrapper.h"
37 
38 #include "otbMacro.h"
39 
40 // forward declarations
41 namespace otb
42 {
43 namespace internal
44 {
45 struct ProcessVisitor;
46 }
47 } // otb::internal namespace
48 
49 namespace otb
50 {
58 class OTBGdalAdapters_EXPORT GeometriesToGeometriesFilter : public GeometriesSource
59 {
60 public:
61 
65  typedef itk::ProcessObject Superclass;
66  typedef itk::SmartPointer<Self> Pointer;
67  typedef itk::SmartPointer<const Self> ConstPointer;
69 
74  // typedef GeometriesSet::Pointer InputGeometriesPointer;
75  // typedef GeometriesSet::Pointer OutputGeometriesPointer;
77 
80 
84 
87  using Superclass::SetInput;
88  virtual void SetInput(const InputGeometriesType* input);
91 
92 
93 protected:
98 
103 
108  void GenerateData(void) override;
109 
110 private:
116 
123  void Process(InputGeometriesType const& source, OutputGeometriesType& destination);
124 
130 
139  virtual void DoProcessLayer(ogr::Layer const& source, ogr::Layer& destination) const = 0;
140 
150  virtual OGRSpatialReference* DoDefineNewLayerSpatialReference(ogr::Layer const& source) const;
151 
157  virtual OGRwkbGeometryType DoDefineNewLayerGeometryType(ogr::Layer const& source) const;
158 
165  virtual std::vector<std::string> DoDefineNewLayerOptions(ogr::Layer const& source) const;
166 
172  virtual void DoDefineNewLayerFields(ogr::Layer const& source, ogr::Layer& dest) const = 0;
173 
182  {
183  }
185 
186  friend struct otb::internal::ProcessVisitor;
187 };
188 
193 struct OTBGdalAdapters_EXPORT FieldCopyTransformation
194 {
195  OGRFeatureDefn& getDefinition(ogr::Layer& outLayer) const
196  {
197  return outLayer.GetLayerDefn();
198  }
199 
204  void fieldsTransform(ogr::Feature const& itkNotUsed(inoutFeature)) const
205  {
206  // default => do nothing for in-place transformation
207  }
208 
216  void fieldsTransform(ogr::Feature const& inFeature, ogr::Feature& outFeature) const;
217 
225  void DefineFields(ogr::Layer const& source, ogr::Layer& dest) const;
226 
227 private:
238  mutable std::map<int, int> m_SourceToDestFieldIndicesMap;
239 };
241 
242 
269 template <class TransformationFunctor, class TransformedElementType, class FieldTransformationPolicy = FieldCopyTransformation>
271 {
272 };
274 
286 template <class TransformationFunctor, class FieldTransformationPolicy>
287 struct TransformationFunctorDispatcher<TransformationFunctor, ogr::Layer, FieldTransformationPolicy> : FieldTransformationPolicy
288 {
289  typedef typename TransformationFunctor::TransformedElementType TransformedElementType;
290  BOOST_MPL_ASSERT((boost::is_same<ogr::Layer, TransformedElementType>));
292  {
293  }
294  TransformationFunctorDispatcher(TransformationFunctor functor) : m_functor(functor)
295  {
296  }
297  void operator()(ogr::Layer const& in, ogr::Layer& out) const;
298  void operator()(ogr::Layer& inout) const;
299  TransformationFunctor* operator->()
300  {
301  return &m_functor;
302  }
304 
305 private:
306  TransformationFunctor m_functor;
307 };
308 
327 template <class TransformationFunctor, class FieldTransformationPolicy>
328 struct TransformationFunctorDispatcher<TransformationFunctor, OGRGeometry, FieldTransformationPolicy> : FieldTransformationPolicy
329 {
330  typedef typename TransformationFunctor::TransformedElementType TransformedElementType;
331  BOOST_MPL_ASSERT((boost::is_same<OGRGeometry, TransformedElementType>));
333  {
334  }
335  TransformationFunctorDispatcher(TransformationFunctor functor) : m_functor(functor)
336  {
337  }
339 
340  void operator()(ogr::Layer const& in, ogr::Layer& out) const;
341  void operator()(ogr::Layer& inout) const;
342  TransformationFunctor* operator->()
343  {
344  return &m_functor;
345  }
346 
347 private:
348  TransformationFunctor m_functor;
349 };
350 
351 
366 template <class TransformationFunctor, class FieldTransformationPolicy = FieldCopyTransformation>
369  public TransformationFunctorDispatcher<TransformationFunctor, typename TransformationFunctor::TransformedElementType, FieldTransformationPolicy>
370 {
371 public:
372 
377  typedef itk::SmartPointer<Self> Pointer;
378  typedef itk::SmartPointer<const Self> ConstPointer;
380 
383  typedef TransformationFunctor TransformationFunctorType;
384  typedef typename TransformationFunctor::TransformedElementType TransformedElementType;
387 
390 
392  itkNewMacro(Self);
393 
397 
398 protected:
401 
404 
415  void DoProcessLayer(ogr::Layer const& source, ogr::Layer& destination) const override;
416 
425  void DoDefineNewLayerFields(ogr::Layer const& source, ogr::Layer& dest) const override
426  {
427  this->DefineFields(source, dest);
428  }
429 };
431 
432 } // end namespace otb
433 
434 #ifndef OTB_MANUAL_INSTANTIATION
436 #endif
437 
438 #endif // otbGeometriesToGeometriesFilter_h
TransformationFunctorDispatcher< TransformationFunctorType, TransformedElementType, FieldTransformationPolicy > TransformationFunctorDispatcherType
TransformationFunctor::TransformedElementType TransformedElementType
void DoDefineNewLayerFields(ogr::Layer const &source, ogr::Layer &dest) const override
Common ITK type to manipulate any set of geometries: a otb::ogr::DataSource, or a otb::ogr::Layer.
void Process(InputGeometriesType const &source, OutputGeometriesType &destination)
virtual void DoProcessLayer(ogr::Layer const &source, ogr::Layer &destination) const =0
const InputGeometriesType * GetInput(void)
itk::SmartPointer< const Self > ConstPointer
virtual void SetInput(const InputGeometriesType *input)
virtual OGRSpatialReference * DoDefineNewLayerSpatialReference(ogr::Layer const &source) const
virtual void DoDefineNewLayerFields(ogr::Layer const &source, ogr::Layer &dest) const =0
void GenerateData(void) override
virtual OGRwkbGeometryType DoDefineNewLayerGeometryType(ogr::Layer const &source) const
virtual std::vector< std::string > DoDefineNewLayerOptions(ogr::Layer const &source) const
void Process(OutputGeometriesType &inout)
Geometric object with descriptive fields.
Layer of geometric objects.
OGRFeatureDefn & GetLayerDefn() const
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
void DefineFields(ogr::Layer const &source, ogr::Layer &dest) const
void fieldsTransform(ogr::Feature const &inFeature, ogr::Feature &outFeature) const
OGRFeatureDefn & getDefinition(ogr::Layer &outLayer) const
void fieldsTransform(ogr::Feature const &) const