QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
28 auto callback = [ = ](
const QgsFeature & feature )
31 mFeedback->reportError( QObject::tr(
"Encountered a transform error when reprojecting feature with id %1." ).arg( feature.id() ) );
33 mTransformErrorCallback = callback;
38 for (
auto it = mLayersToLoadOnCompletion.constBegin(); it != mLayersToLoadOnCompletion.constEnd(); ++it )
40 delete it.value().postProcessor();
46 for (
auto it = mLayersToLoadOnCompletion.constBegin(); it != mLayersToLoadOnCompletion.constEnd(); ++it )
48 if ( !layers.contains( it.key() ) || layers.value( it.key() ).postProcessor() != it.value().postProcessor() )
49 delete it.value().postProcessor();
51 mLayersToLoadOnCompletion = layers;
56 if ( mLayersToLoadOnCompletion.contains( layer ) && mLayersToLoadOnCompletion.value( layer ).postProcessor() != details.
postProcessor() )
57 delete mLayersToLoadOnCompletion.value( layer ).postProcessor();
59 mLayersToLoadOnCompletion.insert( layer, details );
64 mInvalidGeometryCheck = check;
65 mUseDefaultInvalidGeometryCallback =
true;
71 if ( mUseDefaultInvalidGeometryCallback )
74 return mInvalidGeometryCallback;
79 const QString sourceName = source ? source->
sourceName() : QString();
84 auto callback = [sourceName](
const QgsFeature & feature )
86 if ( !sourceName.isEmpty() )
87 throw QgsProcessingException( QObject::tr(
"Feature (%1) from “%2” has invalid geometry. Please fix the geometry or change the “Invalid features filtering” option for this input or globally in Processing settings." ).arg( feature.id() ).arg( sourceName ) );
89 throw QgsProcessingException( QObject::tr(
"Feature (%1) has invalid geometry. Please fix the geometry or change the “Invalid features filtering” option for input layers or globally in Processing settings." ).arg( feature.id() ) );
96 auto callback = [ = ](
const QgsFeature & feature )
100 if ( !sourceName.isEmpty() )
101 mFeedback->reportError( QObject::tr(
"Feature (%1) from “%2” has invalid geometry and has been skipped. Please fix the geometry or change the “Invalid features filtering” option for this input or globally in Processing settings." ).arg( feature.id() ).arg( sourceName ) );
103 mFeedback->reportError( QObject::tr(
"Feature (%1) has invalid geometry and has been skipped. Please fix the geometry or change the “Invalid features filtering” option for input layers or globally in Processing settings." ).arg( feature.id() ) );
118 context.mLayersToLoadOnCompletion.clear();
149 if ( !mEllipsoid.isEmpty() )
150 res.insert( QStringLiteral(
"ellipsoid" ), mEllipsoid );
152 res.insert( QStringLiteral(
"project_path" ), mProject->fileName() );
164 if ( !mEllipsoid.isEmpty() )
165 res << QStringLiteral(
"--ellipsoid=%1" ).arg( mEllipsoid );
169 res << QStringLiteral(
"--project_path=%1" ).arg( mProject->fileName() );
177 return mCurrentTimeRange;
197 return mDistanceUnit;
202 mDistanceUnit = unit;
217 return mPostProcessor;
222 if ( mPostProcessor && mPostProcessor != processor )
223 delete mPostProcessor;
225 mPostProcessor = processor;
236 if ( ( !forceName && preferFilenameAsLayerName && !layer->
isTemporary() ) || name.isEmpty() )
239 const QString layerName = sourceParts.value( QStringLiteral(
"layerName" ) ).toString();
241 if ( !layerName.isEmpty() )
245 const QString path = sourceParts.value( QStringLiteral(
"path" ) ).toString();
246 if ( !path.isEmpty() )
248 const QFileInfo fi( path );
249 layer->
setName( fi.baseName() );
251 else if ( !name.isEmpty() )
void transferLayersFromStore(QgsMapLayerStore *other)
Transfers all the map layers contained within another map layer store and adds them to this store.
QStringList asQgisProcessArguments(QgsProcessingContext::ProcessArgumentFlags flags=QgsProcessingContext::ProcessArgumentFlags()) const
Returns list of the equivalent qgis_process arguments representing the settings from the context.
void setPostProcessor(QgsProcessingLayerPostProcessorInterface *processor)
Sets the layer post-processor.
@ GeometryAbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
QgsUnitTypes::DistanceUnit distanceUnit() const
Returns the distance unit to use for distance calculations.
@ IncludeProjectPath
Include the associated project path argument.
@ DistanceUnknownUnit
Unknown distance unit.
std::function< void(const QgsFeature &) > defaultInvalidGeometryCallbackForCheck(QgsFeatureRequest::InvalidGeometryCheck check, QgsFeatureSource *source=nullptr) const
Returns the default callback function to use for a particular invalid geometry check.
QgsMapLayer * takeResultLayer(const QString &id)
Takes the result map layer with matching id from the context and transfers ownership of it back to th...
void setLayersToLoadOnCompletion(const QMap< QString, QgsProcessingContext::LayerDetails > &layers)
Sets the map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion...
An interface for objects which provide features via a getFeatures method.
LogLevel
Logging level for algorithms to use when pushing feedback messages.
InvalidGeometryCheck
Handling of features with invalid geometries.
@ GeometrySkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
DistanceUnit
Units of distance.
QgsMapLayer * mapLayer(const QString &id) const
Retrieve a pointer to a layer by layer id.
void setLogLevel(LogLevel level)
Sets the logging level for algorithms to use when pushing feedback messages to users.
QString providerType() const
Returns the provider type (provider key) for this layer.
void setOutputLayerName(QgsMapLayer *layer) const
Sets a layer name to match this output, respecting any local user settings which affect this name.
void setEllipsoid(const QString &ellipsoid)
Sets a specified ellipsoid to use for distance and area calculations.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
void takeResultsFrom(QgsProcessingContext &context)
Takes the results from another context and merges them with the results currently stored in this cont...
void setCurrentTimeRange(const QgsDateTimeRange ¤tTimeRange)
Sets the current time range to use for temporal operations.
virtual QString sourceName() const =0
Returns a friendly display name for the source.
QgsDateTimeRange currentTimeRange() const
Returns the current time range to use for temporal operations.
Contains information about the context in which a processing algorithm is executed.
std::function< void(const QgsFeature &) > invalidGeometryCallback(QgsFeatureSource *source=nullptr) const
Returns the callback function to use when encountering an invalid geometry and invalidGeometryCheck()...
Utility functions for use with processing classes.
QString ellipsoid() const
Returns the ellipsoid to use for distance and area calculations.
void setInvalidGeometryCheck(QgsFeatureRequest::InvalidGeometryCheck check)
Sets the behavior used for checking invalid geometries in input layers.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
QVariantMap exportToMap() const
Exports the context's settings to a variant map.
An interface for layer post-processing handlers for execution following a processing algorithm operat...
QgsProcessingLayerPostProcessorInterface * postProcessor() const
Layer post-processor.
void setAreaUnit(QgsUnitTypes::AreaUnit areaUnit)
Sets the unit to use for area calculations.
void setDistanceUnit(QgsUnitTypes::DistanceUnit unit)
Sets the unit to use for distance calculations.
Details for layers to load into projects.
QgsMapLayer * takeMapLayer(QgsMapLayer *layer)
Takes a layer from the store.
QgsMapLayer * getMapLayer(const QString &identifier)
Returns a map layer from the context with a matching identifier.
QgsMapLayerStore * temporaryLayerStore()
Returns a reference to the layer store used for storing temporary layers during algorithm execution.
QgsProcessingContext()
Constructor for QgsProcessingContext.
virtual bool isTemporary() const
Returns true if the layer is considered a temporary layer.
QString source() const
Returns the source for the layer.
void addLayerToLoadOnCompletion(const QString &layer, const QgsProcessingContext::LayerDetails &details)
Adds a layer to load (by ID or datasource) into the canvas upon completion of the algorithm or model.
QgsUnitTypes::AreaUnit areaUnit() const
Returns the area unit to use for area calculations.
void setName(const QString &name)
Set the display name of the layer.
Base class for all map layer types. This is the base class for all map layer types (vector,...
QgsProcessingContext::Flags flags() const
Returns any flags set in the context.
@ GeometryNoCheck
No invalid geometry checking.
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.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
static const QgsSettingsEntryBool settingsPreferFilenameAsLayerName
Settings entry prefer filename as layer name.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Custom exception class for processing related exceptions.
@ AreaUnknownUnit
Unknown areal unit.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
LogLevel logLevel() const
Returns the logging level for algorithms to use when pushing feedback messages to users.