28auto QgsGeometryCheckAngleAlgorithm::name() const -> QString
30 return QStringLiteral(
"checkgeometryangle" );
33auto QgsGeometryCheckAngleAlgorithm::displayName() const -> QString
35 return QObject::tr(
"Check geometry (Angle)" );
38auto QgsGeometryCheckAngleAlgorithm::tags() const -> QStringList
40 return QObject::tr(
"check,geometry,angle" ).split(
',' );
43auto QgsGeometryCheckAngleAlgorithm::group() const -> QString
45 return QObject::tr(
"Check geometry" );
48auto QgsGeometryCheckAngleAlgorithm::groupId() const -> QString
50 return QStringLiteral(
"checkgeometry" );
53auto QgsGeometryCheckAngleAlgorithm::shortHelpString() const -> QString
55 return QObject::tr(
"This algorithm checks the angles of line or polygon geometries." );
58auto QgsGeometryCheckAngleAlgorithm::flags() const ->
Qgis::ProcessingAlgorithmFlags
63auto QgsGeometryCheckAngleAlgorithm::createInstance() const -> QgsGeometryCheckAngleAlgorithm *
65 return new QgsGeometryCheckAngleAlgorithm();
68void QgsGeometryCheckAngleAlgorithm::initAlgorithm(
const QVariantMap &configuration )
70 Q_UNUSED( configuration )
75 QStringLiteral(
"INPUT" ), QObject::tr(
"Input layer" ),
79 addParameter(
new QgsProcessingParameterField( QStringLiteral(
"UNIQUE_ID" ), QObject::tr(
"Unique feature identifier" ), QString(), QStringLiteral(
"INPUT" ) ) );
86 std::unique_ptr<QgsProcessingParameterNumber> tolerance = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"TOLERANCE" ), QObject::tr(
"Tolerance" ),
Qgis::ProcessingNumberParameterType::Integer, 8,
false, 1, 13 );
88 addParameter( tolerance.release() );
93 mTolerance = parameterAsInt( parameters, QStringLiteral(
"TOLERANCE" ), context );
99auto QgsGeometryCheckAngleAlgorithm::outputFields() ->
QgsFields
102 fields.
append(
QgsField( QStringLiteral(
"gc_layerid" ), QMetaType::QString ) );
103 fields.
append(
QgsField( QStringLiteral(
"gc_layername" ), QMetaType::QString ) );
104 fields.
append(
QgsField( QStringLiteral(
"gc_partidx" ), QMetaType::Int ) );
105 fields.
append(
QgsField( QStringLiteral(
"gc_ringidx" ), QMetaType::Int ) );
106 fields.
append(
QgsField( QStringLiteral(
"gc_vertidx" ), QMetaType::Int ) );
107 fields.
append(
QgsField( QStringLiteral(
"gc_errorx" ), QMetaType::Double ) );
108 fields.
append(
QgsField( QStringLiteral(
"gc_errory" ), QMetaType::Double ) );
109 fields.
append(
QgsField( QStringLiteral(
"gc_error" ), QMetaType::QString ) );
120 QString uniqueIdFieldName( parameterAsString( parameters, QStringLiteral(
"UNIQUE_ID" ), context ) );
122 if ( uniqueIdFieldIdx == -1 )
123 throw QgsProcessingException( QObject::tr(
"Missing field %1 in input layer" ).arg( uniqueIdFieldName ) );
128 fields.
append( uniqueIdField );
130 const std::unique_ptr<QgsFeatureSink> sink_output( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest_output, fields, input->
wkbType(), input->
sourceCrs() ) );
134 const std::unique_ptr<QgsFeatureSink> sink_errors( parameterAsSink( parameters, QStringLiteral(
"ERRORS" ), context, dest_errors, fields,
Qgis::WkbType::Point, input->
sourceCrs() ) );
142 const std::unique_ptr<QgsGeometryCheckContext> checkContext = std::make_unique<QgsGeometryCheckContext>( mTolerance, input->
sourceCrs(), project->
transformContext(), project );
145 QList<QgsGeometryCheckError *> checkErrors;
146 QStringList messages;
148 const double minAngle = parameterAsDouble( parameters, QStringLiteral(
"MIN_ANGLE" ), context );
150 QVariantMap configurationCheck;
151 configurationCheck.insert(
"minAngle", minAngle );
154 multiStepFeedback.setCurrentStep( 1 );
155 feedback->setProgressText( QObject::tr(
"Preparing features…" ) );
156 QMap<QString, QgsFeaturePool *> featurePools;
161 multiStepFeedback.setCurrentStep( 2 );
162 feedback->setProgressText( QObject::tr(
"Collecting errors…" ) );
163 check.collectErrors( featurePools, checkErrors, messages, feedback );
165 multiStepFeedback.setCurrentStep( 3 );
166 feedback->setProgressText( QObject::tr(
"Exporting errors…" ) );
167 const double step { checkErrors.size() > 0 ? 100.0 / checkErrors.size() : 1 };
169 feedback->setProgress( 0.0 );
173 if ( feedback->isCanceled() )
180 attrs << error->layerId()
181 << inputLayer->
name()
182 << error->vidx().part
183 << error->vidx().ring
184 << error->vidx().vertex
185 << error->location().x()
186 << error->location().y()
187 << error->value().toString()
193 throw QgsProcessingException( writeFeatureError( sink_output.get(), parameters, QStringLiteral(
"OUTPUT" ) ) );
197 throw QgsProcessingException( writeFeatureError( sink_errors.get(), parameters, QStringLiteral(
"ERRORS" ) ) );
200 feedback->setProgress( 100.0 * step *
static_cast<double>( i ) );
204 outputs.insert( QStringLiteral(
"OUTPUT" ), dest_output );
205 outputs.insert( QStringLiteral(
"ERRORS" ), dest_errors );
The Qgis class provides global constants for use throughout the application.
@ VectorAnyGeometry
Any vector layer with geometry.
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ NoThreading
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
@ Double
Double/float values.
This class 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...
QgsVectorLayer * materialize(const QgsFeatureRequest &request, QgsFeedback *feedback=nullptr)
Materializes a request (query) made against this feature source, by running it over the source and re...
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.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
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.
Q_INVOKABLE int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
This represents an error reported by a geometry check.
static QgsGeometry fromPoint(const QgsPoint &point)
Creates a new geometry from a QgsPoint object.
Point geometry type, with support for z-dimension and m-values.
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.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
QgsCoordinateReferenceSystem sourceCrs() const override
Returns the coordinate reference system for features in the source.
Qgis::WkbType wkbType() const override
Returns the geometry type for features returned by this source.
QgsFields fields() const override
Returns the fields associated with features in the source.
Base class for providing feedback from a processing algorithm.
Processing feedback object for multi-step operations.
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.
A numeric parameter for processing algorithms.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
A feature pool based on a vector data provider.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.