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

Layer of geometric objets. More...

#include <otbOGRLayerWrapper.h>

Classes

struct  boolean
  More...
 
class  feature_iter
 Implementation class for Feature iterator. This iterator is a single pass iterator. We may fetch the Feature referenced by an iterator previously stored, but never resume the iteration after a call to Layer::begin(), Layer::start_at(), Layer::CreateFeature(), Layer::DeleteFeature(), Layer::GetFeature(), Layer::SetFeature(), nor fork the iteration. More...
 

Public Member Functions

OGREnvelope GetExtent (bool force=false) const
 
void GetExtent (double &ulx, double &uly, double &lrx, double &lry, bool force=false) const
 
OGRwkbGeometryType GetGeomType () const
 
std::string GetName () const
 
std::string GetProjectionRef () const
 
OGRSpatialReference const * GetSpatialRef () const
 
OGRLayer & ogr ()
 
 operator int boolean::* () const
 
void PrintSelf (std::ostream &os, itk::Indent indent) const
 
Construction
 Layer (OGRLayer *layer, bool modifiable)
 
 Layer (OGRLayer *layer, OGRDataSource &sourceInChargeOfLifeTime, bool modifiable)
 
Features collection
int GetFeatureCount (bool doForceComputation) const
 
void CreateFeature (Feature feature)
 
void DeleteFeature (long nFID)
 
Feature GetFeature (long nFID)
 
void SetFeature (Feature feature)
 
Spatial filter property
Todo:
We'll see later if a Geometry capsule is defined, or a nondeletable<> pointer type.
OGRGeometry const * GetSpatialFilter () const
 
void SetSpatialFilter (OGRGeometry const *spatialFilter)
 
void SetSpatialFilterRect (double dfMinX, double dfMinY, double dfMaxX, double dfMaxY)
 
Features definition
Todo:
Shall we instead inhibit the declaration of the functions when GDAL version does not match?
OGRFeatureDefn & GetLayerDefn () const
 
void CreateField (FieldDefn const &field, bool bApproxOK=true)
 
void DeleteField (vcl_size_t fieldIndex)
 
void AlterFieldDefn (vcl_size_t fieldIndex, FieldDefn const &newFieldDefn, int nFlags)
 
void ReorderField (vcl_size_t oldPos, vcl_size_t newPos)
 
void ReorderFields (int *map)
 
void SetIgnoredFields (char const **fieldNames)
 

Private Member Functions

Feature GetNextFeature ()
 

Private Attributes

boost::shared_ptr< OGRLayer > m_Layer
 
bool m_Modifiable
 

Friends

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

ITK standard definitions

typedef Layer Self
 
const char * GetNameOfClass () const
 

Iteration

typedef feature_iter< Featureiterator
 Features iterator. More...
 
typedef feature_iter< Feature
const > 
const_iterator
 Features const iterator. More...
 
template<class >
class feature_iter
 Features iterator. More...
 
const_iterator cbegin () const
 
const_iterator cend () const
 
const_iterator begin () const
  More...
 
const_iterator end () const
  More...
 
iterator begin ()
  More...
 
iterator end ()
  More...
 
const_iterator cstart_at (vcl_size_t index) const
 
const_iterator start_at (vcl_size_t index) const
  More...
 
iterator start_at (vcl_size_t index)
  More...
 

Detailed Description

Layer of geometric objets.

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

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.
When created from a otb::ogr::DataSource::ExecuteSQL(), it will automatically manage the release of the underlying OGRLayer.
The default constructor is disabled on purpose.
The destructor automatically generated does everything that is expected.
Todo:
Find a way to be notified when the related OGRDataSource is released
Since
OTB v 3.14.0

Definition at line 64 of file otbOGRLayerWrapper.h.

Member Typedef Documentation

Features const iterator.

Definition at line 355 of file otbOGRLayerWrapper.h.

Features iterator.

Definition at line 353 of file otbOGRLayerWrapper.h.

Definition at line 69 of file otbOGRLayerWrapper.h.

Constructor & Destructor Documentation

otb::ogr::Layer::Layer ( OGRLayer *  layer,
bool  modifiable 
)

Init constructor with a layer owned by a DataSource.

