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