otbGeometriesToGeometriesFilter.hxx 4.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
20

21 22
#ifndef otbGeometriesToGeometriesFilter_hxx
#define otbGeometriesToGeometriesFilter_hxx
23 24 25 26

/*===========================================================================*/
/*===============================[ Includes ]================================*/
/*===========================================================================*/
Guillaume Pasero's avatar
Guillaume Pasero committed
27
#include "otbGeometriesToGeometriesFilter.h"
28 29

/*===========================================================================*/
30
/*==================[ DefaultGeometriesToGeometriesFilter ]==================*/
31
/*===========================================================================*/
32
template <class TransformationFunctor, class FieldTransformationPolicy>
33
inline
34
otb::DefaultGeometriesToGeometriesFilter<TransformationFunctor, FieldTransformationPolicy>::DefaultGeometriesToGeometriesFilter()
35 36
{}

37
template <class TransformationFunctor, class FieldTransformationPolicy>
38 39
inline
/*virtual*/
40
otb::DefaultGeometriesToGeometriesFilter<TransformationFunctor, FieldTransformationPolicy>::~DefaultGeometriesToGeometriesFilter()
41
{}
42

43
template <class TransformationFunctor, class FieldTransformationPolicy>
44 45
inline
/*virtual*/
46
void otb::DefaultGeometriesToGeometriesFilter<TransformationFunctor, FieldTransformationPolicy>::DoProcessLayer(
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  otb::ogr::Layer const& source, otb::ogr::Layer & destination) const
{
  if (source != destination)
    {
    (*this)(source, destination); // if TransformedElementType == layer
    // m_TransformationFunctor(source, destination); // if TransformedElementType == layer
    }
  else
    {
    // m_TransformationFunctor(destination); // if TransformedElementType == layer
    (*this)(destination); // if TransformedElementType == layer
    }
}

/*===========================================================================*/
/*================[ TransformationFunctorDispatcher<layer> ]=================*/
/*===========================================================================*/

65
template <class TransformationFunctor, class FieldTransformationPolicy>
66
inline
67
void otb::TransformationFunctorDispatcher<TransformationFunctor,otb::ogr::Layer,FieldTransformationPolicy>::operator()(
68 69 70 71 72
  otb::ogr::Layer const& in, otb::ogr::Layer & out) const
{
  m_functor(in, out);
}

73
template <class TransformationFunctor, class FieldTransformationPolicy>
74
inline
75
void otb::TransformationFunctorDispatcher<TransformationFunctor,otb::ogr::Layer,FieldTransformationPolicy>::operator()(
76 77 78 79 80 81 82 83 84
  otb::ogr::Layer & inout) const

{
  m_functor(inout);
}

/*===========================================================================*/
/*=============[ TransformationFunctorDispatcher<OGRGeometry> ]==============*/
/*===========================================================================*/
85
template <class TransformationFunctor, class FieldTransformationPolicy>
86
inline
87
void otb::TransformationFunctorDispatcher<TransformationFunctor,OGRGeometry,FieldTransformationPolicy>::operator()(
88 89 90 91 92 93 94 95
  otb::ogr::Layer const& in, otb::ogr::Layer & out) const
{
  OGRFeatureDefn & defn = out.GetLayerDefn();
  for (ogr::Layer::const_iterator b = in.begin(), e = in.end(); b != e; ++b)
    {
    ogr::Feature const feat = *b;
    ogr::UniqueGeometryPtr g = m_functor(feat.GetGeometry());
    ogr::Feature dest(defn);
96
    dest.SetGeometryDirectly(otb::move(g));
97
    this->fieldsTransform(feat, dest);
98 99 100 101
    out.CreateFeature(dest);
    }
}

102
template <class TransformationFunctor, class FieldTransformationPolicy>
103
inline
104
void otb::TransformationFunctorDispatcher<TransformationFunctor,OGRGeometry,FieldTransformationPolicy>::operator()(
105 106
  otb::ogr::Layer & inout) const
{
107
//  OGRFeatureDefn & defn = inout.GetLayerDefn();
108 109 110 111 112 113
  // NB: We can't iterate with begin()/end() as SetFeature may invalidate the
  // iterators depending of the underlying drivers
  // => we use start_at(), i.e. SetNextByIndex()
  for (int i=0, N=inout.GetFeatureCount(true); i!=N; ++i)
    {
    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 118 119
    inout.SetFeature(feat);
    }
}
Guillaume Pasero's avatar
Guillaume Pasero committed
120 121

#endif