Class: QgsFeatureSink

An interface for objects which accept features via addFeature(s) methods.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: addFeatures()

Class Hierarchy

Inheritance diagram of qgis.core.QgsFeatureSink

Subclasses

QgsVectorLayer

Represents a vector layer which manages a vector based dataset.

QgsFeatureStore

A container for features with the same fields and crs.

QgsProxyFeatureSink

A simple feature sink which proxies feature addition onto another feature sink.

QgsRemappingProxyFeatureSink

A QgsFeatureSink which proxies incoming features to a destination feature sink, after applying transformations and field value mappings.

QgsSpatialIndex

A spatial index for QgsFeature objects.

QgsVectorDataProvider

Base class for vector data providers.

QgsVectorFileWriter

A convenience class for writing vector layers to disk based formats (e.g. Shapefiles, GeoPackage).

QgsVectorLayerExporter

A convenience class for exporting vector layers to a destination data provider.

QgsVectorLayerJoinBuffer

Manages joined fields for a vector layer.

QgsFeaturePool

A feature pool is based on a vector layer and caches features.

class qgis.core.QgsFeatureSink[source]

Bases: object

FastInsert = 2
class Flag

Bases: int

class Flags
class Flags(f: QgsFeatureSink.Flags | QgsFeatureSink.Flag)
class Flags(a0: QgsFeatureSink.Flags)

Bases: object

RegeneratePrimaryKey = 2
RollBackOnErrors = 4
class SinkFlag

Bases: int

class SinkFlags
class SinkFlags(f: QgsFeatureSink.SinkFlags | QgsFeatureSink.SinkFlag)
class SinkFlags(a0: QgsFeatureSink.SinkFlags)

Bases: object

virtual addFeature(self, feature: QgsFeature, flags: QgsFeatureSink.Flags | QgsFeatureSink.Flag = QgsFeatureSink.Flags()) bool[source]

Adds a single feature to the sink. Feature addition behavior is controlled by the specified flags.

See also

addFeatures()

Return type:

bool

Returns:

True in case of success and False in case of failure

Parameters:
abstract addFeatures(self, features: Iterable[QgsFeature], flags: QgsFeatureSink.Flags | QgsFeatureSink.Flag = QgsFeatureSink.Flags()) bool[source]

Adds a list of features to the sink. Feature addition behavior is controlled by the specified flags.

See also

addFeature()

Returns:

True in case of success and False in case of failure

addFeatures(self, iterator: QgsFeatureIterator, flags: Union[QgsFeatureSink.Flags, QgsFeatureSink.Flag] = QgsFeatureSink.Flags()) -> bool Adds all features from the specified iterator to the sink. Feature addition behavior is controlled by the specified flags.

Return type:

bool

Returns:

True if all features were added successfully, or False if any feature could not be added

Parameters:
virtual finalize(self)[source]

Finalizes the sink, flushing any buffered features to the destination.

Added in version 3.42.

virtual flushBuffer(self) bool[source]

Flushes any internal buffer which may exist in the sink, causing any buffered features to be added to the sink’s destination.

Return type:

bool

Returns:

False if any buffered features could not be added to the sink.

virtual lastError(self) str[source]

Returns the most recent error encountered by the sink, e.g. when a call to addFeatures() returns False.

Added in version 3.16.

Return type:

str