OTB  9.0.0
Orfeo Toolbox
otbOGRFeatureWrapper.h
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_h
22 #define otbOGRFeatureWrapper_h
23 
24 #include <memory>
25 
26 // #include "itkIndent.h", included from field
27 #include "otbOGRFieldWrapper.h"
28 #include "otbOGRGeometryWrapper.h"
29 
30 class OGRFeature;
31 class OGRFeatureDefn;
32 
33 namespace otb
34 {
35 namespace ogr
36 {
37 class Feature;
38 
39 OTBGdalAdapters_EXPORT bool operator==(Feature const& lhs, Feature const& rhs);
40 
63 class OTBGdalAdapters_EXPORT Feature
64 {
65 public:
66 
69 
82  Feature(OGRFeatureDefn& definition);
83 
95  Feature(OGRFeature* feature);
96 
103  ~Feature();
104 
115  Feature Clone() const;
116 
127  void SetFrom(Feature const& rhs, int* map, bool mustForgive = true);
128 
131  void SetFrom(Feature const& rhs, bool mustForgive = true);
133 
134 
136  void PrintSelf(std::ostream& os, itk::Indent indent) const;
137 
146  OGRFeature& ogr() const;
147 
149  OGRFeature& ogr();
150 
158  std::shared_ptr<OGRFeature>& sptr()
159  {
160  return m_Feature;
161  }
162 
164  std::shared_ptr<OGRFeature> const& sptr() const
165  {
166  return m_Feature;
167  }
168 
176  long GetFID() const;
177 
185  void SetFID(long fid);
186 
194  OGRFeatureDefn& GetDefn() const;
195 
205 
211  int GetSize() const;
212 
219  Field operator[](int index);
220 
227  Field const operator[](int index) const;
228 
234  Field operator[](std::string const& name);
235 
241  Field const operator[](std::string const& name) const;
242 
249  FieldDefn GetFieldDefn(int index) const;
250 
256  FieldDefn GetFieldDefn(std::string const& name) const;
257 
262  int GetFieldIndex(std::string const& name) const;
264 
273 
283  void SetGeometry(OGRGeometry const* geometry);
284 
294  OGRGeometry const* GetGeometry() const;
295 
310  void SetGeometryDirectly(UniqueGeometryPtr geometry);
311 
325  UniqueGeometryPtr StealGeometry();
327 
337  friend bool otb::ogr::operator==(Feature const& lhs, Feature const& rhs);
338  OGRFeature const* addr() const
339  {
340  return m_Feature.get();
341  }
343 
344 private:
353  Feature UncheckedClone() const;
354  void UncheckedSetFrom(Feature const& rhs, int* map, bool mustForgive = true);
355  void UncheckedSetFrom(Feature const& rhs, bool mustForgive = true);
356  void UncheckedPrintSelf(std::ostream& os, itk::Indent indent) const;
357  Field UncheckedGetElement(int index);
358  Field UncheckedGetElement(std::string const& name);
359  FieldDefn UncheckedGetFieldDefn(int index) const;
360  FieldDefn UncheckedGetFieldDefn(std::string const& name) const;
361  int UncheckedGetFieldIndex(std::string const& name) const;
362  long UncheckedGetFID() const;
363  void UncheckedSetFID(long fid);
364  OGRFeatureDefn& UncheckedGetDefn() const;
365  void UncheckedSetGeometryDirectly(UniqueGeometryPtr geometry);
366  UniqueGeometryPtr UncheckedStealGeometry();
367  OGRGeometry const* UncheckedGetGeometry() const;
368  void UncheckedSetGeometry(OGRGeometry const* geometry);
370 
371 
381  void CheckInvariants() const;
382 
385  std::shared_ptr<OGRFeature> m_Feature;
386 };
387 
388 
389 } // ogr namespace
390 } // otb namespace
391 
392 
393 #ifndef OTB_MANUAL_INSTANTIATION
394 #include "otbOGRFeatureWrapper.hxx"
395 #endif
396 
397 #endif // otbOGRFeatureWrapper_h
otb::ogr::Feature::addr
OGRFeature const * addr() const
Definition: otbOGRFeatureWrapper.h:338
otb::ogr::FieldDefn
Encapsulation of OGRFieldDefn: field definition.
Definition: otbOGRFieldWrapper.h:60
otbOGRFieldWrapper.h
otb::ogr::Feature::m_Feature
std::shared_ptr< OGRFeature > m_Feature
Definition: otbOGRFeatureWrapper.h:385
otb::ogr::operator==
OTBGdalAdapters_EXPORT bool operator==(Feature const &lhs, Feature const &rhs)
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbOGRGeometryWrapper.h
otb::ogr::UniqueGeometryPtr
boost::interprocess::unique_ptr< OGRGeometry, internal::GeometryDeleter > UniqueGeometryPtr
Definition: otbOGRGeometryWrapper.h:109
otb::ogr::Field
Encapsulation of OGRField Instances of Field are expected to be built from an existing Feature with w...
Definition: otbOGRFieldWrapper.h:117
otbOGRFeatureWrapper.hxx
otb::ogr::Feature::sptr
std::shared_ptr< OGRFeature > const & sptr() const
Definition: otbOGRFeatureWrapper.h:164
otb::ogr::Feature::sptr
std::shared_ptr< OGRFeature > & sptr()
Definition: otbOGRFeatureWrapper.h:158
otb::ogr::Feature
Geometric object with descriptive fields.
Definition: otbOGRFeatureWrapper.h:63