OTB  6.7.0
Orfeo Toolbox
otbOGRFeatureWrapper.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 otbOGRFeatureWrapper_hxx
22 #define otbOGRFeatureWrapper_hxx
23 
24 /*===========================================================================*/
25 /*===============================[ Includes ]================================*/
26 /*===========================================================================*/
27 #include "otbOGRFeatureWrapper.h"
28 #include <cassert>
29 #include <boost/version.hpp>
30 #if BOOST_VERSION >= 104800
31 # include <boost/move/move.hpp> // since 1.48
32 #else
33 # include <boost/interprocess/detail/move.hpp>
34 #endif
35 
36 namespace otb
37 {
38 #if BOOST_VERSION >= 104800
39 using boost::move;
40 #else
41 using boost::interprocess::move;
42 #endif
43 }
44 
45 /*===========================================================================*/
46 /*================================[ Feature ]================================*/
47 /*===========================================================================*/
48 inline
50 {
51  assert(m_Feature && "OGRFeature can't be null");
52 }
53 
54 inline
56 {
57  CheckInvariants();
58  return UncheckedClone();
59 }
60 
61 inline
62 void otb::ogr::Feature::SetFrom(Feature const& rhs, bool mustForgive)
63 {
64  CheckInvariants();
65  UncheckedSetFrom(rhs, mustForgive);
66 }
67 
68 inline
69 void otb::ogr::Feature::SetFrom(Feature const& rhs, int * map, bool mustForgive)
70 {
71  CheckInvariants();
72  UncheckedSetFrom(rhs, map, mustForgive);
73 }
74 
75 /*===========================================================================*/
76 /*================================[ Fields ]=================================*/
77 /*===========================================================================*/
78 inline
80 {
81  assert(index < GetSize() && "out of range field-index."); // also calls CheckInvariants();
82  return UncheckedGetElement(index);
83 }
84 
85 inline
87 {
88  return const_cast<Feature*>(this)->operator[](index);
89 }
90 
91 inline
93 {
94  CheckInvariants();
95  return UncheckedGetElement(name);
96 }
97 
98 inline
99 otb::ogr::Field const otb::ogr::Feature::operator[](std::string const& name) const
100 {
101  return const_cast<Feature*>(this)->operator[](name);
102 }
103 
104 inline
106 {
107  assert(index < GetSize() && "out of range field-index."); // also calls CheckInvariants();
108  return UncheckedGetFieldDefn(index);
109 }
110 
111 inline
113 {
114  CheckInvariants();
115  return UncheckedGetFieldDefn(name);
116 }
117 
118 inline
119 int otb::ogr::Feature::GetFieldIndex(std::string const& name) const
120 {
121  CheckInvariants();
122  return UncheckedGetFieldIndex(name);
123 }
124 
125 /*===========================================================================*/
126 /*==============================[ Properties ]===============================*/
127 /*===========================================================================*/
128 inline
130 {
131  CheckInvariants();
132  return UncheckedGetFID();
133 }
134 
135 inline
137 {
138  CheckInvariants();
139  UncheckedSetFID(fid);
140 }
141 
142 inline
143 OGRFeatureDefn& otb::ogr::Feature::GetDefn() const
144 {
145  CheckInvariants();
146  return UncheckedGetDefn();
147 }
148 
149 /*===========================================================================*/
150 /*==============================[ Geometries ]===============================*/
151 /*===========================================================================*/
152 inline
154 {
155  CheckInvariants();
156 #if !defined(NDEBUG)
157  OGRGeometry * g = geometry.get();
158 #endif
159  UncheckedSetGeometryDirectly(otb::move(geometry));
160  assert((m_Feature->GetGeometryRef() == g) && "The new geometry hasn't been set as expected");
161  assert(!geometry && "UniqueGeometryPtr hasn't released its pointer");
162 }
163 
164 inline
166 {
167  CheckInvariants();
168  UniqueGeometryPtr res = UncheckedStealGeometry();
169  itkAssertOrThrowMacro(!m_Feature->GetGeometryRef(), "Geometry hasn't been properly stolen");
170  return otb::move(res);
171 }
172 
173 inline
174 void otb::ogr::Feature::SetGeometry(OGRGeometry const* geometry)
175 {
176  CheckInvariants();
177  UncheckedSetGeometry(geometry);
178 }
179 
180 inline
181 OGRGeometry const* otb::ogr::Feature::GetGeometry() const
182 {
183  CheckInvariants();
184  return UncheckedGetGeometry();
185 }
186 
187 /*===========================================================================*/
188 /*=================================[ Misc ]==================================*/
189 /*===========================================================================*/
190 inline
191 OGRFeature & otb::ogr::Feature::ogr() const
192 { // not returning a OGRFeature const& because OGR is not const-correct
193  CheckInvariants();
194  return *m_Feature;
195 }
196 
197 inline
199 {
200  CheckInvariants();
201  return *m_Feature;
202 }
203 
204 inline
205 void otb::ogr::Feature::PrintSelf(std::ostream & os, itk::Indent indent) const
206 {
207  CheckInvariants();
208  UncheckedPrintSelf(os, indent);
209 }
210 
211 #endif // otbOGRFeatureWrapper_hxx
void CheckInvariants() const
OGRGeometry const * GetGeometry() const
UniqueGeometryPtr StealGeometry()
void SetGeometry(OGRGeometry const *geometry)
boost::shared_ptr< OGRFeature > m_Feature
OGRFeature & ogr() const
Feature Clone() const
void PrintSelf(std::ostream &os, itk::Indent indent) const
FieldDefn GetFieldDefn(int index) const
boost::interprocess::unique_ptr< OGRGeometry, internal::GeometryDeleter > UniqueGeometryPtr
OGRFeatureDefn & GetDefn() const
int GetFieldIndex(std::string const &name) const
void SetFrom(Feature const &rhs, int *map, bool mustForgive=true)
Field operator[](int index)
Geometric objet with descriptive fields.
Encapsulation of OGRField Instances of Field are expected to be built from an existing Feature with w...
void SetGeometryDirectly(UniqueGeometryPtr geometry)
Encapsulation of OGRFieldDefn: field definition.