OTB  9.0.0
Orfeo Toolbox
List of all members
otb::ogr::Feature Class Reference

#include <otbOGRFeatureWrapper.h>

+ Collaboration diagram for otb::ogr::Feature:

Public Member Functions

Construction, copy and destruction
 Feature (OGRFeatureDefn &definition)
 
 Feature (OGRFeature *feature)
 
 ~Feature ()
 
Feature Clone () const
 
void SetFrom (Feature const &rhs, int *map, bool mustForgive=true)
 
void SetFrom (Feature const &rhs, bool mustForgive=true)
 
void PrintSelf (std::ostream &os, itk::Indent indent) const
 
OGRFeature & ogr () const
 
OGRFeature & ogr ()
 
std::shared_ptr< OGRFeature > & sptr ()
 
std::shared_ptr< OGRFeature > const & sptr () const
 
long GetFID () const
 
void SetFID (long fid)
 
OGRFeatureDefn & GetDefn () const
 
Fields

Fields access. Unlike original OGR API, the access to the fields of a feature is done directly from the Field interface, and not the Feature interface.

Ones first need to iterate on the fields of a feature, and then use the appropriate setter/getter to access to each field.

int GetSize () const
 
Field operator[] (int index)
 
const Field operator[] (int index) const
 
Field operator[] (std::string const &name)
 
const Field operator[] (std::string const &name) const
 
FieldDefn GetFieldDefn (int index) const
 
FieldDefn GetFieldDefn (std::string const &name) const
 
int GetFieldIndex (std::string const &name) const
 

Geometries

Todo:
We should detect whether the official C++11 std::unique_ptr<> is available instead of always using boost.interprocess.unique_ptr<>.
void SetGeometry (OGRGeometry const *geometry)
 
OGRGeometry const * GetGeometry () const
 
void SetGeometryDirectly (UniqueGeometryPtr geometry)
 
UniqueGeometryPtr StealGeometry ()
 
OGRFeature const * addr () const
 
bool otb::ogr::operator== (Feature const &lhs, Feature const &rhs)
 

Unchecked definitions

All the definitions that follow do the real work. However, they are not the exposed public functions. The design of this class follows the principle behind the NVI (Non-Virtual Interface) pattern:

  • The public functions are inlined and check invariants and preconditions,
  • While the private functions do the work.
std::shared_ptr< OGRFeature > m_Feature
 
Feature UncheckedClone () const
 
void UncheckedSetFrom (Feature const &rhs, int *map, bool mustForgive=true)
 
void UncheckedSetFrom (Feature const &rhs, bool mustForgive=true)
 
void UncheckedPrintSelf (std::ostream &os, itk::Indent indent) const
 
Field UncheckedGetElement (int index)
 
Field UncheckedGetElement (std::string const &name)
 
FieldDefn UncheckedGetFieldDefn (int index) const
 
FieldDefn UncheckedGetFieldDefn (std::string const &name) const
 
int UncheckedGetFieldIndex (std::string const &name) const
 
long UncheckedGetFID () const
 
void UncheckedSetFID (long fid)
 
OGRFeatureDefn & UncheckedGetDefn () const
 
void UncheckedSetGeometryDirectly (UniqueGeometryPtr geometry)
 
UniqueGeometryPtr UncheckedStealGeometry ()
 
OGRGeometry const * UncheckedGetGeometry () const
 
void UncheckedSetGeometry (OGRGeometry const *geometry)
 
void CheckInvariants () const
 

Detailed Description

Geometric object with descriptive fields.

It provides an encapsulation of OGR classes. In that particular case, it's an encapsulation of OGRFeature.

Note
This class is a proxy class on top of an OGRLayer.
It can be copied, and assigned. New instances will share the underlying OGRLayer: Feature assignment will just make one Feature proxy point to another OGRFeature. In order to truly assign from one to another, use SetFrom, or Clone in order to duplicate the current feature.
The default constructor is disabled on purpose.
The destructor automatically generated does everything that is expected.
Invariant
m_Feature != 0 Actually, this isn't a true invariant per se, as it may be null in some cases, for instance to define mark the Layer::end() iterator.
Since
OTB v 3.14.0

Definition at line 63 of file otbOGRFeatureWrapper.h.

Constructor & Destructor Documentation

◆ Feature() [1/2]

otb::ogr::Feature::Feature ( OGRFeatureDefn &  definition)

Construction from a definition.

Parameters
[in]definitiondefinition of the fields of the feature.
Exceptions
None
Postcondition
m_Feature != 0
definition internal reference count is incremented
Warning
DO NOT destroy the definition while it is relied upon by features.

◆ Feature() [2/2]

otb::ogr::Feature::Feature ( OGRFeature *  feature)

Construction from a pre-existing OGRFeature.

