OTB  9.0.0
Orfeo Toolbox
otbGeometriesToGeometriesFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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_hxx
22 #define otbGeometriesToGeometriesFilter_hxx
23 
24 /*===========================================================================*/
25 /*===============================[ Includes ]================================*/
26 /*===========================================================================*/
28 
29 /*===========================================================================*/
30 /*==================[ DefaultGeometriesToGeometriesFilter ]==================*/
31 /*===========================================================================*/
32 template <class TransformationFunctor, class FieldTransformationPolicy>
34 {
35 }
36 
37 template <class TransformationFunctor, class FieldTransformationPolicy>
38 inline
39  /*virtual*/
41 {
42 }
43 
44 template <class TransformationFunctor, class FieldTransformationPolicy>
45 inline
46  /*virtual*/
47  void
49  otb::ogr::Layer& destination) const
50 {
51  if (source != destination)
52  {
53  (*this)(source, destination); // if TransformedElementType == layer
54  // m_TransformationFunctor(source, destination); // if TransformedElementType == layer
55  }
56  else
57  {
58  // m_TransformationFunctor(destination); // if TransformedElementType == layer
59  (*this)(destination); // if TransformedElementType == layer
60  }
61 }
62 
63 /*===========================================================================*/
64 /*================[ TransformationFunctorDispatcher<layer> ]=================*/
65 /*===========================================================================*/
66 
67 template <class TransformationFunctor, class FieldTransformationPolicy>
69  otb::ogr::Layer& out) const
70 {
71  m_functor(in, out);
72 }
73 
74 template <class TransformationFunctor, class FieldTransformationPolicy>
76 
77 {
78  m_functor(inout);
79 }
80 
81 /*===========================================================================*/
82 /*=============[ TransformationFunctorDispatcher<OGRGeometry> ]==============*/
83 /*===========================================================================*/
84 template <class TransformationFunctor, class FieldTransformationPolicy>
86  otb::ogr::Layer& out) const
87 {
88  OGRFeatureDefn& defn = out.GetLayerDefn();
89  for (ogr::Layer::const_iterator b = in.begin(), e = in.end(); b != e; ++b)
90  {
91  ogr::Feature const feat = *b;
92  ogr::Feature dest(defn);
93  dest.SetGeometryDirectly(m_functor(feat.GetGeometry()));
94  this->fieldsTransform(feat, dest);
95  out.CreateFeature(dest);
96  }
97 }
98 
99 template <class TransformationFunctor, class FieldTransformationPolicy>
101 {
102  // OGRFeatureDefn & defn = inout.GetLayerDefn();
103  // NB: We can't iterate with begin()/end() as SetFeature may invalidate the
104  // iterators depending of the underlying drivers
105  // => we use start_at(), i.e. SetNextByIndex()
106  for (int i = 0, N = inout.GetFeatureCount(true); i != N; ++i)
107  {
108  ogr::Feature feat = *inout.start_at(i);
109  this->fieldsTransform(feat);
110  feat.SetGeometryDirectly(m_functor(feat.GetGeometry()));
111  inout.SetFeature(feat);
112  }
113 }
114 
115 #endif
otb::ogr::Layer::SetFeature
void SetFeature(Feature feature)
otb::DefaultGeometriesToGeometriesFilter::DefaultGeometriesToGeometriesFilter
DefaultGeometriesToGeometriesFilter()
Definition: otbGeometriesToGeometriesFilter.hxx:33
otb::DefaultGeometriesToGeometriesFilter::DoProcessLayer
void DoProcessLayer(ogr::Layer const &source, ogr::Layer &destination) const override
Definition: otbGeometriesToGeometriesFilter.hxx:48
otb::ogr::Layer::start_at
const_iterator start_at(GIntBig index) const
Definition: otbOGRLayerWrapper.h:440
otb::ogr::Layer::CreateFeature
void CreateFeature(Feature feature)
otb::TransformationFunctorDispatcher
Definition: otbGeometriesToGeometriesFilter.h:270
otb::ogr::Layer::begin
const_iterator begin() const
Definition: otbOGRLayerWrapper.h:412
otb::ogr::Layer::end
const_iterator end() const
Definition: otbOGRLayerWrapper.h:418
otb::DefaultGeometriesToGeometriesFilter::~DefaultGeometriesToGeometriesFilter
~DefaultGeometriesToGeometriesFilter() override
Definition: otbGeometriesToGeometriesFilter.hxx:40
otb::ogr::Feature::GetGeometry
OGRGeometry const * GetGeometry() const
Definition: otbOGRFeatureWrapper.hxx:149
otb::ogr::Layer::feature_iter
Implementation class for Feature iterator. This iterator is a single pass iterator....
Definition: otbOGRLayerWrapper.h:348
otbGeometriesToGeometriesFilter.h
otb::ogr::Feature
Geometric object with descriptive fields.
Definition: otbOGRFeatureWrapper.h:63
otb::ogr::Layer::GetFeatureCount
int GetFeatureCount(bool doForceComputation) const
otb::ogr::Layer
Layer of geometric objects.
Definition: otbOGRLayerWrapper.h:80
otb::ogr::Feature::SetGeometryDirectly
void SetGeometryDirectly(UniqueGeometryPtr geometry)
Definition: otbOGRFeatureWrapper.hxx:124
otb::ogr::Layer::GetLayerDefn
OGRFeatureDefn & GetLayerDefn() const