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

#include <otbOGRLayerWrapper.h>

Classes

struct  boolean
 
class  feature_iter
 

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, GDALDataset &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 (int 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 operator== (Layer const &lhs, Layer const &rhs)
 

ITK standard definitions

typedef Layer Self
 
const char * GetNameOfClass () const
 

Iteration

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

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 79 of file otbOGRLayerWrapper.h.

Member Typedef Documentation

Features const iterator.

Definition at line 378 of file otbOGRLayerWrapper.h.

Features iterator.

Definition at line 376 of file otbOGRLayerWrapper.h.

Definition at line 85 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. Unfortunately, there is no mean to report this to this layer proxy.
otb::ogr::Layer::Layer ( OGRLayer *  layer,
GDALDataset &  sourceInChargeOfLifeTime,
bool  modifiable 
)

Init constructor for layers that need to be released.

Parameters
layerOGRLayer owned by the client code.
sourceInChargeOfLifeTimereference to the actual GDALDataset 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

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 existence 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
const_iterator otb::ogr::Layer::begin ( ) const
inline
iterator otb::ogr::Layer::begin ( )

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

See Also
feature_iter
const_iterator otb::ogr::Layer::cbegin ( ) const

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

See Also
feature_iter
const_iterator otb::ogr::Layer::cend ( ) const
inline

Returns the end iterator of the sequence.

Definition at line 387 of file otbOGRLayerWrapper.h.

void otb::ogr::Layer::CreateFeature ( Feature  feature)
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 existence 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

Referenced by otb::PersistentSamplingFilterBase< TInputImage, TMaskImage >::AllocateOutputs(), otb::LabelImageToVectorDataFilter< TInputImage, TPrecision >::GenerateData(), otb::LabelImageToOGRDataSourceFilter< TInputImage >::GenerateData(), otb::PersistentImageToOGRDataFilter< TImage >::Initialize(), and otb::PersistentSamplingFilterBase< TInputImage, TMaskImage >::InitializeOutputDataSource().

const_iterator otb::ogr::Layer::cstart_at ( GIntBig  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).
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()
void otb::ogr::Layer::DeleteField ( int  fieldIndex)

Deletes a field.

Parameters
[in]fieldIndexindex of the field to remove.
Precondition
This function shall not be called while there are Feature in existence 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.
const_iterator otb::ogr::Layer::end ( ) const
inline
iterator otb::ogr::Layer::end ( )
inline

Returns the end iterator of the sequence.

Definition at line 399 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.
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.
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()
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()

Referenced by otb::PersistentSamplingFilterBase< TInputImage, TMaskImage >::DispatchInputVectors(), otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::operator()(), otb::PersistentImageSampleExtractorFilter< TInputImage >::ThreadedGenerateVectorData(), and otb::PersistentSamplingFilterBase< TInputImage, TMaskImage >::ThreadedGenerateVectorData().

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

Returns the type of the geometry stored.

See Also
OGRLayer::GetGeomType()

Referenced by otb::PersistentSamplingFilterBase< TInputImage, TMaskImage >::AllocateOutputs().

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

Returns the name given to the layer, if any.

Referenced by otb::PersistentSamplingFilterBase< TInputImage, TMaskImage >::InitializeOutputDataSource().

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

Definition at line 86 of file otbOGRLayerWrapper.h.

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

Internal encapsulation of OGRLayer::GetNextFeature().

Returns
the next OGRFeature of the layer, encapsulated in a Feature.
Exceptions
None
std::string otb::ogr::Layer::GetProjectionRef ( ) const

Returns the projection ref associated with the layer.

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

Referenced by otb::PersistentSamplingFilterBase< TInputImage, TMaskImage >::InitializeOutputDataSource().

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()
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.

Referenced by otb::PersistentSamplingFilterBase< TInputImage, TMaskImage >::AllocateOutputs(), otb::PersistentImageToOGRLayerFilter< TImage >::GenerateData(), and otb::PersistentImageSampleExtractorFilter< TInputImage >::GenerateOutputInformation().

OGRLayer& otb::ogr::Layer::ogr ( )
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 239 of file otbOGRLayerWrapper.h.

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

Prints self into stream.

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 existence 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.
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 existence 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.
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 needs 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.

Referenced by otb::PersistentOGRDataToSamplePositionFilter< TInputImage, TMaskImage, TSampler >::FillOneOutput(), otb::PersistentSamplingFilterBase< TInputImage, TMaskImage >::FillOneOutput(), and otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::operator()().

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()
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()

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

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()
const_iterator otb::ogr::Layer::start_at ( GIntBig  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 409 of file otbOGRLayerWrapper.h.

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

iterator otb::ogr::Layer::start_at ( GIntBig  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).

Friends And Related Function Documentation

template<class >
friend class feature_iter
friend

Features iterator.

Definition at line 374 of file otbOGRLayerWrapper.h.

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

Compares layers identities.

Returns
whether the two layers are in fact the same.

Definition at line 528 of file otbOGRLayerWrapper.h.

Member Data Documentation

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

Data implementation.

Definition at line 552 of file otbOGRLayerWrapper.h.

Referenced by otb::ogr::operator==().

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

Definition at line 554 of file otbOGRLayerWrapper.h.


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