Parameters
[in,out]featurepre-existing feature that will be owned by the wrapper.
Exceptions
None
Precondition
The feature is expected to have been built with OGR API.

◆ ~Feature()

otb::ogr::Feature::~Feature ( )

Destructor.

Exceptions
None

Member Function Documentation

◆ addr()

OGRFeature const* otb::ogr::Feature::addr ( ) const
inline

Changes the current geometry.

Parameters
[in]geometryPointer to an existing geometry, null to dismiss any geometry.
Postcondition
The input OGRGeometry is copied (cloned actually).
Exceptions
itk::ExceptionObjecton failure.
Invariant
m_Feature != 0
See also
OGRFeature::SetGeometry()

Definition at line 338 of file otbOGRFeatureWrapper.h.

Referenced by otb::Wrapper::TrainVectorBase< TInputValue, TOutputValue >::ExtractSamplesWithLabel().

◆ CheckInvariants()

void otb::ogr::Feature::CheckInvariants ( ) const
inlineprivate

Checks whether the internal OGRFeature is non null. Fires an assertion otherwise.

Definition at line 34 of file otbOGRFeatureWrapper.hxx.

References m_Feature.

◆ Clone()

otb::ogr::Feature otb::ogr::Feature::Clone ( ) const
inline

Duplicates the current feature.

Returns
a duplicita of *this.
Exceptions
None
Invariant
m_Feature != 0

As Feature is a proxy class that shares its underlying OGRFeature, this function represents the only way to duplicate a feature.

See also
OGRFeature::Clone()

Definition at line 39 of file otbOGRFeatureWrapper.hxx.

◆ GetDefn()

OGRFeatureDefn & otb::ogr::Feature::GetDefn ( ) const
inline

Feature definition accessor.

Returns
a reference to the internal definition.
Exceptions
None
Invariant
m_Feature != 0
See also
OGRFeature::GetDefnRef()

Definition at line 115 of file otbOGRFeatureWrapper.hxx.

◆ GetFID()

long otb::ogr::Feature::GetFID ( ) const
inline

Obtains feature ID..

Returns
its ID, or OGRNullFID if none has been assigned.
Exceptions
None
Invariant
m_Feature != 0
See also
OGRFeature::GetFID()

Definition at line 103 of file otbOGRFeatureWrapper.hxx.

Referenced by otb::PersistentOGRDataToSamplePositionFilter< TInputImage, TMaskImage, TSampler >::ProcessSample(), and otb::OGRLayerStreamStitchingFilter< TInputImage >::ProcessStreamingLine().

◆ GetFieldDefn() [1/2]

otb::ogr::FieldDefn otb::ogr::Feature::GetFieldDefn ( int  index) const
inline

Accessor to the definition of the i-th field.

Invariant
m_Feature != 0
Precondition
index < GetSize()
Exceptions
None
See also
OGRFeature::GetFieldDefnRef()

Definition at line 82 of file otbOGRFeatureWrapper.hxx.

◆ GetFieldDefn() [2/2]

otb::ogr::FieldDefn otb::ogr::Feature::GetFieldDefn ( std::string const &  name) const
inline

Accessor to the definition of a field gven its name.

Invariant
m_Feature != 0
Exceptions
itk::ExceptionObjectif no field named name exists.
See also
OGRFeature::GetFieldDefnRef()

Definition at line 88 of file otbOGRFeatureWrapper.hxx.

◆ GetFieldIndex()

int otb::ogr::Feature::GetFieldIndex ( std::string const &  name) const
inline

Searches the index of a field given a name.

Invariant
m_Feature != 0
Exceptions
itk::ExceptionObjectif no field named name exists.

Definition at line 94 of file otbOGRFeatureWrapper.hxx.

◆ GetGeometry()

OGRGeometry const * otb::ogr::Feature::GetGeometry ( ) const
inline

Accessor to the internal OGRGeometry stored.

Returns
The result may be null if no geometry is associated to the feature.
In any case the result shall not be modified.
Exceptions
None
Invariant
m_Feature != 0
See also
OGRFeature::GetGeometryRef()

Definition at line 149 of file otbOGRFeatureWrapper.hxx.

Referenced by otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::operator()(), and otb::OGRLayerStreamStitchingFilter< TInputImage >::ProcessStreamingLine().

◆ GetSize()

int otb::ogr::Feature::GetSize ( ) const

Returns the number of fields.

Invariant
m_Feature != 0
See also
OGRFeature::GetFieldCount()

◆ ogr() [1/2]

OGRFeature& otb::ogr::Feature::ogr ( )

Access to raw OGRFeature. This function provides an abstraction leak in case deeper control on the underlying OGRFeature is required.

Invariant
The underlying OGRFeature must be valid, i.e. m_DataSource != 0, an assertion is fired otherwise.
Warning
You must under no circumstance try to delete the OGRFeature obtained this way.

