22QString QgsFixGeometryDeleteFeaturesAlgorithm::name()
const
24 return QStringLiteral(
"fixgeometrydeletefeatures" );
27QString QgsFixGeometryDeleteFeaturesAlgorithm::displayName()
const
29 return QObject::tr(
"Delete features" );
32QString QgsFixGeometryDeleteFeaturesAlgorithm::shortDescription()
const
34 return QObject::tr(
"Deletes features detected with an algorithm from the \"Check geometry\" section." );
37QStringList QgsFixGeometryDeleteFeaturesAlgorithm::tags()
const
39 return QObject::tr(
"fix,delete,features" ).split(
',' );
42QString QgsFixGeometryDeleteFeaturesAlgorithm::group()
const
44 return QObject::tr(
"Fix geometry" );
47QString QgsFixGeometryDeleteFeaturesAlgorithm::groupId()
const
49 return QStringLiteral(
"fixgeometry" );
52QString QgsFixGeometryDeleteFeaturesAlgorithm::shortHelpString()
const
54 return QObject::tr(
"This algorithm deletes error features listed in the errors layer from an algorithm in the \"Check geometry\" section.\n"
55 "The required inputs are the original layer used in the check algorithm, its unique id field, and its corresponding errors layer.\n\n"
56 "For instance, it can be used after the following check algorithms to delete error features:"
57 "<html><ul><li>Feature inside polygon</li>"
58 "<li>Degenerate polygons</li>"
59 "<li>Small segments</li>"
60 "<li>Duplicated geometries</li>"
61 "<li>etc.</li></ul></html>" );
64QgsFixGeometryDeleteFeaturesAlgorithm *QgsFixGeometryDeleteFeaturesAlgorithm::createInstance()
const
66 return new QgsFixGeometryDeleteFeaturesAlgorithm();
69void QgsFixGeometryDeleteFeaturesAlgorithm::initAlgorithm(
const QVariantMap &configuration )
71 Q_UNUSED( configuration )
75 QStringLiteral(
"INPUT" ), QObject::tr(
"Input layer" ),
85 QStringLiteral(
"UNIQUE_ID" ), QObject::tr(
"Field of original feature unique identifier" ),
86 QString(), QStringLiteral(
"ERRORS" )
100 const std::unique_ptr<QgsProcessingFeatureSource> input( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
104 const std::unique_ptr<QgsProcessingFeatureSource> errors( parameterAsSource( parameters, QStringLiteral(
"ERRORS" ), context ) );
108 const QString featIdFieldName = parameterAsString( parameters, QStringLiteral(
"UNIQUE_ID" ), context );
111 const int errorsIdFieldIndex = errors->fields().indexFromName( featIdFieldName );
112 if ( errorsIdFieldIndex == -1 )
113 throw QgsProcessingException( QObject::tr(
"Field %1 does not exist in the error layer." ).arg( featIdFieldName ) );
114 const int inputIdFieldIndex = input->fields().indexFromName( featIdFieldName );
115 if ( inputIdFieldIndex == -1 )
116 throw QgsProcessingException( QObject::tr(
"Field %1 does not exist in input layer." ).arg( featIdFieldName ) );
118 const QgsField inputFeatIdField = input->fields().at( inputIdFieldIndex );
119 const QMetaType::Type inputFeatIdFieldType = inputFeatIdField.
type();
120 if ( inputFeatIdFieldType != errors->fields().at( errorsIdFieldIndex ).type() )
121 throw QgsProcessingException( QObject::tr(
"Input field %1 does not have the same type as in the error layer." ).arg( featIdFieldName ) );
124 const std::unique_ptr<QgsFeatureSink> sink_output( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest_output, input->fields(), input->wkbType(), input->sourceCrs() ) );
129 QgsFields reportFields = errors->fields();
130 reportFields.
append(
QgsField( QStringLiteral(
"report" ), QMetaType::QString ) );
131 reportFields.
append(
QgsField( QStringLiteral(
"error_fixed" ), QMetaType::Bool ) );
132 const std::unique_ptr<QgsFeatureSink> sink_report( parameterAsSink( parameters, QStringLiteral(
"REPORT" ), context, dest_report, reportFields, errors->wkbType(), errors->sourceCrs() ) );
136 QgsFeature inputFeature, errorFeature, reportFeature;
138 long long progression = 0;
139 long long totalProgression = input->featureCount();
143 while ( inputFeaturesIt.
nextFeature( inputFeature ) )
149 feedback->
setProgress(
static_cast<double>(
static_cast<long double>( progression ) / totalProgression ) * 100 );
151 QString idValue = inputFeature.
attribute( featIdFieldName ).toString();
152 if ( inputFeatIdFieldType == QMetaType::QString )
153 idValue =
"'" + idValue +
"'";
158 .setFilterExpression(
"\"" + featIdFieldName +
"\" = " + idValue )
169 throw QgsProcessingException( writeFeatureError( sink_report.get(), parameters, QStringLiteral(
"REPORT" ) ) );
176 throw QgsProcessingException( writeFeatureError( sink_output.get(), parameters, QStringLiteral(
"OUTPUT" ) ) );
182 outputs.insert( QStringLiteral(
"OUTPUT" ), dest_output );
183 outputs.insert( QStringLiteral(
"REPORT" ), dest_report );
@ VectorAnyGeometry
Any vector layer with geometry.
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ SubsetOfAttributes
Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
@ NoThreading
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
void setFields(const QgsFields &fields, bool initAttributes=false)
Assigns a field map with the feature to allow attribute access by attribute name.
bool isValid() const
Returns the validity of this feature.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void setProgressText(const QString &text)
Sets a progress report text string.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A vector layer or feature source field parameter for processing algorithms.