OTB  6.7.0
Orfeo Toolbox
otbOGRFeatureWrapper.h
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_h
22 #define otbOGRFeatureWrapper_h
23 
24 // #include <iosfwd> // std::ostream&
25 #if defined(__GNUC__) || defined(__clang__)
26 #pragma GCC diagnostic push
27 #pragma GCC diagnostic ignored "-Wshadow"
28 #include <boost/shared_ptr.hpp>
29 #pragma GCC diagnostic pop
30 #else
31 #include <boost/shared_ptr.hpp>
32 #endif
33 // #include "itkIndent.h", included from field
34 #include "otbOGRFieldWrapper.h"
35 #include "otbOGRGeometryWrapper.h"
36 
37 class OGRFeature;
38 class OGRFeatureDefn;
39 
40 namespace otb {
41 namespace ogr {
42 class Feature;
43 
44 OTBGdalAdapters_EXPORT
45 bool operator==(Feature const& lhs, Feature const& rhs);
46 
69 class OTBGdalAdapters_EXPORT Feature
70  {
71 public:
72 
75 
88  Feature(OGRFeatureDefn & definition);
89 
101  Feature(OGRFeature * feature);
102 
109  ~Feature();
110 
121  Feature Clone() const;
122 
133  void SetFrom(Feature const& rhs, int *map, bool mustForgive = true);
134 
137  void SetFrom(Feature const& rhs, bool mustForgive = true);
139 
140 
142  void PrintSelf(std::ostream &os, itk::Indent indent) const;
143 
152  OGRFeature & ogr() const;
153 
155  OGRFeature & ogr();
156 
164  boost::shared_ptr<OGRFeature> & sptr() {return m_Feature; }
165 
167  boost::shared_ptr<OGRFeature> const& sptr() const {return m_Feature; }
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;
258 
267 
277  void SetGeometry(OGRGeometry const* geometry);
278 
288  OGRGeometry const* GetGeometry() const;
289 
304  void SetGeometryDirectly(UniqueGeometryPtr geometry);
305 
319  UniqueGeometryPtr StealGeometry();
321 
331  friend bool otb::ogr::operator==(Feature const& lhs, Feature const& rhs);
332  OGRFeature const* addr() const { return m_Feature.get(); }
333 private:
334 
343  Feature UncheckedClone() const;
344  void UncheckedSetFrom(Feature const& rhs, int *map, bool mustForgive = true);
345  void UncheckedSetFrom(Feature const& rhs, bool mustForgive = true);
346  void UncheckedPrintSelf(std::ostream &os, itk::Indent indent) const;
347  Field UncheckedGetElement(int index);
348  Field UncheckedGetElement(std::string const& name);
349  FieldDefn UncheckedGetFieldDefn(int index) const;
350  FieldDefn UncheckedGetFieldDefn(std::string const& name) const;
351  int UncheckedGetFieldIndex(std::string const& name) const;
352  long UncheckedGetFID() const;
353  void UncheckedSetFID(long fid);
354  OGRFeatureDefn& UncheckedGetDefn() const;
355  void UncheckedSetGeometryDirectly(UniqueGeometryPtr geometry);
356  UniqueGeometryPtr UncheckedStealGeometry();
357  OGRGeometry const* UncheckedGetGeometry() const;
358  void UncheckedSetGeometry(OGRGeometry const* geometry);
360 
361 
366  int GetFieldIndex(std::string const& name) const;
367 
377  void CheckInvariants() const;
378 
381  boost::shared_ptr<OGRFeature> m_Feature;
382  };
383 
384 
385 } // ogr namespace
386 } // otb namespace
387 
388 
389 #ifndef OTB_MANUAL_INSTANTIATION
390 #include "otbOGRFeatureWrapper.hxx"
391 #endif
392 
393 #endif // otbOGRFeatureWrapper_h
OGRFeature const * addr() const
boost::shared_ptr< OGRFeature > & sptr()
boost::shared_ptr< OGRFeature > m_Feature
OTBGdalAdapters_EXPORT bool operator==(Feature const &lhs, Feature const &rhs)
boost::interprocess::unique_ptr< OGRGeometry, internal::GeometryDeleter > UniqueGeometryPtr
Geometric objet with descriptive fields.
Encapsulation of OGRField Instances of Field are expected to be built from an existing Feature with w...
Encapsulation of OGRFieldDefn: field definition.
boost::shared_ptr< OGRFeature > const & sptr() const