37 return QList<QgsRasterLayer *>();
39 QList<QgsRasterLayer *> layers;
42 if ( canUseLayer( l ) )
50 return QString::localeAwareCompare( a->
name(), b->name() ) < 0;
59 return QList<QgsVectorLayer *>();
61 QList<QgsVectorLayer *> layers;
64 if ( canUseLayer( l, geometryTypes ) )
72 return QString::localeAwareCompare( a->
name(), b->name() ) < 0;
81 return QList<QgsMapLayer *>();
83 QList<QgsMapLayer *> layers;
93 return QString::localeAwareCompare( a->
name(), b->name() ) < 0;
101 if ( !store ||
string.isEmpty() )
104 QList< QgsMapLayer * > layers = store->
mapLayers().values();
106 layers.erase( std::remove_if( layers.begin(), layers.end(), [](
QgsMapLayer * layer )
108 switch ( layer->type() )
111 return !canUseLayer( qobject_cast< QgsVectorLayer * >( layer ) );
113 return !canUseLayer( qobject_cast< QgsRasterLayer * >( layer ) );
122 auto isCompatibleType = [typeHint](
QgsMapLayer * l ) ->
bool 140 if ( isCompatibleType( l ) && l->id() == string )
145 if ( isCompatibleType( l ) && l->name() == string )
157 class ProjectionSettingRestorer
161 ProjectionSettingRestorer()
164 previousSetting = settings.
value( QStringLiteral(
"/Projections/defaultBehavior" ) ).toString();
165 settings.
setValue( QStringLiteral(
"/Projections/defaultBehavior" ), QStringLiteral(
"useProject" ) );
168 ~ProjectionSettingRestorer()
171 settings.
setValue( QStringLiteral(
"/Projections/defaultBehavior" ), previousSetting );
174 QString previousSetting;
178 QgsMapLayer *QgsProcessingUtils::loadMapLayerFromString(
const QString &
string,
LayerHint typeHint )
180 QStringList components =
string.split(
'|' );
181 if ( components.isEmpty() )
185 if ( QFileInfo::exists(
string ) )
186 fi = QFileInfo(
string );
187 else if ( QFileInfo::exists( components.at( 0 ) ) )
188 fi = QFileInfo( components.at( 0 ) );
193 ProjectionSettingRestorer restorer;
196 QString name = fi.baseName();
203 std::unique_ptr< QgsVectorLayer > layer(
new QgsVectorLayer(
string, name, QStringLiteral(
"ogr" ), options ) );
204 if ( layer->isValid() )
206 return layer.release();
213 std::unique_ptr< QgsRasterLayer > rasterLayer(
new QgsRasterLayer(
string, name, QStringLiteral(
"gdal" ), rasterOptions ) );
214 if ( rasterLayer->isValid() )
216 return rasterLayer.release();
224 if (
string.isEmpty() )
240 if ( !allowLoadingNewLayers )
243 layer = loadMapLayerFromString(
string, typeHint );
257 QVariant val = value;
258 bool selectedFeaturesOnly =
false;
273 if (
QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) ) )
283 else if ( !val.isValid() || val.toString().isEmpty() )
286 if (
QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( fallbackValue ) ) )
291 layerRef = fallbackValue.toString();
295 layerRef = val.toString();
298 if ( layerRef.isEmpty() )
305 if ( selectedFeaturesOnly )
315 bool QgsProcessingUtils::canUseLayer(
const QgsRasterLayer *layer )
317 return layer && layer->
isValid();
320 bool QgsProcessingUtils::canUseLayer(
const QgsVectorLayer *layer,
const QList<int> &sourceTypes )
322 return layer && layer->
isValid() &&
323 ( sourceTypes.isEmpty()
334 QString normalized = source;
335 normalized.replace(
'\\',
'/' );
336 return normalized.trimmed();
342 s.replace(
'\\', QStringLiteral(
"\\\\" ) );
343 s.replace(
'\n', QStringLiteral(
"\\n" ) );
344 s.replace(
'\r', QStringLiteral(
"\\r" ) );
345 s.replace(
'\t', QStringLiteral(
"\\t" ) );
346 s.replace(
'"', QStringLiteral(
"\\\"" ) );
347 s.replace(
'\'', QStringLiteral(
"\\\'" ) );
348 s = s.prepend(
'\'' ).append(
'\'' );
352 void QgsProcessingUtils::parseDestinationString( QString &destination, QString &providerKey, QString &uri, QString &layerName, QString &format, QMap<QString, QVariant> &options,
bool &useWriter, QString &extension )
355 QRegularExpression splitRx( QStringLiteral(
"^(.{3,}?):(.*)$" ) );
356 QRegularExpressionMatch match = splitRx.match( destination );
357 if ( match.hasMatch() )
359 providerKey = match.captured( 1 );
360 if ( providerKey == QStringLiteral(
"postgis" ) )
362 providerKey = QStringLiteral(
"postgres" );
364 uri = match.captured( 2 );
365 if ( providerKey == QLatin1String(
"ogr" ) )
370 if ( !dsUri.
table().isEmpty() )
372 layerName = dsUri.
table();
373 options.insert( QStringLiteral(
"layerName" ), layerName );
376 extension = QFileInfo( uri ).completeSuffix();
381 extension = QFileInfo( uri ).completeSuffix();
383 options.insert( QStringLiteral(
"update" ),
true );
390 providerKey = QStringLiteral(
"ogr" );
391 QRegularExpression splitRx( QStringLiteral(
"^(.*)\\.(.*?)$" ) );
392 QRegularExpressionMatch match = splitRx.match( destination );
393 if ( match.hasMatch() )
395 extension = match.captured( 2 );
399 if ( format.isEmpty() )
401 format = QStringLiteral(
"GPKG" );
402 destination = destination + QStringLiteral(
".gpkg" );
405 options.insert( QStringLiteral(
"driverName" ), format );
412 QVariantMap options = createOptions;
413 if ( !options.contains( QStringLiteral(
"fileEncoding" ) ) )
419 if ( destination.isEmpty() || destination.startsWith( QLatin1String(
"memory:" ) ) )
422 if ( destination.startsWith( QLatin1String(
"memory:" ) ) )
423 destination = destination.mid( 7 );
425 if ( destination.isEmpty() )
426 destination = QStringLiteral(
"output" );
430 if ( !layer || !layer->isValid() )
436 destination = layer->id();
439 std::unique_ptr< QgsProcessingFeatureSink > sink(
new QgsProcessingFeatureSink( layer->dataProvider(), destination, context ) );
442 return sink.release();
451 bool useWriter =
false;
452 parseDestinationString( destination, providerKey, uri, layerName, format, options, useWriter, extension );
455 if ( useWriter && providerKey == QLatin1String(
"ogr" ) )
459 QString finalFileName;
460 std::unique_ptr< QgsVectorFileWriter > writer = qgis::make_unique< QgsVectorFileWriter >( destination, options.value( QStringLiteral(
"fileEncoding" ) ).toString(), newFields, geometryType,
crs, format,
QgsVectorFileWriter::defaultDatasetOptions( format ),
463 if ( writer->hasError() )
465 throw QgsProcessingException( QObject::tr(
"Could not create layer %1: %2" ).arg( destination, writer->errorMessage() ) );
467 destination = finalFileName;
473 std::unique_ptr< QgsVectorLayerExporter > exporter(
new QgsVectorLayerExporter( uri, providerKey, newFields, geometryType, crs,
true, options, sinkFlags ) );
474 if ( exporter->errorCode() )
476 throw QgsProcessingException( QObject::tr(
"Could not create layer %1: %2" ).arg( destination, exporter->errorMessage() ) );
480 if ( !layerName.isEmpty() )
481 uri += QStringLiteral(
"|layername=%1" ).arg( layerName );
482 std::unique_ptr< QgsVectorLayer > layer(
new QgsVectorLayer( uri, destination, providerKey ) );
484 destination = layer->id();
495 *sink =
createFeatureSink( destination, context, fields, geometryType, crs, options );
535 if ( !input.isValid() )
536 return QStringLiteral(
"memory:%1" ).arg(
id.toString() );
552 QString res = input.toString();
553 if ( res.startsWith( QLatin1String(
"memory:" ) ) )
555 return res +
'_' +
id.toString();
561 int lastIndex = res.lastIndexOf(
'.' );
562 return res.left( lastIndex ) +
'_' +
id.toString() + res.mid( lastIndex );
569 static QString sFolder;
570 static QMutex sMutex;
572 if ( sFolder.isEmpty() )
574 QString subPath = QUuid::createUuid().toString().remove(
'-' ).remove(
'{' ).remove(
'}' );
575 sFolder = QDir::tempPath() + QStringLiteral(
"/processing_" ) + subPath;
576 if ( !QDir( sFolder ).exists() )
577 QDir().mkpath( sFolder );
585 QString subPath = QUuid::createUuid().toString().remove(
'-' ).remove(
'{' ).remove(
'}' );
587 if ( !QDir( path ).exists() )
590 tmpDir.mkdir( path );
597 auto getText = [map](
const QString & key )->QString
599 if ( map.contains( key ) )
600 return map.value( key ).toString();
604 QString s = QObject::tr(
"<html><body><h2>Algorithm description</h2>\n" );
605 s += QStringLiteral(
"<p>" ) + getText( QStringLiteral(
"ALG_DESC" ) ) + QStringLiteral(
"</p>\n" );
610 inputs += QStringLiteral(
"<h3>" ) + def->
description() + QStringLiteral(
"</h3>\n" );
611 inputs += QStringLiteral(
"<p>" ) + getText( def->
name() ) + QStringLiteral(
"</p>\n" );
613 if ( !inputs.isEmpty() )
614 s += QObject::tr(
"<h2>Input parameters</h2>\n" ) + inputs;
619 outputs += QStringLiteral(
"<h3>" ) + def->
description() + QStringLiteral(
"</h3>\n" );
620 outputs += QStringLiteral(
"<p>" ) + getText( def->
name() ) + QStringLiteral(
"</p>\n" );
622 if ( !outputs.isEmpty() )
623 s += QObject::tr(
"<h2>Outputs</h2>\n" ) + outputs;
625 s += QLatin1String(
"<br>" );
626 if ( !map.value( QStringLiteral(
"ALG_CREATOR" ) ).toString().isEmpty() )
627 s += QObject::tr(
"<p align=\"right\">Algorithm author: %1</p>" ).arg( getText( QStringLiteral(
"ALG_CREATOR" ) ) );
628 if ( !map.value( QStringLiteral(
"ALG_HELP_CREATOR" ) ).toString().isEmpty() )
629 s += QObject::tr(
"<p align=\"right\">Help author: %1</p>" ).arg( getText( QStringLiteral(
"ALG_HELP_CREATOR" ) ) );
630 if ( !map.value( QStringLiteral(
"ALG_VERSION" ) ).toString().isEmpty() )
631 s += QObject::tr(
"<p align=\"right\">Algorithm version: %1</p>" ).arg( getText( QStringLiteral(
"ALG_VERSION" ) ) );
633 s += QStringLiteral(
"</body></html>" );
639 bool requiresTranslation =
false;
643 requiresTranslation = requiresTranslation || selectedFeaturesOnly;
648 requiresTranslation = requiresTranslation || vl->
dataProvider()->
name() != QLatin1String(
"ogr" );
652 requiresTranslation = requiresTranslation || !vl->
subsetString().isEmpty();
656 requiresTranslation = requiresTranslation || vl->
source().startsWith( QLatin1String(
"/vsi" ) );
660 if ( !requiresTranslation )
663 if ( parts.contains( QStringLiteral(
"path" ) ) )
665 diskPath = parts.value( QStringLiteral(
"path" ) ).toString();
666 QFileInfo fi( diskPath );
667 requiresTranslation = !compatibleFormats.contains( fi.suffix(), Qt::CaseInsensitive );
671 const QString layerName = parts.value( QStringLiteral(
"layerName" ) ).toString();
672 requiresTranslation = requiresTranslation || ( !layerName.isEmpty() && layerName != fi.baseName() );
676 requiresTranslation =
true;
680 if ( requiresTranslation )
688 if ( selectedFeaturesOnly )
710 QSet< QString > usedNames;
713 usedNames.insert( f.name().toLower() );
718 if ( usedNames.contains( f.name().toLower() ) )
721 QString newName = f.name() +
'_' + QString::number( idx );
722 while ( usedNames.contains( newName.toLower() ) )
725 newName = f.name() +
'_' + QString::number( idx );
729 outFields.
append( newField );
730 usedNames.insert( newName.toLower() );
734 usedNames.insert( f.name().toLower() );
746 if ( !fieldNames.isEmpty() )
748 indices.reserve( fieldNames.count() );
749 for (
const QString &f : fieldNames )
753 indices.append( idx );
758 indices.reserve( fields.
count() );
759 for (
int i = 0; i < fields.
count(); ++i )
769 for (
int i : indices )
770 fieldsSubset.
append( fields.
at( i ) );
780 : mSource( originalSource )
781 , mOwnsSource( ownsOriginalSource )
784 : context.invalidGeometryCheck() )
785 , mInvalidGeometryCallback( context.invalidGeometryCallback() )
786 , mTransformErrorCallback( context.transformErrorCallback() )
817 return sourceAvailability;
891 return expressionContextScope;
900 , mContext( context )
901 , mSinkName( sinkName )
902 , mOwnsSink( ownsOriginalSink )
915 mContext.
feedback()->
reportError( QObject::tr(
"Feature could not be written to %1" ).arg( mSinkName ) );
923 mContext.
feedback()->
reportError( QObject::tr(
"%1 feature(s) could not be written to %2" ).arg( features.count() ).arg( mSinkName ) );
931 mContext.
feedback()->
reportError( QObject::tr(
"Features could not be written to %1" ).arg( mSinkName ) );
QgsProperty sink
Sink/layer definition.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Wrapper for iterator of features from vector data provider or vector layer.
bool isCanceled() const
Tells whether the operation has been canceled already.
virtual QVariant maximumValue(int fieldIndex) const
Returns the maximum value for an attribute column or an invalid variant in case of error...
~QgsProcessingFeatureSource() override
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
A rectangle specified with double values.
QgsWkbTypes::Type wkbType() const override
Returns the geometry type for features returned by this source.
Base class for all map layer types.
static QgsRectangle combineLayerExtents(const QList< QgsMapLayer * > &layers, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Combines the extent of several map layers.
bool loadDefaultStyle
Sets to true if the default layer style should be loaded.
QSet< QgsFeatureId > QgsFeatureIds
QgsFeatureRequest & setInvalidGeometryCallback(const std::function< void(const QgsFeature &)> &callback)
Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is s...
bool isValid() const
Returns the status of the layer.
Base class for providing feedback from a processing algorithm.
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
virtual QgsFields fields() const =0
Returns the fields associated with features in the source.
QgsProcessingParameterDefinitions parameterDefinitions() const
Returns an ordered list of parameter definitions utilized by the algorithm.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm...
static void createFeatureSinkPython(QgsFeatureSink **sink, QString &destination, QgsProcessingContext &context, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs, const QVariantMap &createOptions=QVariantMap()) SIP_THROW(QgsProcessingException)
Creates a feature sink ready for adding features.
A simple feature sink which proxies feature addition on to another feature sink.
QgsFeatureRequest & setInvalidGeometryCheck(InvalidGeometryCheck check)
Sets invalid geometry checking behavior.
QgsProcessingFeatureSource(QgsFeatureSource *originalSource, const QgsProcessingContext &context, bool ownsOriginalSource=false)
Constructor for QgsProcessingFeatureSource, accepting an original feature source originalSource and p...
This class is a composition of two QSettings instances:
FeatureAvailability
Possible return value for hasFeatures() to determine if a source is empty.
QString name() const
Returns the name of the parameter.
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Setting options for loading vector layers.
LayerHint
Layer type hints.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QList< QgsFeature > QgsFeatureList
Handles storage of information regarding WKB types and their properties.
QgsFeatureIds allFeatureIds() const override
Returns a list of all feature IDs for features present in the source.
virtual QgsWkbTypes::Type wkbType() const =0
Returns the geometry type for features returned by this source.
An interface for objects which accept features via addFeature(s) methods.
#define Q_NOWARN_DEPRECATED_PUSH
static QList< QgsRasterLayer * > compatibleRasterLayers(QgsProject *project, bool sort=true)
Returns a list of raster layers from a project which are compatible with the processing framework...
static QString stringToPythonLiteral(const QString &string)
Converts a string to a Python string literal.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource, modifying results according to the settings in a QgsProcessingContext.
Container of fields for a vector layer.
void setName(const QString &name)
Set the field name.
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=nullptr) override
Adds a list of features to the sink.
QString source() const
Returns the source for the layer.
virtual QgsFeatureIds allFeatureIds() const
Returns a list of all feature IDs for features present in the source.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Returns the components (e.g.
static QString driverForExtension(const QString &extension)
Returns the OGR driver name for a specified file extension.
static QList< QgsVectorLayer * > compatibleVectorLayers(QgsProject *project, const QList< int > &sourceTypes=QList< int >(), bool sort=true)
Returns a list of vector layers from a project which are compatible with the processing framework...
A convenience class for writing vector files to disk.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsExpressionContextScope * createExpressionContextScope() const
Returns an expression context scope suitable for this source.
const QgsCoordinateReferenceSystem & crs
QVariant maximumValue(int fieldIndex) const override
Returns the maximum value for an attribute column or an invalid variant in case of error...
static QString convertToCompatibleFormat(const QgsVectorLayer *layer, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Converts a source vector layer to a file path to a vector layer of compatible format.
QgsRectangle sourceExtent() const override
Returns the extent of all geometries from the source.
QString description() const
Returns the description for the output.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
static QString normalizeLayerSource(const QString &source)
Normalizes a layer source string for safe comparison across different operating system environments...
Abstract base class for processing algorithms.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
QgsMapLayerStore * layerStore()
Returns a pointer to the project's internal layer store.
virtual QString name() const =0
Returns a provider name.
bool selectedFeaturesOnly
True if only selected features in the source should be used by algorithms.
QString database() const
Returns the database.
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=nullptr) override
Adds a list of features to the sink.
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const override
Returns the set of unique values contained within the specified fieldIndex from this source...
static QgsFeatureSink * createFeatureSink(QString &destination, QgsProcessingContext &context, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs, const QVariantMap &createOptions=QVariantMap(), QgsFeatureSink::SinkFlags sinkFlags=nullptr)
Creates a feature sink ready for adding features.
virtual QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const
Returns the set of unique values contained within the specified fieldIndex from this source...
QgsProcessingFeedback * feedback()
Returns the associated feedback object.
QString defaultEncoding() const
Returns the default encoding to use for newly created files.
static QList< int > fieldNamesToIndices(const QStringList &fieldNames, const QgsFields &fields)
Returns a list of field indices parsed from the given list of field names.
Type
The WKB type describes the number of dimensions a geometry has.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QgsFields fields() const override
Returns the fields associated with features in the source.
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QgsMapLayerStore * temporaryLayerStore()
Returns a reference to the layer store used for storing temporary layers during algorithm execution...
QgsProperty source
Source definition.
virtual QgsRectangle extent() const
Returns the extent of the layer.
static QStringList defaultLayerOptions(const QString &driverName)
Returns a list of the default layer options for a specified driver.
QVariant minimumValue(int fieldIndex) const override
Returns the minimum value for an attribute column or an invalid variant in case of error...
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB)
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
static QString stringToSafeFilename(const QString &string)
Converts a string to a safe filename, replacing characters which are not safe for filenames with an '...
bool loadDefaultStyle
Sets to true if the default layer style should be loaded.
QgsCoordinateReferenceSystem sourceCrs() const override
Returns the coordinate reference system for features in the source.
QMap< QString, QgsMapLayer * > mapLayers() const
Returns a map of all layers by layer ID.
virtual QgsRectangle sourceExtent() const
Returns the extent of all geometries from the source.
~QgsProcessingFeatureSink() override
There are certainly no features available in this source.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Custom exception class for processing related exceptions.
static QList< QgsMapLayer * > compatibleLayers(QgsProject *project, bool sort=true)
Returns a list of map layers from a project which are compatible with the processing framework...
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request, Flags flags) const
Returns an iterator for the features in the source, respecting the supplied feature flags...
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false) ...
Reads and writes project states.
int count() const
Returns number of items.
No invalid geometry checking.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=nullptr) override
Adds a single feature to the sink.
Encapsulate a field in an attribute table or data source.
QString description() const
Returns the description for the parameter.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsProcessingFeatureSource * variantToSource(const QVariant &value, QgsProcessingContext &context, const QVariant &fallbackValue=QVariant())
Converts a variant value to a new feature source.
A store for object properties.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsFeatureRequest & setTransformErrorCallback(const std::function< void(const QgsFeature &)> &callback)
Sets a callback function to use when encountering a transform error when iterating features and a des...
A convenience class for exporting vector layers to a destination data provider.
static QString tempFolder()
Returns a session specific processing temporary folder for use in processing algorithms.
virtual QgsCoordinateReferenceSystem sourceCrs() const =0
Returns the coordinate reference system for features in the source.
Encapsulates settings relating to a feature source input to a processing algorithm.
static QString generateTempFilename(const QString &basename)
Returns a temporary filename for a given file, putting it into a temporary folder (creating that fold...
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
Base class for the definition of processing outputs.
#define Q_NOWARN_DEPRECATED_POP
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QgsProxyFeatureSink subclass which reports feature addition errors to a QgsProcessingContext.
static QString formatHelpMapAsHtml(const QVariantMap &map, const QgsProcessingAlgorithm *algorithm)
Returns a HTML formatted version of the help text encoded in a variant map for a specified algorithm...
static QgsFields indicesToFields(const QList< int > &indices, const QgsFields &fields)
Returns a subset of fields based on the indices of desired fields.
virtual QgsExpressionContextScope * createExpressionContextScope() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsFeatureSource subclass for the selected features from a QgsVectorLayer.
virtual QVariant minimumValue(int fieldIndex) const
Returns the minimum value for an attribute column or an invalid variant in case of error...
QgsMapLayer * addMapLayer(QgsMapLayer *layer, bool takeOwnership=true)
Add a layer to the store.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
Abstract interface for generating an expression context scope.
An interface for objects which provide features via a getFeatures method.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QgsFeatureSource::FeatureAvailability hasFeatures() const override
Determines if there are any features available in the source.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm's parent class) implements the new pure virtual createInstance(self) call
static QVariant generateIteratingDestination(const QVariant &input, const QVariant &id, QgsProcessingContext &context)
Converts an input parameter value for use in source iterating mode, where one individual sink is crea...
QString sourceName() const override
Returns a friendly display name for the source.
static QStringList defaultDatasetOptions(const QString &driverName)
Returns a list of the default dataset options for a specified driver.
This class represents a coordinate reference system (CRS).
Base class for the definition of processing parameters.
QgsFeatureIterator getSelectedFeatures(QgsFeatureRequest request=QgsFeatureRequest()) const
Returns an iterator of the selected features.
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Query the layer for features specified in request.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=nullptr) override
Adds a single feature to the sink.
Custom exception class for Coordinate Reference System related exceptions.
static QgsVectorLayer * createMemoryLayer(const QString &name, const QgsFields &fields, QgsWkbTypes::Type geometryType=QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Creates a new memory layer using the specified parameters.
There may be features available in this source.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider.
QString name() const
Returns the name of the output.
bool nextFeature(QgsFeature &f)
QgsFeatureSink * destinationSink()
Returns the destination QgsFeatureSink which the proxy will forward features to.
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, LayerHint typeHint=UnknownType)
Interprets a string as a map layer within the supplied context.
virtual QString sourceName() const =0
Returns a friendly display name for the source.
long featureCount() const override
Returns the number of features contained in the source, or -1 if the feature count is unknown...
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
Represents a vector layer which manages a vector based data sets.
QString table() const
Returns the table.
Contains information about the context in which a processing algorithm is executed.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Any vector layer with geometry.
virtual FeatureAvailability hasFeatures() const
Determines if there are any features available in the source.
Setting options for loading raster layers.
QgsCoordinateReferenceSystem crs
QgsProcessingOutputDefinitions outputDefinitions() const
Returns an ordered list of output definitions utilized by the algorithm.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
Returns an iterator for the features in the source.
virtual long featureCount() const =0
Returns the number of features contained in the source, or -1 if the feature count is unknown...
QgsProcessingFeatureSink(QgsFeatureSink *originalSink, const QString &sinkName, QgsProcessingContext &context, bool ownsOriginalSink=false)
Constructor for QgsProcessingFeatureSink, accepting an original feature sink originalSink and process...