◆ ogr() [2/2]

OGRFeature & otb::ogr::Feature::ogr ( ) const
inline

Access to raw OGRFeature. This function provides an abstraction leak in case deeper control on the underlying OGRFeature is required.

Invariant
The underlying OGRFeature must be valid, i.e. m_DataSource != 0, an assertion is fired otherwise.
Warning
You must under no circumstance try to delete the OGRFeature obtained this way.

Definition at line 158 of file otbOGRFeatureWrapper.hxx.

Referenced by otb::Wrapper::TrainVectorBase< TInputValue, TOutputValue >::DoUpdateParameters(), otb::Wrapper::TrainVectorBase< TInputValue, TOutputValue >::ExtractSamplesWithLabel(), otb::PersistentOGRDataToClassStatisticsFilter< TInputImage, TMaskImage >::PrepareFeature(), and otb::PersistentOGRDataToSamplePositionFilter< TInputImage, TMaskImage, TSampler >::ProcessSample().

◆ operator[]() [1/4]

otb::ogr::Field otb::ogr::Feature::operator[] ( int  index)
inline

Read-Write access to the i-th field.

Invariant
m_Feature != 0
Precondition
index < GetSize()
Exceptions
None

Definition at line 60 of file otbOGRFeatureWrapper.hxx.

◆ operator[]() [2/4]

const otb::ogr::Field otb::ogr::Feature::operator[] ( int  index) const
inline

Read-only access to the i-th field.

Invariant
m_Feature != 0
Precondition
index < GetSize()
Exceptions
None

Definition at line 66 of file otbOGRFeatureWrapper.hxx.

◆ operator[]() [3/4]

otb::ogr::Field otb::ogr::Feature::operator[] ( std::string const &  name)
inline

Read-Write access to a field by name.

Invariant
m_Feature != 0
Exceptions
itk::ExceptionObjectif no field named name exists.

Definition at line 71 of file otbOGRFeatureWrapper.hxx.

◆ operator[]() [4/4]

const otb::ogr::Field otb::ogr::Feature::operator[] ( std::string const &  name) const
inline

Read-Only access to a field by name.

Invariant
m_Feature != 0
Exceptions
itk::ExceptionObjectif no field named name exists.

Definition at line 77 of file otbOGRFeatureWrapper.hxx.

◆ PrintSelf()

void otb::ogr::Feature::PrintSelf ( std::ostream &  os,
itk::Indent  indent 
) const
inline

Prints self into stream.

Definition at line 170 of file otbOGRFeatureWrapper.hxx.

◆ SetFID()

void otb::ogr::Feature::SetFID ( long  fid)
inline

◆ SetFrom() [1/2]

void otb::ogr::Feature::SetFrom ( Feature const &  rhs,
bool  mustForgive = true 
)
inline

Assigns a pre-existing feature to the current one.

Parameters
[in]rhspre-existing feature to assign ourseleves from.
[in]mapinteger list of the fields to duplicated (default: all)
[in]mustForgivetells whether the operation should continue despite lacking output fields matching some of the source fields.
Exceptions
itk::ExceptionObjectif no value is transferred
See also
OGRFeature::SetFrom()

Definition at line 45 of file otbOGRFeatureWrapper.hxx.

◆ SetFrom() [2/2]

void otb::ogr::Feature::SetFrom ( Feature const &  rhs,
int *  map,
bool  mustForgive = true 
)
inline

◆ SetGeometry()

void otb::ogr::Feature::SetGeometry ( OGRGeometry const *  geometry)
inline

Changes the current geometry.

Parameters
[in]geometryPointer to an existing geometry, null to dismiss any geometry.
Postcondition
The input OGRGeometry is copied (cloned actually).
Exceptions
itk::ExceptionObjecton failure.
Invariant
m_Feature != 0
See also
OGRFeature::SetGeometry()

Definition at line 143 of file otbOGRFeatureWrapper.hxx.

Referenced by otb::PersistentOGRDataToSamplePositionFilter< TInputImage, TMaskImage, TSampler >::ProcessSample(), and otb::OGRLayerStreamStitchingFilter< TInputImage >::ProcessStreamingLine().

◆ SetGeometryDirectly()

void otb::ogr::Feature::SetGeometryDirectly ( UniqueGeometryPtr  geometry)
inline

Changes the current geometry (transfers ownership).

Parameters
[in]geometryUnique-pointer to an existing geometry, null to dismiss any geometry.
Postcondition
Ownership of the input OGRGeometry is given to the feature.
GetGeometry() == initial_geometry
The user is no longer responsible of the input geometry, even on failure of the operation. In that case, the geometry would have been definitivelly destroyed with the ad'hoc function (OGRGeometryFactory::destroyGeometry()).
Exceptions
itk::ExceptionObjecton failure.
Invariant
m_Feature != 0
See also
OGRFeature::SetGeometryDirectly()

