QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsgeometrymultipartcheck.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometrymultipartcheck.cpp
3 ---------------------
4 begin : September 2015
5 copyright : (C) 2014 by Sandro Mani / Sourcepole AG
6 email : smani at sourcepole dot ch
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "qgsfeaturepool.h"
18
19QList<QgsSingleGeometryCheckError *> QgsGeometryMultipartCheck::processGeometry( const QgsGeometry &geometry ) const
20{
21 QList<QgsSingleGeometryCheckError *> errors;
22
23 const QgsAbstractGeometry *geom = geometry.constGet();
24 const Qgis::WkbType type = geom->wkbType();
25 if ( geom->partCount() == 1 && QgsWkbTypes::isMultiType( type ) )
26 {
27 errors.append( new QgsSingleGeometryCheckError( this, geometry, geometry ) );
28 }
29 return errors;
30}
31
32void QgsGeometryMultipartCheck::fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> & /*mergeAttributeIndices*/, Changes &changes ) const
33{
34 QgsFeaturePool *featurePool = featurePools[ error->layerId() ];
35 QgsFeature feature;
36 if ( !featurePool->getFeature( error->featureId(), feature ) )
37 {
38 error->setObsolete();
39 return;
40 }
41 const QgsGeometry featureGeom = feature.geometry();
42 const QgsAbstractGeometry *geom = featureGeom.constGet();
43
44 // Check if error still applies
45 if ( geom->partCount() > 1 || !QgsWkbTypes::isMultiType( geom->wkbType() ) )
46 {
47 error->setObsolete();
48 return;
49 }
50
51 // Fix error
52 if ( method == NoChange )
53 {
54 error->setFixed( method );
55 }
56 else if ( method == ConvertToSingle )
57 {
58 feature.setGeometry( QgsGeometry( QgsGeometryCheckerUtils::getGeomPart( geom, 0 )->clone() ) );
59 featurePool->updateFeature( feature );
60 error->setFixed( method );
61 changes[error->layerId()][feature.id()].append( Change( ChangeFeature, ChangeChanged ) );
62 }
63 else if ( method == RemoveObject )
64 {
65 featurePool->deleteFeature( feature.id() );
66 error->setFixed( method );
67 changes[error->layerId()][feature.id()].append( Change( ChangeFeature, ChangeRemoved ) );
68 }
69 else
70 {
71 error->setFixFailed( tr( "Unknown method" ) );
72 }
73}
74
76{
77 static const QStringList methods = QStringList()
78 << tr( "Convert to single part feature" )
79 << tr( "Delete feature" )
80 << tr( "No action" );
81 return methods;
82}
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
Abstract base class for all geometries.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual int partCount() const =0
Returns count of parts contained in the geometry.
A feature pool is based on a vector layer and caches features.
virtual void updateFeature(QgsFeature &feature)=0
Updates a feature in this pool.
virtual void deleteFeature(QgsFeatureId fid)=0
Removes a feature from this pool.
bool getFeature(QgsFeatureId id, QgsFeature &feature)
Retrieves the feature with the specified id into feature.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
QgsFeatureId id
Definition qgsfeature.h:66
QgsGeometry geometry
Definition qgsfeature.h:69
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
This represents an error reported by a geometry check.
QgsFeatureId featureId() const
The id of the feature on which this error has been detected.
void setFixed(int method)
Set the status to fixed and specify the method that has been used to fix the error.
void setFixFailed(const QString &reason)
Set the error status to failed and specify the reason for failure.
void setObsolete()
Set the error status to obsolete.
const QString & layerId() const
The id of the layer on which this error has been detected.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
@ ChangeFeature
This change happens on feature level.
@ ChangeChanged
Something has been updated.
@ ChangeRemoved
Something has been removed.
static QgsAbstractGeometry * getGeomPart(QgsAbstractGeometry *geom, int partIdx)
void fixError(const QMap< QString, QgsFeaturePool * > &featurePools, QgsGeometryCheckError *error, int method, const QMap< QString, int > &mergeAttributeIndices, Changes &changes) const override
Fixes the error error with the specified method.
QList< QgsSingleGeometryCheckError * > processGeometry(const QgsGeometry &geometry) const override
Check the geometry for errors.
Q_DECL_DEPRECATED QStringList resolutionMethods() const override
Returns a list of descriptions for available resolutions for errors.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
An error from a QgsSingleGeometryCheck.
static bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
Descripts a change to fix a geometry.