Parameters
layerOGRLayer instance that is owned by a DataSource.
datasourcePointer to the actual data source.
Exceptions
NoneOn destruction of the proxy class, the internal OGRLayer is left alone.
Warning
If the datasource hosting the layer (built with this constructor) is deleted, the layer won't be usable anymore. Unfortunatelly, there is no mean to report this to this layer proxy.

Definition at line 47 of file otbOGRLayerWrapper.cxx.

otb::ogr::Layer::Layer ( OGRLayer *  layer,
OGRDataSource &  sourceInChargeOfLifeTime,
bool  modifiable 
)

Init constructor for layers that need to be released.

Parameters
layerOGRLayer owned by the client code.
sourceInChargeOfLifeTimereference to the actual OGRDataSource that knows how to release the layer.
Postcondition
In this case, m_datasource is left null: we suppose (for now, that the layer won't need access to the datasource meta-information).
Exceptions
None

Definition at line 56 of file otbOGRLayerWrapper.cxx.

Member Function Documentation

void otb::ogr::Layer::AlterFieldDefn ( vcl_size_t  fieldIndex,
FieldDefn const &  newFieldDefn,
int  nFlags 
)

Changes the definition of the i-th field.

Parameters
[in]fieldIndexindex of the field to change
[in,out]newFieldDefndefinition of the new field.
[in]nFlagscombination of ALTER_NAME_FLAG, ALTER_TYPE_FLAG and ALTER_WIDTH_PRECISION_FLAG to indicate which of the name and/or type and/or width and precision fields from the new field definition must be taken into account.
Precondition
This function shall not be called while there are Feature in existance that were obtained or created with the previous layer definition.
Exceptions
itk::ExceptionObjectif the new field cannot be modified
See Also
OGRLayer::AlterFieldDefn()
Precondition
To be available, this function requires OTB to be compiled against OGR v1.9.0 at least.
Todo:
Move to use otb::ogr::FieldDefn

Definition at line 339 of file otbOGRLayerWrapper.cxx.

References otb::ogr::FieldDefn::ogr().

const_iterator otb::ogr::Layer::begin ( ) const
inline
otb::ogr::Layer::iterator otb::ogr::Layer::begin ( )

Returns a single-pass iterator to the start of the sequence.

See Also
feature_iter

Definition at line 80 of file otbOGRLayerWrapper.cxx.

otb::ogr::Layer::const_iterator otb::ogr::Layer::cbegin ( ) const

Returns a single-pass iterator to the start of the sequence.

See Also
feature_iter

Definition at line 87 of file otbOGRLayerWrapper.cxx.

Referenced by begin().

const_iterator otb::ogr::Layer::cend ( ) const
inline

Returns the end iterator of the sequence.

Definition at line 363 of file otbOGRLayerWrapper.h.

Referenced by end().

void otb::ogr::Layer::CreateFeature ( Feature  feature)

Adds a pre-existing Feature to the layer.

Parameters
[in,out]featurefeature to add. Upon successful completion, the feature id will be updated (unless it was previously set)
Exceptions
itk::ExceptionObjectif the feature can't be added.
See Also
OGRLayer::CreateFeature()

Definition at line 108 of file otbOGRLayerWrapper.cxx.

References otb::ogr::Feature::ogr().

Referenced by otb::PersistentImageToOGRDataFilter< TImage >::GenerateData(), and otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::operator()().

void otb::ogr::Layer::CreateField ( FieldDefn const &  field,
bool  bApproxOK = true 
)

Adds a new field given its definition.

Parameters
[in]fieldfield definition
[in]bApproxOKIf true, the field may be created in a slightly different form depending on the limitations of the format driver.
Precondition
This function shall not be called while there are Feature in existance that were obtained or created with the previous layer definition.
Exceptions
itk::ExceptionObjectif the new field cannot be created
See Also
OGRLayer::CreateField()
Warning
Calls to this function may invalidate any feature iterator previously obtained depending on the actual OGRDriver.
Todo:
Move to use otb::ogr::FieldDefn

Definition at line 297 of file otbOGRLayerWrapper.cxx.

References otb::ogr::FieldDefn::ogr().

Referenced by otb::FieldCopyTransformation::DefineFields(), otb::LabelImageToVectorDataFilter< TInputImage, TPrecision >::GenerateData(), and otb::LabelImageToOGRDataSourceFilter< TInputImage >::GenerateData().

otb::ogr::Layer::const_iterator otb::ogr::Layer::cstart_at ( vcl_size_t  index) const

Returns a single-pass iterator to the i-th Feature of the sequence.

See Also
feature_iter Depending of the actual driver (i.e. OGRDriver), this may be done in O(N).

Definition at line 101 of file otbOGRLayerWrapper.cxx.

Referenced by start_at().

void otb::ogr::Layer::DeleteFeature ( long  nFID)

Removes a feature identified by its id from the Layer.

Parameters
[in]nFIDfeature id.
Exceptions
itk::ExceptionObjectif the feature can't be added.
Warning
Calls to this function will invalidate any feature iterator previously obtained.
See Also
OGRFeature::DeleteFeature()

Definition at line 126 of file otbOGRLayerWrapper.cxx.

Referenced by otb::PersistentImageToOGRLayerSegmentationFilter< TImageType, TSegmentationFilter >::ProcessTile().

void otb::ogr::Layer::DeleteField ( vcl_size_t  fieldIndex)

Deletes a field.

Parameters
[in]fieldIndexindex of the field to remove.
Precondition
This function shall not be called while there are Feature in existance that were obtained or created with the previous layer definition.
Exceptions
itk::ExceptionObjectif the new field cannot be deleted
See Also
OGRLayer::DeleteField()
Precondition
To be available, this function requires OTB to be compiled against OGR v1.9.0 at least.

Definition at line 316 of file otbOGRLayerWrapper.cxx.

const_iterator otb::ogr::Layer::end ( ) const
inline
iterator otb::ogr::Layer::end ( )
inline

Returns the end iterator of the sequence.

Definition at line 371 of file otbOGRLayerWrapper.h.

OGREnvelope otb::ogr::Layer::GetExtent ( bool  force = false) const

Retrieves the extent of the layer.

Parameters
[in]forceForce computation of the extent if not available. May force the driver to walk all geometries to compute the extent.
Returns
the extent of the layer
Exceptions
itk::ExceptionObjectif the extent can not be retrieved.

Definition at line 186 of file otbOGRLayerWrapper.cxx.

void otb::ogr::Layer::GetExtent ( double &  ulx,
double &  uly,
double &  lrx,
double &  lry,
bool  force = false 
) const

Retrieves the extent of the layer.

Parameters
[out]ulxreference to upper-left x coordinate of the extent
[out]ulyreference to upper-left y coordinate of the extent
[out]lrxreference to lower-right x coordinate of the extent
[out]ulyreference to lower-right y coordinate of the extent
[in]forceForce computation of the extent if not available. May force the driver to walk all geometries to compute the extent.
Exceptions
itk::ExceptionObjectif the extent can not be retrieved.

Definition at line 199 of file otbOGRLayerWrapper.cxx.

otb::ogr::Feature otb::ogr::Layer::GetFeature ( long  nFID)

Finds a feature from its id.

Parameters
[in]nFIDfeature id.
Returns
a RAII capsule around the OGRFeature stored in the layer and that matches the requested id.
Exceptions
itk::ExceptionObjectif nFID is null
Precondition
nFID value cannot be OGRNullFID
Postcondition
Result's GetFID() equals nFID
Warning
Calls to this function will invalidate any feature iterator previously obtained.
See Also
OGRFeature::GetFeature()

Definition at line 144 of file otbOGRLayerWrapper.cxx.

int otb::ogr::Layer::GetFeatureCount ( bool  doForceComputation) const

Returns the number of elements in the layer.

Parameters
[in]doForceCompuationindicates whether the size shall be computed even so it's expensive to do so.
Returns
the number of features in the layer, -1 if count is unknown
Exceptions
None
See Also
OGRLayer::GetFeatureCount()

Definition at line 67 of file otbOGRLayerWrapper.cxx.

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

OGRwkbGeometryType otb::ogr::Layer::GetGeomType ( ) const

Returns the type of the geometry stored.

See Also
OGRLayer::GetGeomType()

Definition at line 428 of file otbOGRLayerWrapper.cxx.

Referenced by otb::GeometriesToGeometriesFilter::DoDefineNewLayerGeometryType().

OGRFeatureDefn & otb::ogr::Layer::GetLayerDefn ( ) const
std::string otb::ogr::Layer::GetName ( ) const

Returns the name given to the layer, if any.

Definition at line 176 of file otbOGRLayerWrapper.cxx.

Referenced by otb::ogr::DataSource::CopyLayer(), otb::ogr::DataSource::GetLayerIDUnchecked(), and otb::internal::ProcessVisitor::operator()().

const char* otb::ogr::Layer::GetNameOfClass ( ) const
inline

Definition at line 70 of file otbOGRLayerWrapper.h.

otb::ogr::Feature otb::ogr::Layer::GetNextFeature ( )
private

Internal encapsulation of OGRLayer::GetNextFeature().

Returns
the next OGRFeature of the layer, encapsulated in a Feature.
Exceptions
None

Definition at line 73 of file otbOGRLayerWrapper.cxx.

Referenced by otb::ogr::Layer::feature_iter< Value >::increment().

std::string otb::ogr::Layer::GetProjectionRef ( void  ) const

Returns the projection ref associated with the layer.

Returns
The projection ref (wkt string) associated with the layer

Definition at line 263 of file otbOGRLayerWrapper.cxx.

Referenced by otb::GeometriesProjectionFilter::DoProcessLayer().

OGRGeometry const * otb::ogr::Layer::GetSpatialFilter ( ) const

Returns a reference to the current spatial filter, if any.

Returns
a reference to the current spatial filter. Spatial filter that isn't supposed to be modified this way. Use SetSpatialFilter or SetSpatialFilterRect for this purpose.
Exceptions
None
See Also
OGRLayer::GetSpatialFilter()

Definition at line 236 of file otbOGRLayerWrapper.cxx.

OGRSpatialReference const * otb::ogr::Layer::GetSpatialRef ( ) const

Spatial Reference property.

Note
Read-only property. In order to set this property, you'll have to create a new layer with a spatial reference.

Definition at line 257 of file otbOGRLayerWrapper.cxx.

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

OGRLayer & otb::ogr::Layer::ogr ( )

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

Precondition
The underlying OGRLayer must be valid, i.e. m_Layer != 0, an assertion is fired otherwise.
Warning
You must under no circonstance try to delete the OGRLayer obtained this way.

Definition at line 208 of file otbOGRLayerWrapper.cxx.

Referenced by otb::ogr::DataSource::CopyLayer(), otb::LabelImageToVectorDataFilter< TInputImage, TPrecision >::GenerateData(), otb::LabelImageToOGRDataSourceFilter< TInputImage >::GenerateData(), and otb::PersistentImageToOGRDataFilter< TImage >::GenerateData().

otb::ogr::Layer::operator int boolean::* ( ) const
inline

Can the layer be used (ie not null).

Hack to provide a boolean operator that is convertible only to a boolean expression to be used in if tests.

See Also
Imperfect C++, Matthew Wilson, Addisson-Welsey, par 24.6

Definition at line 220 of file otbOGRLayerWrapper.h.

References otb::ogr::Layer::boolean::i, and m_Layer.

void otb::ogr::Layer::PrintSelf ( std::ostream &  os,
itk::Indent  indent 
) const
void otb::ogr::Layer::ReorderField ( vcl_size_t  oldPos,
vcl_size_t  newPos 
)

Moves a field from one position to another.

Parameters
[in]oldPosold field index position
[in]newPosnew field index position
Precondition
This function shall not be called while there are Feature in existance that were obtained or created with the previous layer definition.
Exceptions
itk::ExceptionObjectif the new field cannot be modified
See Also
OGRLayer::ReorderField()
Precondition
To be available, this function requires OTB to be compiled against OGR v1.9.0 at least.

Definition at line 366 of file otbOGRLayerWrapper.cxx.

void otb::ogr::Layer::ReorderFields ( int *  map)

Reorder all the fields of the layer.

Parameters
[in]maparray that tells the new position of each field.
Precondition
This function shall not be called while there are Feature in existance that were obtained or created with the previous layer definition.
Exceptions
itk::ExceptionObjectif the new field cannot be modified
See Also
OGRLayer::ReorderFields()
Precondition
To be available, this function requires OTB to be compiled against OGR v1.9.0 at least.

Definition at line 389 of file otbOGRLayerWrapper.cxx.

void otb::ogr::Layer::SetFeature ( Feature  feature)

Changes a Feature in the Layer.

Parameters
[in,out]featurefeature to set. Upon successful completion, the feature id will be updated (in case it was previously set)
Exceptions
itk::ExceptionObjectif the feature can't be set.
Precondition
The Layer need to support OLCRandomWrite capability.
See Also
OGRLayer::SetFeature()
Warning
Calls to this function may invalidate any feature iterator previously obtained depending on the actual OGRDriver.

Definition at line 155 of file otbOGRLayerWrapper.cxx.

References otb::ogr::Feature::ogr().

Referenced by otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::operator()(), and otb::PersistentImageToOGRLayerSegmentationFilter< TImageType, TSegmentationFilter >::ProcessTile().

void otb::ogr::Layer::SetIgnoredFields ( char const **  fieldNames)

Sets which fields can be omitted when retrieving features from the layer.

Parameters
[in]fieldNames0-terminated array of the field names to ignore when fetching features from the layer. 0 to clear the list. end

Besides field names of the layers, the following special fields can be passed: "OGR_GEOMETRY" to ignore geometry and "OGR_STYLE" to ignore layer style.

By default, no fields are ignored.

Exceptions
itk::ExceptionObjectif the new field cannot be modified
See Also
OGRLayer::SetIgnoredFields()

Definition at line 412 of file otbOGRLayerWrapper.cxx.

void otb::ogr::Layer::SetSpatialFilter ( OGRGeometry const *  spatialFilter)

Sets the current spatial filter. Replaces the current spatial filter with a clone of the one passed as parameter. Thus the parameter remains of the responsibility of the caller.

The spatial filter is used to filter the Feature's obtained when iterating on the layer.

Parameters
[in]spatialFilternew spatial filter definition, NULL clears the filter.
Exceptions
None
Note
OGR warns us that the test may be incorrectly implemented, and that we may have false-positives, but no missed shapes.
See Also
OGRLayer::SetSpatialFilter()

Definition at line 243 of file otbOGRLayerWrapper.cxx.

void otb::ogr::Layer::SetSpatialFilterRect ( double  dfMinX,
double  dfMinY,
double  dfMaxX,
double  dfMaxY 
)

Sets a new rectangular spatial filter. Defines the new filter as a rectangular shape.

The coordinates used shall be in the same referential as the layer as the whole (as returned by GetSpatialRef()).

See Also
OGRLayer::SetSpatialFilterRect()

Definition at line 250 of file otbOGRLayerWrapper.cxx.

const_iterator otb::ogr::Layer::start_at ( vcl_size_t  index) const
inline

Returns a single-pass iterator to the i-th Feature of the sequence.

See Also
feature_iter Depending of the actual driver (i.e. OGRDriver), this may be done in O(N).

Definition at line 380 of file otbOGRLayerWrapper.h.

References cstart_at().

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

otb::ogr::Layer::iterator otb::ogr::Layer::start_at ( vcl_size_t  index)

Returns a single-pass iterator to the i-th Feature of the sequence.

See Also
feature_iter Depending of the actual driver (i.e. OGRDriver), this may be done in O(N).

Definition at line 94 of file otbOGRLayerWrapper.cxx.

Friends And Related Function Documentation

template<class >
friend class feature_iter
friend

Features iterator.

Definition at line 351 of file otbOGRLayerWrapper.h.

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

Member Data Documentation

boost::shared_ptr<OGRLayer> otb::ogr::Layer::m_Layer
private

Data implementation.

Definition at line 517 of file otbOGRLayerWrapper.h.

Referenced by operator int boolean::*(), and otb::ogr::operator==().

bool otb::ogr::Layer::m_Modifiable
private

Definition at line 519 of file otbOGRLayerWrapper.h.


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