Definition at line 124 of file otbOGRFeatureWrapper.hxx.

Referenced by otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::operator()().

◆ sptr() [1/2]

std::shared_ptr<OGRFeature>& otb::ogr::Feature::sptr ( )
inline

Abstraction leak to the internal shared OGRFeature.

Exceptions
None

Definition at line 158 of file otbOGRFeatureWrapper.h.

◆ sptr() [2/2]

std::shared_ptr<OGRFeature> const& otb::ogr::Feature::sptr ( ) const
inline

Abstraction leak to the internal shared OGRFeature.

Exceptions
None

Definition at line 164 of file otbOGRFeatureWrapper.h.

◆ StealGeometry()

otb::ogr::UniqueGeometryPtr otb::ogr::Feature::StealGeometry ( )
inline

Steals the geometry stored..

Returns
A unique-pointer to a OGRGeometry that is now of the responsibility of the caller.
Postcondition
GetGeometry() == 0
Exceptions
None
Invariant
m_Feature != 0
See also
OGRFeature::StealGeometry()

Definition at line 135 of file otbOGRFeatureWrapper.hxx.

◆ UncheckedClone()

Feature otb::ogr::Feature::UncheckedClone ( ) const
private

Internal pointer to the shared OGRFeature.

◆ UncheckedGetDefn()

OGRFeatureDefn& otb::ogr::Feature::UncheckedGetDefn ( ) const
private

Internal pointer to the shared OGRFeature.

◆ UncheckedGetElement() [1/2]

Field otb::ogr::Feature::UncheckedGetElement ( int  index)
private

Internal pointer to the shared OGRFeature.

◆ UncheckedGetElement() [2/2]

Field otb::ogr::Feature::UncheckedGetElement ( std::string const &  name)
private

Internal pointer to the shared OGRFeature.

◆ UncheckedGetFID()

long otb::ogr::Feature::UncheckedGetFID ( ) const
private

Internal pointer to the shared OGRFeature.

◆ UncheckedGetFieldDefn() [1/2]

FieldDefn otb::ogr::Feature::UncheckedGetFieldDefn ( int  index) const
private

Internal pointer to the shared OGRFeature.

◆ UncheckedGetFieldDefn() [2/2]

FieldDefn otb::ogr::Feature::UncheckedGetFieldDefn ( std::string const &  name) const
private

Internal pointer to the shared OGRFeature.

◆ UncheckedGetFieldIndex()

int otb::ogr::Feature::UncheckedGetFieldIndex ( std::string const &  name) const
private

Internal pointer to the shared OGRFeature.

◆ UncheckedGetGeometry()

OGRGeometry const* otb::ogr::Feature::UncheckedGetGeometry ( ) const
private

Internal pointer to the shared OGRFeature.

◆ UncheckedPrintSelf()

void otb::ogr::Feature::UncheckedPrintSelf ( std::ostream &  os,
itk::Indent  indent 
) const
private

Internal pointer to the shared OGRFeature.

◆ UncheckedSetFID()

void otb::ogr::Feature::UncheckedSetFID ( long  fid)
private

Internal pointer to the shared OGRFeature.

◆ UncheckedSetFrom() [1/2]

void otb::ogr::Feature::UncheckedSetFrom ( Feature const &  rhs,
bool  mustForgive = true 
)
private

Internal pointer to the shared OGRFeature.

◆ UncheckedSetFrom() [2/2]

void otb::ogr::Feature::UncheckedSetFrom ( Feature const &  rhs,
int *  map,
bool  mustForgive = true 
)
private

Internal pointer to the shared OGRFeature.

◆ UncheckedSetGeometry()

void otb::ogr::Feature::UncheckedSetGeometry ( OGRGeometry const *  geometry)
private

Internal pointer to the shared OGRFeature.

◆ UncheckedSetGeometryDirectly()

void otb::ogr::Feature::UncheckedSetGeometryDirectly ( UniqueGeometryPtr  geometry)
private

Internal pointer to the shared OGRFeature.

◆ UncheckedStealGeometry()

UniqueGeometryPtr otb::ogr::Feature::UncheckedStealGeometry ( )
private

Internal pointer to the shared OGRFeature.

Friends And Related Function Documentation

◆ otb::ogr::operator==

bool otb::ogr::operator== ( Feature const &  lhs,
Feature const &  rhs 
)
friend

Tells whether two features are equal.

Returns
whether both are null or equal.
Exceptions
None
See also
OGRFeature::Equals()

Member Data Documentation

◆ m_Feature

std::shared_ptr<OGRFeature> otb::ogr::Feature::m_Feature
private

Internal pointer to the shared OGRFeature.

Definition at line 385 of file otbOGRFeatureWrapper.h.

Referenced by CheckInvariants().


The documentation for this class was generated from the following files: