OTB  6.7.0
Orfeo Toolbox
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
otb::ogr::Feature Class Reference

#include <otbOGRFeatureWrapper.h>

Public Member Functions

OGRFeature const * addr () const
 
OGRFeatureDefn & GetDefn () const
 
long GetFID () const
 
OGRFeature & ogr () const
 
OGRFeature & ogr ()
 
void PrintSelf (std::ostream &os, itk::Indent indent) const
 
void SetFID (long fid)
 
boost::shared_ptr< OGRFeature > & sptr ()
 
boost::shared_ptr< OGRFeature >
const & 
sptr () const
 
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)
 
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)
 
Field const operator[] (int index) const
 
Field operator[] (std::string const &name)
 
Field const operator[] (std::string const &name) const
 
FieldDefn GetFieldDefn (int index) const
 
FieldDefn GetFieldDefn (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 ()
 

Private Member Functions

void CheckInvariants () const
 
int GetFieldIndex (std::string const &name) const
 
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.
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)
 

Private Attributes

boost::shared_ptr< OGRFeature > m_Feature
 

Friends

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

Detailed Description

Geometric objet 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 69 of file otbOGRFeatureWrapper.h.

Constructor & Destructor Documentation

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.
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.
otb::ogr::Feature::~Feature ( )

Destructor.

Exceptions
None

Member Function Documentation

OGRFeature const* otb::ogr::Feature::addr ( ) const
inline
void otb::ogr::Feature::CheckInvariants ( ) const
inlineprivate

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

Definition at line 49 of file otbOGRFeatureWrapper.hxx.

References m_Feature.

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 55 of file otbOGRFeatureWrapper.hxx.

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 143 of file otbOGRFeatureWrapper.hxx.

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 129 of file otbOGRFeatureWrapper.hxx.

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

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 105 of file otbOGRFeatureWrapper.hxx.

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 112 of file otbOGRFeatureWrapper.hxx.

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

Searches the index of a field given a name.

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

Definition at line 119 of file otbOGRFeatureWrapper.hxx.

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 181 of file otbOGRFeatureWrapper.hxx.

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

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

Returns the number of fields.

Invariant
m_Feature != 0
See Also
OGRFeature::GetFieldCount()
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 191 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().

OGRFeature & otb::ogr::Feature::ogr ( )
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 198 of file otbOGRFeatureWrapper.hxx.

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 79 of file otbOGRFeatureWrapper.hxx.

otb::ogr::Field const 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 86 of file otbOGRFeatureWrapper.hxx.

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 92 of file otbOGRFeatureWrapper.hxx.

otb::ogr::Field const 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 99 of file otbOGRFeatureWrapper.hxx.

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

Prints self into stream.

Definition at line 205 of file otbOGRFeatureWrapper.hxx.

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

Feature ID setter.

Parameters
[in]fidnew id.
Exceptions
itk::ExceptionObjectif it cannot be set.
Invariant
m_Feature != 0
See Also
OGRFeature::SetFID()

Definition at line 136 of file otbOGRFeatureWrapper.hxx.

Referenced by otb::PersistentOGRDataToSamplePositionFilter< TInputImage, TMaskImage, TSampler >::DispatchInputVectors(), and otb::PersistentSamplingFilterBase< TInputImage, TMaskImage >::DispatchInputVectors().

void otb::ogr::Feature::SetFrom ( Feature const &  rhs,
int *  map,
bool  mustForgive = true 
)
inline
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 62 of file otbOGRFeatureWrapper.hxx.

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 174 of file otbOGRFeatureWrapper.hxx.

Referenced by otb::OGRLayerStreamStitchingFilter< TInputImage >::ProcessStreamingLine().

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 153 of file otbOGRFeatureWrapper.hxx.

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

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

Abstraction leak to the internal shared OGRFeature.

Exceptions
None

Definition at line 164 of file otbOGRFeatureWrapper.h.

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

Abstraction leak to the internal shared OGRFeature.

Exceptions
None

Definition at line 167 of file otbOGRFeatureWrapper.h.

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 165 of file otbOGRFeatureWrapper.hxx.

Feature otb::ogr::Feature::UncheckedClone ( ) const
private
OGRFeatureDefn& otb::ogr::Feature::UncheckedGetDefn ( ) const
private
Field otb::ogr::Feature::UncheckedGetElement ( int  index)
private
Field otb::ogr::Feature::UncheckedGetElement ( std::string const &  name)
private
long otb::ogr::Feature::UncheckedGetFID ( ) const
private
FieldDefn otb::ogr::Feature::UncheckedGetFieldDefn ( int  index) const
private
FieldDefn otb::ogr::Feature::UncheckedGetFieldDefn ( std::string const &  name) const
private
int otb::ogr::Feature::UncheckedGetFieldIndex ( std::string const &  name) const
private
OGRGeometry const* otb::ogr::Feature::UncheckedGetGeometry ( ) const
private
void otb::ogr::Feature::UncheckedPrintSelf ( std::ostream &  os,
itk::Indent  indent 
) const
private
void otb::ogr::Feature::UncheckedSetFID ( long  fid)
private
void otb::ogr::Feature::UncheckedSetFrom ( Feature const &  rhs,
int *  map,
bool  mustForgive = true 
)
private
void otb::ogr::Feature::UncheckedSetFrom ( Feature const &  rhs,
bool  mustForgive = true 
)
private
void otb::ogr::Feature::UncheckedSetGeometry ( OGRGeometry const *  geometry)
private
void otb::ogr::Feature::UncheckedSetGeometryDirectly ( UniqueGeometryPtr  geometry)
private
UniqueGeometryPtr otb::ogr::Feature::UncheckedStealGeometry ( )
private

Friends And Related Function Documentation

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

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

Internal pointer to the shared OGRFeature.

Definition at line 381 of file otbOGRFeatureWrapper.h.

Referenced by CheckInvariants().


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