OTB  6.7.0
Orfeo Toolbox
otbGeometriesToGeometriesFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 { namespace internal {
42 struct ProcessVisitor;
43 } } // otb::internal namespace
44 
45 namespace otb
46 {
54 class OTBGdalAdapters_EXPORT GeometriesToGeometriesFilter : public GeometriesSource
55  {
56 public:
57 
65 
70  // typedef GeometriesSet::Pointer InputGeometriesPointer;
71  // typedef GeometriesSet::Pointer OutputGeometriesPointer;
73 
76 
80 
83  using Superclass::SetInput;
84  virtual void SetInput(const InputGeometriesType *input);
85  const InputGeometriesType * GetInput(void);
87 
88 
89 protected:
94 
98  ~GeometriesToGeometriesFilter() override;
99 
104  void GenerateData(void) override;
105 
106 private:
111  void Process(OutputGeometriesType &inout);
112 
119  void Process(InputGeometriesType const& source, OutputGeometriesType &destination);
120 
126 
135  virtual void DoProcessLayer(ogr::Layer const& source, ogr::Layer & destination) const=0;
136 
146  virtual OGRSpatialReference* DoDefineNewLayerSpatialReference(ogr::Layer const& source) const;
147 
153  virtual OGRwkbGeometryType DoDefineNewLayerGeometryType(ogr::Layer const& source) const;
154 
161  virtual std::vector<std::string> DoDefineNewLayerOptions(ogr::Layer const& source) const;
162 
168  virtual void DoDefineNewLayerFields(ogr::Layer const& source, ogr::Layer & dest) const = 0;
169 
177  virtual void DoFinalizeInitialization() {}
179 
180  friend struct otb::internal::ProcessVisitor;
181  };
182 
187 struct OTBGdalAdapters_EXPORT FieldCopyTransformation
188  {
189  OGRFeatureDefn & getDefinition(ogr::Layer & outLayer) const
190  {
191  return outLayer.GetLayerDefn();
192  }
193 
198  void fieldsTransform(ogr::Feature const& itkNotUsed(inoutFeature)) const
199  {
200  // default => do nothing for in-place transformation
201  }
202 
210  void fieldsTransform(ogr::Feature const& inFeature, ogr::Feature & outFeature) const;
211 
219  void DefineFields(ogr::Layer const& source, ogr::Layer & dest) const;
220 private:
221 
232  mutable std::map<int,int> m_SourceToDestFieldIndicesMap;
233  };
235 
236 
263 template <class TransformationFunctor, class TransformedElementType, class FieldTransformationPolicy = FieldCopyTransformation>
265  {
266  };
268 
280 template <class TransformationFunctor, class FieldTransformationPolicy>
281 struct TransformationFunctorDispatcher<TransformationFunctor, ogr::Layer, FieldTransformationPolicy>
282 : FieldTransformationPolicy
283  {
284  typedef typename TransformationFunctor::TransformedElementType TransformedElementType;
285  BOOST_MPL_ASSERT((boost::is_same<ogr::Layer, TransformedElementType>));
287  TransformationFunctorDispatcher(TransformationFunctor functor) : m_functor(functor){ }
288  void operator()(ogr::Layer const& in, ogr::Layer & out) const;
289  void operator()(ogr::Layer & inout) const;
290  TransformationFunctor * operator->() { return &m_functor; }
291 private:
292  TransformationFunctor m_functor;
293  };
295 
314 template <class TransformationFunctor, class FieldTransformationPolicy>
315 struct TransformationFunctorDispatcher<TransformationFunctor, OGRGeometry, FieldTransformationPolicy>
316 : FieldTransformationPolicy
317  {
318  typedef typename TransformationFunctor::TransformedElementType TransformedElementType;
319  BOOST_MPL_ASSERT((boost::is_same<OGRGeometry, TransformedElementType>));
321  TransformationFunctorDispatcher(TransformationFunctor functor) : m_functor(functor){}
323 
324  void operator()(ogr::Layer const& in, ogr::Layer & out) const;
325  void operator()(ogr::Layer & inout) const;
326  TransformationFunctor * operator->() { return &m_functor; }
327 private:
328  TransformationFunctor m_functor;
329  };
330 
331 
346 template <class TransformationFunctor, class FieldTransformationPolicy = FieldCopyTransformation>
349 , public TransformationFunctorDispatcher<TransformationFunctor, typename TransformationFunctor::TransformedElementType, FieldTransformationPolicy>
350 {
351 public:
352 
360 
363  typedef TransformationFunctor TransformationFunctorType;
364  typedef typename TransformationFunctor::TransformedElementType TransformedElementType;
368 
371 
373  itkNewMacro(Self);
374 
378 
379 protected:
382 
385 
396  void DoProcessLayer(ogr::Layer const& source, ogr::Layer & destination) const override;
397 
406  void DoDefineNewLayerFields(ogr::Layer const& source, ogr::Layer & dest) const override
407  {
408  this->DefineFields(source, dest);
409  }
410 };
412 
413 } // end namespace otb
414 
415 #ifndef OTB_MANUAL_INSTANTIATION
417 #endif
418 
419 #endif // otbGeometriesToGeometriesFilter_h
OGRFeatureDefn & GetLayerDefn() const
Layer of geometric objets.
void fieldsTransform(ogr::Feature const &) const
TransformationFunctor::TransformedElementType TransformedElementType
TransformationFunctorDispatcher< TransformationFunctorType, TransformedElementType, FieldTransformationPolicy > TransformationFunctorDispatcherType
Common ITK type to manipulate any set of geometries: a otb::ogr::DataSource, or a otb::ogr::Layer...
Geometric objet with descriptive fields.
void DoDefineNewLayerFields(ogr::Layer const &source, ogr::Layer &dest) const override
itk::SmartPointer< const Self > ConstPointer
OGRFeatureDefn & getDefinition(ogr::Layer &outLayer) const