QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
27 auto callback = [ = ](
const QgsFeature & feature )
30 mFeedback->reportError( QObject::tr(
"Encountered a transform error when reprojecting feature with id %1." ).arg( feature.id() ) );
32 mTransformErrorCallback = callback;
37 for (
auto it = mLayersToLoadOnCompletion.constBegin(); it != mLayersToLoadOnCompletion.constEnd(); ++it )
39 delete it.value().postProcessor();
45 for (
auto it = mLayersToLoadOnCompletion.constBegin(); it != mLayersToLoadOnCompletion.constEnd(); ++it )
47 if ( !layers.contains( it.key() ) || layers.value( it.key() ).postProcessor() != it.value().postProcessor() )
48 delete it.value().postProcessor();
50 mLayersToLoadOnCompletion = layers;
55 if ( mLayersToLoadOnCompletion.contains( layer ) && mLayersToLoadOnCompletion.value( layer ).postProcessor() != details.
postProcessor() )
56 delete mLayersToLoadOnCompletion.value( layer ).postProcessor();
58 mLayersToLoadOnCompletion.insert( layer, details );
63 mInvalidGeometryCheck = check;
64 mUseDefaultInvalidGeometryCallback =
true;
70 if ( mUseDefaultInvalidGeometryCallback )
73 return mInvalidGeometryCallback;
78 const QString sourceName = source ? source->
sourceName() : QString();
83 auto callback = [sourceName](
const QgsFeature & feature )
85 if ( !sourceName.isEmpty() )
86 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 ) );
88 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() ) );
95 auto callback = [ = ](
const QgsFeature & feature )
99 if ( !sourceName.isEmpty() )
100 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 ) );
102 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() ) );
117 context.mLayersToLoadOnCompletion.clear();
143 return mDistanceUnit;
148 mDistanceUnit = unit;
163 return mPostProcessor;
168 if ( mPostProcessor && mPostProcessor != processor )
169 delete mPostProcessor;
171 mPostProcessor = processor;
179 const bool preferFilenameAsLayerName =
QgsSettings().
value( QStringLiteral(
"Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ),
true ).toBool();
182 if ( ( !forceName && preferFilenameAsLayerName && !layer->
isTemporary() ) || name.isEmpty() )
185 const QString layerName = sourceParts.value( QStringLiteral(
"layerName" ) ).toString();
187 if ( !layerName.isEmpty() )
191 const QString path = sourceParts.value( QStringLiteral(
"path" ) ).toString();
192 if ( !path.isEmpty() )
194 const QFileInfo fi( path );
195 layer->
setName( fi.baseName() );
197 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.
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...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QgsUnitTypes::DistanceUnit distanceUnit() const
Returns the distance unit to use for distance calculations.
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.
This class is a composition of two QSettings instances:
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.
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.
void takeResultsFrom(QgsProcessingContext &context)
Takes the results from another context and merges them with the results currently stored in this cont...
virtual QString sourceName() const =0
Returns a friendly display name for the source.
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.
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.
@ 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 id, geometry and a list of field/values...
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Custom exception class for processing related exceptions.