OTB  6.7.0
Orfeo Toolbox
otbGeometriesToGeometriesFilter.hxx
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_hxx
22 #define otbGeometriesToGeometriesFilter_hxx
23 
24 /*===========================================================================*/
25 /*===============================[ Includes ]================================*/
26 /*===========================================================================*/
28 
29 /*===========================================================================*/
30 /*==================[ DefaultGeometriesToGeometriesFilter ]==================*/
31 /*===========================================================================*/
32 template <class TransformationFunctor, class FieldTransformationPolicy>
33 inline
35 {}
36 
37 template <class TransformationFunctor, class FieldTransformationPolicy>
38 inline
39 /*virtual*/
41 {}
42 
43 template <class TransformationFunctor, class FieldTransformationPolicy>
44 inline
45 /*virtual*/
47  otb::ogr::Layer const& source, otb::ogr::Layer & destination) const
48 {
49  if (source != destination)
50  {
51  (*this)(source, destination); // if TransformedElementType == layer
52  // m_TransformationFunctor(source, destination); // if TransformedElementType == layer
53  }
54  else
55  {
56  // m_TransformationFunctor(destination); // if TransformedElementType == layer
57  (*this)(destination); // if TransformedElementType == layer
58  }
59 }
60 
61 /*===========================================================================*/
62 /*================[ TransformationFunctorDispatcher<layer> ]=================*/
63 /*===========================================================================*/
64 
65 template <class TransformationFunctor, class FieldTransformationPolicy>
66 inline
68  otb::ogr::Layer const& in, otb::ogr::Layer & out) const
69 {
70  m_functor(in, out);
71 }
72 
73 template <class TransformationFunctor, class FieldTransformationPolicy>
74 inline
76  otb::ogr::Layer & inout) const
77 
78 {
79  m_functor(inout);
80 }
81 
82 /*===========================================================================*/
83 /*=============[ TransformationFunctorDispatcher<OGRGeometry> ]==============*/
84 /*===========================================================================*/
85 template <class TransformationFunctor, class FieldTransformationPolicy>
86 inline
88  otb::ogr::Layer const& in, otb::ogr::Layer & out) const
89 {
90  OGRFeatureDefn & defn = out.GetLayerDefn();
91  for (ogr::Layer::const_iterator b = in.begin(), e = in.end(); b != e; ++b)
92  {
93  ogr::Feature const feat = *b;
94  ogr::UniqueGeometryPtr g = m_functor(feat.GetGeometry());
95  ogr::Feature dest(defn);
96  dest.SetGeometryDirectly(otb::move(g));
97  this->fieldsTransform(feat, dest);
98  out.CreateFeature(dest);
99  }
100 }
101 
102 template <class TransformationFunctor, class FieldTransformationPolicy>
103 inline
105  otb::ogr::Layer & inout) const
106 {
107 // OGRFeatureDefn & defn = inout.GetLayerDefn();
108  // NB: We can't iterate with begin()/end() as SetFeature may invalidate the
109  // iterators depending of the underlying drivers
110  // => we use start_at(), i.e. SetNextByIndex()
111  for (int i=0, N=inout.GetFeatureCount(true); i!=N; ++i)
112  {
113  ogr::Feature feat = *inout.start_at(i);
114  this->fieldsTransform(feat);
115  ogr::UniqueGeometryPtr g = m_functor(feat.GetGeometry());
116  feat.SetGeometryDirectly(otb::move(g));
117  inout.SetFeature(feat);
118  }
119 }
120 
121 #endif
OGRGeometry const * GetGeometry() const
OGRFeatureDefn & GetLayerDefn() const
Layer of geometric objets.
const_iterator start_at(GIntBig index) const
Implementation class for Feature iterator. This iterator is a single pass iterator. We may fetch the Feature referenced by an iterator previously stored, but never resume the iteration after a call to Layer::begin(), Layer::start_at(), Layer::CreateFeature(), Layer::DeleteFeature(), Layer::GetFeature(), Layer::SetFeature(), nor fork the iteration.
const_iterator begin() const
void CreateFeature(Feature feature)
int GetFeatureCount(bool doForceComputation) const
boost::interprocess::unique_ptr< OGRGeometry, internal::GeometryDeleter > UniqueGeometryPtr
void DoProcessLayer(ogr::Layer const &source, ogr::Layer &destination) const override
Geometric objet with descriptive fields.
void SetGeometryDirectly(UniqueGeometryPtr geometry)
void SetFeature(Feature feature)
const_iterator end() const