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

Geometric objet with descriptive fields. More...

#include <otbOGRFeatureWrapper.h>

Public Member Functions

OGRFeature const * addr () const
 
OGRFeatureDefn & GetDefn () const
 
long GetFID () const
 
OGRFeature & ogr () const
 
OGRFeature & ogr ()
  More...
 
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
  More...
 
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)
  More...
 
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.

vcl_size_t GetSize () const
 
Field operator[] (vcl_size_t index)
 
Field const operator[] (vcl_size_t index) const
 
Field operator[] (std::string const &name)
 
Field const operator[] (std::string const &name) const
 
FieldDefn GetFieldDefn (vcl_size_t 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 (vcl_size_t index)
 
Field UncheckedGetElement (std::string const &name)
 
FieldDefn UncheckedGetFieldDefn (vcl_size_t 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 55 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.

Definition at line 33 of file otbOGRFeatureWrapper.cxx.

References CheckInvariants().

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.

Definition at line 41 of file otbOGRFeatureWrapper.cxx.

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

Destructor.

Exceptions
None

Definition at line 50 of file otbOGRFeatureWrapper.cxx.

Member Function Documentation

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

Definition at line 301 of file otbOGRFeatureWrapper.h.

References m_Feature.

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

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

Definition at line 203 of file otbOGRFeatureWrapper.txx.

Referenced by Clone(), and 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 45 of file otbOGRFeatureWrapper.txx.

References CheckInvariants(), and UncheckedClone().

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 133 of file otbOGRFeatureWrapper.txx.

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 119 of file otbOGRFeatureWrapper.txx.

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

otb::ogr::FieldDefn otb::ogr::Feature::GetFieldDefn ( vcl_size_t  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 95 of file otbOGRFeatureWrapper.txx.

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 102 of file otbOGRFeatureWrapper.txx.

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 109 of file otbOGRFeatureWrapper.txx.

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 171 of file otbOGRFeatureWrapper.txx.

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

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

Returns the number of fields.

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

Definition at line 117 of file otbOGRFeatureWrapper.cxx.

Referenced by otb::FieldCopyTransformation::fieldsTransform().

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 circonstance try to delete the OGRFeature obtained this way.

Definition at line 181 of file otbOGRFeatureWrapper.txx.

Referenced by otb::ogr::Layer::CreateFeature(), otb::ogr::Layer::SetFeature(), and UncheckedSetFrom().

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 circonstance try to delete the OGRFeature obtained this way.

Definition at line 188 of file otbOGRFeatureWrapper.txx.

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

Read-Write access to the i-th field.

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

Definition at line 69 of file otbOGRFeatureWrapper.txx.

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

Read-only access to the i-th field.

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

Definition at line 76 of file otbOGRFeatureWrapper.txx.

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 82 of file otbOGRFeatureWrapper.txx.

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 89 of file otbOGRFeatureWrapper.txx.

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

Prints self into stream.

Definition at line 195 of file otbOGRFeatureWrapper.txx.

Referenced by otb::ogr::Layer::PrintSelf().

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 126 of file otbOGRFeatureWrapper.txx.

void otb::ogr::Feature::SetFrom ( Feature const &  rhs,
int *  map,
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 59 of file otbOGRFeatureWrapper.txx.

Referenced by otb::PersistentImageToOGRLayerFilter< TImage >::GenerateData(), and otb::PersistentImageToOGRDataFilter< TImage >::GenerateData().

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 52 of file otbOGRFeatureWrapper.txx.

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 164 of file otbOGRFeatureWrapper.txx.

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

References NULL.

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 145 of file otbOGRFeatureWrapper.h.

References m_Feature.

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

Abstraction leak to the internal shared OGRFeature.

Exceptions
None

Definition at line 147 of file otbOGRFeatureWrapper.h.

References m_Feature.

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 155 of file otbOGRFeatureWrapper.txx.

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

Definition at line 54 of file otbOGRFeatureWrapper.cxx.

Referenced by Clone().

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

Definition at line 175 of file otbOGRFeatureWrapper.cxx.

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

Definition at line 121 of file otbOGRFeatureWrapper.cxx.

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

Definition at line 127 of file otbOGRFeatureWrapper.cxx.

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

Definition at line 161 of file otbOGRFeatureWrapper.cxx.

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

Definition at line 133 of file otbOGRFeatureWrapper.cxx.

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

Definition at line 138 of file otbOGRFeatureWrapper.cxx.

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

Definition at line 148 of file otbOGRFeatureWrapper.cxx.

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

Definition at line 211 of file otbOGRFeatureWrapper.cxx.

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

Definition at line 166 of file otbOGRFeatureWrapper.cxx.

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

Definition at line 69 of file otbOGRFeatureWrapper.cxx.

References ogr().

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

Definition at line 60 of file otbOGRFeatureWrapper.cxx.

References ogr().

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

Definition at line 201 of file otbOGRFeatureWrapper.cxx.

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

Definition at line 184 of file otbOGRFeatureWrapper.cxx.

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

Definition at line 195 of file otbOGRFeatureWrapper.cxx.

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 347 of file otbOGRFeatureWrapper.h.

Referenced by addr(), otb::ogr::operator==(), and sptr().


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

Generated at Sat Mar 8 2014 19:09:06 for Orfeo Toolbox with doxygen 1.8.3.1