39 return QList<QgsRasterLayer *>();
41 QList<QgsRasterLayer *> layers;
46 if ( canUseLayer( l ) )
54 return QString::localeAwareCompare( a->
name(), b->name() ) < 0;
63 return QList<QgsVectorLayer *>();
65 QList<QgsVectorLayer *> layers;
69 if ( canUseLayer( l, geometryTypes ) )
77 return QString::localeAwareCompare( a->
name(), b->name() ) < 0;
86 return QList<QgsMeshLayer *>();
88 QList<QgsMeshLayer *> layers;
92 if ( canUseLayer( l ) )
100 return QString::localeAwareCompare( a->
name(), b->name() ) < 0;
109 return QList<QgsMapLayer *>();
111 QList<QgsMapLayer *> layers;
129 return QString::localeAwareCompare( a->
name(), b->name() ) < 0;
137 if ( !store ||
string.isEmpty() )
140 QList< QgsMapLayer * > layers = store->
mapLayers().values();
142 layers.erase( std::remove_if( layers.begin(), layers.end(), [](
QgsMapLayer * layer )
144 switch ( layer->type() )
147 return !canUseLayer( qobject_cast< QgsVectorLayer * >( layer ) );
149 return !canUseLayer( qobject_cast< QgsRasterLayer * >( layer ) );
153 return !canUseLayer( qobject_cast< QgsMeshLayer * >( layer ) );
158 auto isCompatibleType = [typeHint](
QgsMapLayer * l ) ->
bool 179 if ( isCompatibleType( l ) && l->id() == string )
184 if ( isCompatibleType( l ) && l->name() == string )
196 class ProjectionSettingRestorer
200 ProjectionSettingRestorer()
203 previousSetting = settings.
value( QStringLiteral(
"/Projections/defaultBehavior" ) ).toString();
204 settings.
setValue( QStringLiteral(
"/Projections/defaultBehavior" ), QStringLiteral(
"useProject" ) );
207 ~ProjectionSettingRestorer()
210 settings.
setValue( QStringLiteral(
"/Projections/defaultBehavior" ), previousSetting );
213 QString previousSetting;
219 QStringList components =
string.split(
'|' );
220 if ( components.isEmpty() )
224 if ( QFileInfo::exists(
string ) )
225 fi = QFileInfo(
string );
226 else if ( QFileInfo::exists( components.at( 0 ) ) )
227 fi = QFileInfo( components.at( 0 ) );
232 ProjectionSettingRestorer restorer;
235 QString name = fi.baseName();
241 options.loadDefaultStyle =
false;
242 std::unique_ptr< QgsVectorLayer > layer = qgis::make_unique<QgsVectorLayer>( string, name, QStringLiteral(
"ogr" ), options );
243 if ( layer->isValid() )
245 return layer.release();
252 std::unique_ptr< QgsRasterLayer > rasterLayer(
new QgsRasterLayer(
string, name, QStringLiteral(
"gdal" ), rasterOptions ) );
253 if ( rasterLayer->isValid() )
255 return rasterLayer.release();
261 std::unique_ptr< QgsMeshLayer > meshLayer(
new QgsMeshLayer(
string, name, QStringLiteral(
"mdal" ), meshOptions ) );
262 if ( meshLayer->isValid() )
264 return meshLayer.release();
272 if (
string.isEmpty() )
288 if ( !allowLoadingNewLayers )
291 layer = loadMapLayerFromString(
string, context.
transformContext(), typeHint );
305 QVariant val = value;
306 bool selectedFeaturesOnly =
false;
321 if (
QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( val ) ) )
331 else if ( !val.isValid() || val.toString().isEmpty() )
334 if (
QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( fallbackValue ) ) )
339 layerRef = fallbackValue.toString();
343 layerRef = val.toString();
346 if ( layerRef.isEmpty() )
353 if ( selectedFeaturesOnly )
363 bool QgsProcessingUtils::canUseLayer(
const QgsMeshLayer *layer )
368 bool QgsProcessingUtils::canUseLayer(
const QgsRasterLayer *layer )
370 return layer && layer->
isValid();
373 bool QgsProcessingUtils::canUseLayer(
const QgsVectorLayer *layer,
const QList<int> &sourceTypes )
375 return layer && layer->
isValid() &&
376 ( sourceTypes.isEmpty()
387 QString normalized = source;
388 normalized.replace(
'\\',
'/' );
389 return normalized.trimmed();
394 if ( !value.isValid() )
395 return QStringLiteral(
"None" );
398 return QStringLiteral(
"QgsProperty.fromExpression('%1')" ).arg( value.value<
QgsProperty >().
asExpression() );
402 return QStringLiteral(
"QgsCoordinateReferenceSystem()" );
436 switch ( value.type() )
439 return value.toBool() ? QStringLiteral(
"True" ) : QStringLiteral(
"False" );
441 case QVariant::Double:
442 return QString::number( value.toDouble() );
446 return QString::number( value.toInt() );
448 case QVariant::LongLong:
449 case QVariant::ULongLong:
450 return QString::number( value.toLongLong() );
455 const QVariantList vl = value.toList();
456 for (
const QVariant &v : vl )
460 return parts.join(
',' ).prepend(
'[' ).append(
']' );
473 s.replace(
'\\', QStringLiteral(
"\\\\" ) );
474 s.replace(
'\n', QStringLiteral(
"\\n" ) );
475 s.replace(
'\r', QStringLiteral(
"\\r" ) );
476 s.replace(
'\t', QStringLiteral(
"\\t" ) );
477 s.replace(
'"', QStringLiteral(
"\\\"" ) );
478 s.replace(
'\'', QStringLiteral(
"\\\'" ) );
479 s = s.prepend(
'\'' ).append(
'\'' );
483 void QgsProcessingUtils::parseDestinationString( QString &destination, QString &providerKey, QString &uri, QString &layerName, QString &format, QMap<QString, QVariant> &options,
bool &useWriter, QString &extension )
486 QRegularExpression splitRx( QStringLiteral(
"^(.{3,}?):(.*)$" ) );
487 QRegularExpressionMatch match = splitRx.match( destination );
488 if ( match.hasMatch() )
490 providerKey = match.captured( 1 );
491 if ( providerKey == QStringLiteral(
"postgis" ) )
493 providerKey = QStringLiteral(
"postgres" );
495 uri = match.captured( 2 );
496 if ( providerKey == QLatin1String(
"ogr" ) )
501 if ( !dsUri.
table().isEmpty() )
503 layerName = dsUri.
table();
504 options.insert( QStringLiteral(
"layerName" ), layerName );
507 extension = QFileInfo( uri ).completeSuffix();
512 extension = QFileInfo( uri ).completeSuffix();
514 options.insert( QStringLiteral(
"update" ),
true );
521 providerKey = QStringLiteral(
"ogr" );
522 QRegularExpression splitRx( QStringLiteral(
"^(.*)\\.(.*?)$" ) );
523 QRegularExpressionMatch match = splitRx.match( destination );
524 if ( match.hasMatch() )
526 extension = match.captured( 2 );
530 if ( format.isEmpty() )
532 format = QStringLiteral(
"GPKG" );
533 destination = destination + QStringLiteral(
".gpkg" );
536 options.insert( QStringLiteral(
"driverName" ), format );
543 QVariantMap options = createOptions;
544 if ( !options.contains( QStringLiteral(
"fileEncoding" ) ) )
550 if ( destination.isEmpty() || destination.startsWith( QLatin1String(
"memory:" ) ) )
553 if ( destination.startsWith( QLatin1String(
"memory:" ) ) )
554 destination = destination.mid( 7 );
556 if ( destination.isEmpty() )
557 destination = QStringLiteral(
"output" );
561 if ( !layer || !layer->isValid() )
567 destination = layer->id();
570 std::unique_ptr< QgsProcessingFeatureSink > sink(
new QgsProcessingFeatureSink( layer->dataProvider(), destination, context ) );
573 return sink.release();
582 bool useWriter =
false;
583 parseDestinationString( destination, providerKey, uri, layerName, format, options, useWriter, extension );
586 if ( useWriter && providerKey == QLatin1String(
"ogr" ) )
590 QString finalFileName;
591 std::unique_ptr< QgsVectorFileWriter > writer = qgis::make_unique< QgsVectorFileWriter >( destination, options.value( QStringLiteral(
"fileEncoding" ) ).toString(), newFields, geometryType,
crs, format,
QgsVectorFileWriter::defaultDatasetOptions( format ),
594 if ( writer->hasError() )
596 throw QgsProcessingException( QObject::tr(
"Could not create layer %1: %2" ).arg( destination, writer->errorMessage() ) );
598 destination = finalFileName;
605 std::unique_ptr< QgsVectorLayerExporter > exporter = qgis::make_unique<QgsVectorLayerExporter>( uri, providerKey, newFields, geometryType,
crs,
true, options, sinkFlags );
606 if ( exporter->errorCode() )
608 throw QgsProcessingException( QObject::tr(
"Could not create layer %1: %2" ).arg( destination, exporter->errorMessage() ) );
612 if ( !layerName.isEmpty() )
613 uri += QStringLiteral(
"|layername=%1" ).arg( layerName );
614 std::unique_ptr< QgsVectorLayer > layer = qgis::make_unique<QgsVectorLayer>( uri, destination, providerKey, layerOptions );
616 destination = layer->
id();
626 *sink =
createFeatureSink( destination, context, fields, geometryType, crs, options );
671 if ( !input.isValid() )
672 return QStringLiteral(
"memory:%1" ).arg(
id.toString() );
688 QString res = input.toString();
694 else if ( res.startsWith( QLatin1String(
"memory:" ) ) )
696 return res +
'_' +
id.toString();
702 int lastIndex = res.lastIndexOf(
'.' );
703 return res.left( lastIndex ) +
'_' +
id.toString() + res.mid( lastIndex );
710 static QString sFolder;
711 static QMutex sMutex;
713 if ( sFolder.isEmpty() )
715 QString subPath = QUuid::createUuid().toString().remove(
'-' ).remove(
'{' ).remove(
'}' );
716 sFolder = QDir::tempPath() + QStringLiteral(
"/processing_" ) + subPath;
717 if ( !QDir( sFolder ).exists() )
718 QDir().mkpath( sFolder );
726 QString subPath = QUuid::createUuid().toString().remove(
'-' ).remove(
'{' ).remove(
'}' );
728 if ( !QDir( path ).exists() )
731 tmpDir.mkdir( path );
738 auto getText = [map](
const QString & key )->QString
740 if ( map.contains( key ) )
741 return map.value( key ).toString();
745 QString s = QObject::tr(
"<html><body><h2>Algorithm description</h2>\n" );
746 s += QStringLiteral(
"<p>" ) + getText( QStringLiteral(
"ALG_DESC" ) ) + QStringLiteral(
"</p>\n" );
753 inputs += QStringLiteral(
"<h3>" ) + def->description() + QStringLiteral(
"</h3>\n" );
754 inputs += QStringLiteral(
"<p>" ) + getText( def->name() ) + QStringLiteral(
"</p>\n" );
756 if ( !inputs.isEmpty() )
757 s += QObject::tr(
"<h2>Input parameters</h2>\n" ) + inputs;
763 outputs += QStringLiteral(
"<h3>" ) + def->description() + QStringLiteral(
"</h3>\n" );
764 outputs += QStringLiteral(
"<p>" ) + getText( def->name() ) + QStringLiteral(
"</p>\n" );
766 if ( !outputs.isEmpty() )
767 s += QObject::tr(
"<h2>Outputs</h2>\n" ) + outputs;
769 s += QLatin1String(
"<br>" );
770 if ( !map.value( QStringLiteral(
"ALG_CREATOR" ) ).toString().isEmpty() )
771 s += QObject::tr(
"<p align=\"right\">Algorithm author: %1</p>" ).arg( getText( QStringLiteral(
"ALG_CREATOR" ) ) );
772 if ( !map.value( QStringLiteral(
"ALG_HELP_CREATOR" ) ).toString().isEmpty() )
773 s += QObject::tr(
"<p align=\"right\">Help author: %1</p>" ).arg( getText( QStringLiteral(
"ALG_HELP_CREATOR" ) ) );
774 if ( !map.value( QStringLiteral(
"ALG_VERSION" ) ).toString().isEmpty() )
775 s += QObject::tr(
"<p align=\"right\">Algorithm version: %1</p>" ).arg( getText( QStringLiteral(
"ALG_VERSION" ) ) );
777 s += QStringLiteral(
"</body></html>" );
783 bool requiresTranslation =
false;
787 requiresTranslation = requiresTranslation || selectedFeaturesOnly;
792 requiresTranslation = requiresTranslation || vl->
dataProvider()->
name() != QLatin1String(
"ogr" );
796 requiresTranslation = requiresTranslation || !vl->
subsetString().isEmpty();
800 if ( !requiresTranslation )
803 if ( parts.contains( QStringLiteral(
"path" ) ) )
805 diskPath = parts.value( QStringLiteral(
"path" ) ).toString();
806 QFileInfo fi( diskPath );
807 requiresTranslation = !compatibleFormats.contains( fi.suffix(), Qt::CaseInsensitive );
811 const QString layerName = parts.value( QStringLiteral(
"layerName" ) ).toString();
812 requiresTranslation = requiresTranslation || ( !layerName.isEmpty() && layerName != fi.baseName() );
816 requiresTranslation =
true;
820 if ( requiresTranslation )
828 if ( selectedFeaturesOnly )
850 QSet< QString > usedNames;
853 usedNames.insert( f.name().toLower() );
859 newField.
setName( fieldsBPrefix + f.name() );
860 if ( usedNames.contains( newField.
name().toLower() ) )
863 QString newName = newField.
name() +
'_' + QString::number( idx );
864 while ( usedNames.contains( newName.toLower() ) )
867 newName = newField.
name() +
'_' + QString::number( idx );
870 outFields.
append( newField );
874 outFields.
append( newField );
876 usedNames.insert( newField.
name() );
886 if ( !fieldNames.isEmpty() )
888 indices.reserve( fieldNames.count() );
889 for (
const QString &f : fieldNames )
893 indices.append( idx );
898 indices.reserve( fields.
count() );
899 for (
int i = 0; i < fields.
count(); ++i )
909 for (
int i : indices )
910 fieldsSubset.
append( fields.
at( i ) );
919 : mSource( originalSource )
920 , mOwnsSource( ownsOriginalSource )
923 : context.invalidGeometryCheck() )
924 , mInvalidGeometryCallback( context.invalidGeometryCallback() )
925 , mTransformErrorCallback( context.transformErrorCallback() )
956 return sourceAvailability;
1030 return expressionContextScope;
1039 , mContext( context )
1040 , mSinkName( sinkName )
1041 , mOwnsSink( ownsOriginalSink )
1054 mContext.
feedback()->
reportError( QObject::tr(
"Feature could not be written to %1" ).arg( mSinkName ) );
1062 mContext.
feedback()->
reportError( QObject::tr(
"%1 feature(s) could not be written to %2" ).arg( features.count() ).arg( mSinkName ) );
1070 mContext.
feedback()->
reportError( QObject::tr(
"Features could not be written to %1" ).arg( mSinkName ) );
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QgsProperty sink
Sink/layer definition.
Wrapper for iterator of features from vector data provider or vector layer.
~QgsProcessingFeatureSource() override
virtual QgsRectangle sourceExtent() const
Returns the extent of all geometries from the source.
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.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
Base class for all map layer types.
QString table() const
Returns the table name stored in the URI.
QSet< QgsFeatureId > QgsFeatureIds
static QgsRectangle combineLayerExtents(const QList< QgsMapLayer *> &layers, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context)
Combines the extent of several map layers.
QgsFeatureRequest & setInvalidGeometryCallback(const std::function< void(const QgsFeature &)> &callback)
Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is s...
Base class for providing feedback from a processing algorithm.
QgsProcessingParameterDefinitions parameterDefinitions() const
Returns an ordered list of parameter definitions utilized by the 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.
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.
LayerHint
Layer type hints.
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Setting options for loading vector layers.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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.
A class to represent a 2D point.
A QgsPointXY with associated coordinate reference system.
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.
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.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
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.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QString driverForExtension(const QString &extension)
Returns the OGR driver name for a specified file extension.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request, Flags flags) const
Returns an iterator for the features in the source, respecting the supplied feature flags...
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...
Setting options for loading mesh layers.
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...
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...
bool isValid() const
Returns the status of the layer.
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.
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.
int count() const
Returns number of items.
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.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
bool selectedFeaturesOnly
true if only selected features in the source should be used by algorithms.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
static QgsMapLayer * mapLayerFromString(const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers=true, QgsProcessingUtils::LayerHint typeHint=QgsProcessingUtils::LayerHint::UnknownType)
Interprets a string as a map layer within the supplied context.
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=nullptr) override
Adds a list of features to the sink.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set...
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.
QgsProcessingFeedback * feedback()
Returns the associated feedback object.
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.
virtual QVariant minimumValue(int fieldIndex) const
Returns the minimum value for an attribute column or an invalid variant in case of error...
QgsFields fields() const override
Returns the fields associated with features in the source.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
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.
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...
QgsFeatureIterator getSelectedFeatures(QgsFeatureRequest request=QgsFeatureRequest()) const
Returns an iterator of the selected features.
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.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
~QgsProcessingFeatureSink() override
There are certainly no features available in this source.
static const QString TEMPORARY_OUTPUT
Constant used to indicate that a Processing algorithm output should be a temporary layer/file...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Custom exception class for processing related exceptions.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
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...
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.
No invalid geometry checking.
A QgsRectangle with associated coordinate reference system.
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.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Contains information about the context in which a coordinate transform is executed.
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.
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
virtual QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const
Returns the set of unique values contained within the specified fieldIndex from this source...
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
static QList< QgsMeshLayer * > compatibleMeshLayers(QgsProject *project, bool sort=true)
Returns a list of mesh layers from a project which are compatible with the processing framework...
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...
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.
QgsExpressionContextScope * createExpressionContextScope() const
Returns an expression context scope suitable for this source.
Encapsulates settings relating to a feature source input to a processing algorithm.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QgsProcessingOutputDefinitions outputDefinitions() const
Returns an ordered list of output definitions utilized by the algorithm.
static QString generateTempFilename(const QString &basename)
Returns a temporary filename for a given file, putting it into a temporary folder (creating that fold...
double xMaximum() const
Returns the x maximum value (right side of rectangle).
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.
static QString variantToPythonLiteral(const QVariant &value)
Converts a variant to a Python literal.
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.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
virtual QgsExpressionContextScope * createExpressionContextScope() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QMap< QString, QgsMapLayer * > mapLayers() const
Returns a map of all layers by layer ID.
QgsFeatureSource subclass for the selected features from a QgsVectorLayer.
QgsMapLayer * addMapLayer(QgsMapLayer *layer, bool takeOwnership=true)
Add a layer to the store.
bool isCanceled() const
Tells whether the operation has been canceled already.
Abstract interface for generating an expression context scope.
QString defaultEncoding() const
Returns the default encoding to use for newly created files.
An interface for objects which provide features via a getFeatures method.
QString source() const
Returns the source for the layer.
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.
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.
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
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.
virtual QVariant maximumValue(int fieldIndex) const
Returns the maximum value for an attribute column or an invalid variant in case of error...
There may be features available in this source.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
bool nextFeature(QgsFeature &f)
QgsFeatureSink * destinationSink()
Returns the destination QgsFeatureSink which the proxy will forward features to.
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix=QString())
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
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 RDBMS data source URI (e.g.
Represents a vector layer which manages a vector based data sets.
virtual QgsFeatureIds allFeatureIds() const
Returns a list of all feature IDs for features present in the source.
Contains information about the context in which a processing algorithm is executed.
virtual FeatureAvailability hasFeatures() const
Determines if there are any features available in the source.
QString database() const
Returns the database name stored in the URI.
Any vector layer with geometry.
QString authid() const
Returns the authority identifier for the CRS.
Setting options for loading raster layers.
QgsCoordinateReferenceSystem crs
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...
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QgsProcessingFeatureSink(QgsFeatureSink *originalSink, const QString &sinkName, QgsProcessingContext &context, bool ownsOriginalSink=false)
Constructor for QgsProcessingFeatureSink, accepting an original feature sink originalSink and process...