OTB  9.0.0
Orfeo Toolbox
Classes | List of all members
otb::ogr::Layer Class Reference

#include <otbOGRLayerWrapper.h>

+ Collaboration diagram for otb::ogr::Layer:

Classes

struct  boolean
 
class  feature_iter
 

Public Member Functions

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)
 
std::string GetName () const
 
OGREnvelope GetExtent (bool force=false) const
 
void GetExtent (double &ulx, double &uly, double &lrx, double &lry, bool force=false) const
 
void PrintSelf (std::ostream &os, itk::Indent indent) const
 
 operator int boolean::* () const
 
OGRLayer & ogr ()
 
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)
 
OGRSpatialReference const * GetSpatialRef () const
 
std::string GetProjectionRef () const
 

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)
 

Features definition

Todo:
Shall we instead inhibit the declaration of the functions when GDAL version does not match?
bool operator== (Layer const &lhs, Layer const &rhs)
 
std::shared_ptr< OGRLayer > m_Layer
 
bool m_Modifiable
 
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)
 
OGRwkbGeometryType GetGeomType () const
 
Feature GetNextFeature ()
 

Detailed Description

Layer of geometric objects.

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

Member Typedef Documentation

◆ const_iterator

Features const iterator.

Definition at line 397 of file otbOGRLayerWrapper.h.

◆ iterator

Features iterator.

Definition at line 395 of file otbOGRLayerWrapper.h.

◆ Self

Definition at line 86 of file otbOGRLayerWrapper.h.

Constructor & Destructor Documentation

◆ Layer() [1/2]

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.

◆ Layer() [2/2]

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

◆ AlterFieldDefn()

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

◆ begin() [1/2]

iterator otb::ogr::Layer::begin ( )

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

See also
feature_iter

◆ begin() [2/2]

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

◆ cbegin()

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

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

See also
feature_iter

Referenced by otb::Wrapper::VectorPrediction< RegressionMode >::ReadInputListSample().

◆ cend()

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

Returns the end iterator of the sequence.

Definition at line 406 of file otbOGRLayerWrapper.h.

◆ CreateFeature()

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

◆ CreateField()

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::Wrapper::VectorPrediction< RegressionMode >::AddPredictionField(), otb::PersistentSamplingFilterBase< TInputImage >::AllocateOutputs(), otb::Wrapper::VectorPrediction< RegressionMode >::CreateOutputDataSource(), otb::LabelImageToVectorDataFilter< TInputImage, TPrecision >::GenerateData(), otb::LabelImageToOGRDataSourceFilter< TInputImage >::GenerateData(), otb::PersistentImageToOGRDataFilter< TImage >::Initialize(), and otb::PersistentSamplingFilterBase< TInputImage >::InitializeOutputDataSource().

◆ cstart_at()

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

◆ DeleteFeature()

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

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

◆ DeleteField()

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.

◆ end() [1/2]

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

Returns the end iterator of the sequence.

Definition at line 427 of file otbOGRLayerWrapper.h.

◆ end() [2/2]

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

◆ GetExtent() [1/2]

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.

◆ GetExtent() [2/2]

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.

◆ GetFeature()

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

◆ GetFeatureCount()

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

Returns the number of elements in the layer.

Parameters
[in]doForceComputationindicates 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 >::DispatchInputVectors(), otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::operator()(), otb::PersistentImageSampleExtractorFilter< TInputImage >::ThreadedGenerateVectorData(), and otb::PersistentSamplingFilterBase< TInputImage >::ThreadedGenerateVectorData().

◆ GetGeomType()

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

Returns the type of the geometry stored.

See also
OGRLayer::GetGeomType()

Referenced by otb::PersistentSamplingFilterBase< TInputImage >::AllocateOutputs(), and otb::Wrapper::VectorPrediction< RegressionMode >::CreateOutputDataSource().

◆ GetLayerDefn()

OGRFeatureDefn& otb::ogr::Layer::GetLayerDefn ( ) const

◆ GetName()

std::string otb::ogr::Layer::GetName ( ) const

Returns the name given to the layer, if any.

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

◆ GetNameOfClass()

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

Definition at line 87 of file otbOGRLayerWrapper.h.

◆ GetNextFeature()

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

Internal encapsulation of OGRLayer::GetNextFeature().

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

◆ GetProjectionRef()

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

◆ GetSpatialFilter()

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

◆ GetSpatialRef()

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

◆ ogr()

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

◆ operator int boolean::*()

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

◆ PrintSelf()

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

Prints self into stream.

◆ ReorderField()

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.

◆ ReorderFields()

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.

◆ SetFeature()

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 >::FillOneOutput(), otb::Wrapper::VectorPrediction< RegressionMode >::FillOutputLayer(), otb::TransformationFunctorDispatcher< TransformationFunctor, OGRGeometry, FieldTransformationPolicy >::operator()(), and otb::PersistentImageToOGRLayerSegmentationFilter< TImageType, TSegmentationFilter >::ProcessTile().

◆ SetIgnoredFields()

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

◆ SetSpatialFilter()

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(), and otb::PersistentSamplingFilterBase< TInputImage >::DispatchInputVectors().

◆ SetSpatialFilterRect()

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

◆ start_at() [1/2]

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

◆ start_at() [2/2]

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

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

Friends And Related Function Documentation

◆ feature_iter

template<class >
friend class feature_iter
friend

Features iterator.

Definition at line 393 of file otbOGRLayerWrapper.h.

◆ operator==

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

Member Data Documentation

◆ m_Layer

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

Data implementation.

Definition at line 586 of file otbOGRLayerWrapper.h.

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

◆ m_Modifiable

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

Compares layers identities.

Returns
whether the two layers are in fact the same.

Definition at line 588 of file otbOGRLayerWrapper.h.


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