22 #include "qgssettings.h"
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 Processing setting to the “Ignore invalid input features” option." ).arg( feature.id() ).arg( sourceName ) );
89 throw QgsProcessingException( QObject::tr(
"Feature (%1) has invalid geometry. Please fix the geometry or change the Processing setting to the “Ignore invalid input features” option." ).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 Processing setting to the “Ignore invalid input features” option." ).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 Processing setting to the “Ignore invalid input features” option." ).arg( feature.id() ) );
118 context.mLayersToLoadOnCompletion.clear();
144 return mCurrentTimeRange;
164 return mDistanceUnit;
169 mDistanceUnit = unit;
184 return mPostProcessor;
189 if ( mPostProcessor && mPostProcessor != processor )
190 delete mPostProcessor;
192 mPostProcessor = processor;
203 if ( ( !forceName && preferFilenameAsLayerName && !layer->
isTemporary() ) || name.isEmpty() )
206 const QString layerName = sourceParts.value( QStringLiteral(
"layerName" ) ).toString();
208 if ( !layerName.isEmpty() )
212 const QString path = sourceParts.value( QStringLiteral(
"path" ) ).toString();
213 if ( !path.isEmpty() )
215 const QFileInfo fi( path );
216 layer->
setName( fi.baseName() );
218 else if ( !name.isEmpty() )
InvalidGeometryCheck
Handling of features with invalid geometries.
@ GeometryNoCheck
No invalid geometry checking.
@ GeometryAbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
@ GeometrySkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
An interface for objects which provide features via a getFeatures method.
virtual QString sourceName() const =0
Returns a friendly display name for the source.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsMapLayer * takeMapLayer(QgsMapLayer *layer)
Takes a layer from the store.
QgsMapLayer * mapLayer(const QString &id) const
Retrieve a pointer to a layer by layer id.
void transferLayersFromStore(QgsMapLayerStore *other)
Transfers all the map layers contained within another map layer store and adds them to this store.
Base class for all map layer types.
virtual bool isTemporary() const
Returns true if the layer is considered a temporary layer.
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
void setName(const QString &name)
Set the display name of the layer.
Details for layers to load into projects.
QgsProcessingLayerPostProcessorInterface * postProcessor() const
Layer post-processor.
void setPostProcessor(QgsProcessingLayerPostProcessorInterface *processor)
Sets the layer post-processor.
void setOutputLayerName(QgsMapLayer *layer) const
Sets a layer name to match this output, respecting any local user settings which affect this name.
Contains information about the context in which a processing algorithm is executed.
QgsMapLayerStore * temporaryLayerStore()
Returns a reference to the layer store used for storing temporary layers during algorithm execution.
void setAreaUnit(QgsUnitTypes::AreaUnit areaUnit)
Sets the unit to use for area calculations.
LogLevel
Logging level for algorithms to use when pushing feedback messages.
QgsDateTimeRange currentTimeRange() const
Returns the current time range to use for temporal operations.
QgsUnitTypes::AreaUnit areaUnit() const
Returns the area unit to use for area calculations.
void takeResultsFrom(QgsProcessingContext &context)
Takes the results from another context and merges them with the results currently stored in this cont...
QgsMapLayer * getMapLayer(const QString &identifier)
Returns a map layer from the context with a matching identifier.
std::function< void(const QgsFeature &) > invalidGeometryCallback(QgsFeatureSource *source=nullptr) const
Returns the callback function to use when encountering an invalid geometry and invalidGeometryCheck()...
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...
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 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.
void setEllipsoid(const QString &ellipsoid)
Sets a specified ellipsoid to use for distance and area calculations.
QgsProcessingContext()
Constructor for QgsProcessingContext.
QgsUnitTypes::DistanceUnit distanceUnit() const
Returns the distance unit to use for distance calculations.
void setLogLevel(LogLevel level)
Sets the logging level for algorithms to use when pushing feedback messages to users.
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.
LogLevel logLevel() const
Returns the logging level for algorithms to use when pushing feedback messages to users.
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.
void setCurrentTimeRange(const QgsDateTimeRange ¤tTimeRange)
Sets the current time range to use for temporal operations.
void setDistanceUnit(QgsUnitTypes::DistanceUnit unit)
Sets the unit to use for distance calculations.
Custom exception class for processing related exceptions.
An interface for layer post-processing handlers for execution following a processing algorithm operat...
Utility functions for use with processing classes.
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.
static const QgsSettingsEntryBool settingsPreferFilenameAsLayerName
Settings entry prefer filename as layer name.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
DistanceUnit
Units of distance.