Skip to content

Commit 0984fc8

Browse files
committedMar 18, 2019
Better error location for missing vertex errors
When showing a missing vertex error, the map canvas is now centered on the missing vertex location and scaled by taking neighbouring vertices into account.
1 parent 146dca4 commit 0984fc8

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed
 

‎src/analysis/vector/geometry_checker/qgsgeometrymissingvertexcheck.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polyg
135135
const int numRings = polygon->numInteriorRings();
136136
for ( int i = 0; i < numRings; ++i )
137137
{
138-
geomEngine = QgsGeometryCheckerUtils::createGeomEngine( polygon->exteriorRing(), mContext->tolerance );
138+
geomEngine = QgsGeometryCheckerUtils::createGeomEngine( polygon->interiorRing( i ), mContext->tolerance );
139139
boundaries->addGeometry( geomEngine->buffer( mContext->tolerance, 5 ) );
140140
}
141141

@@ -177,14 +177,36 @@ void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polyg
177177
}
178178
}
179179
if ( !alreadyReported )
180-
errors.append( new QgsGeometryCheckError( this, layerFeature, QgsPointXY( pt ) ) );
180+
{
181+
std::unique_ptr<QgsGeometryMissingVertexCheckError> error = qgis::make_unique<QgsGeometryMissingVertexCheckError>( this, layerFeature, QgsPointXY( pt ) );
182+
error->setAffectedAreaBBox( contextBoundingBox( polygon, vertexId, pt ) );
183+
184+
errors.append( error.release() );
185+
}
181186
}
182187
}
183188
}
184189
}
185190
}
186191
}
187192

193+
QgsRectangle QgsGeometryMissingVertexCheck::contextBoundingBox( const QgsCurvePolygon *polygon, const QgsVertexId &vertexId, const QgsPoint &point ) const
194+
{
195+
QgsVertexId vertexBefore;
196+
QgsVertexId vertexAfter;
197+
198+
polygon->adjacentVertices( vertexId, vertexBefore, vertexAfter );
199+
200+
QgsPoint ptBefore = polygon->vertexAt( vertexBefore );
201+
QgsPoint ptAt = polygon->vertexAt( vertexId );
202+
QgsPoint ptAfter = polygon->vertexAt( vertexAfter );
203+
204+
double length = std::abs( ptAt.distance( ptBefore ) ) + std::abs( ptAt.distance( ptAfter ) );
205+
206+
QgsRectangle rect( point.x() - length / 2, point.y() - length / 2, point.x() + length / 2, point.y() + length / 2 );
207+
return rect;
208+
}
209+
188210
QString QgsGeometryMissingVertexCheck::id() const
189211
{
190212
return factoryId();
@@ -234,3 +256,19 @@ QgsGeometryCheck::CheckType QgsGeometryMissingVertexCheck::factoryCheckType()
234256
{
235257
return QgsGeometryCheck::LayerCheck;
236258
}
259+
///@endcond private
260+
261+
QgsGeometryMissingVertexCheckError::QgsGeometryMissingVertexCheckError( const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsPointXY &errorLocation, QgsVertexId vidx, const QVariant &value, QgsGeometryCheckError::ValueType valueType )
262+
: QgsGeometryCheckError( check, layerFeature, errorLocation, vidx, value, valueType )
263+
{
264+
}
265+
266+
QgsRectangle QgsGeometryMissingVertexCheckError::affectedAreaBBox() const
267+
{
268+
return mAffectedAreaBBox;
269+
}
270+
271+
void QgsGeometryMissingVertexCheckError::setAffectedAreaBBox( const QgsRectangle &affectedAreaBBox )
272+
{
273+
mAffectedAreaBBox = affectedAreaBBox;
274+
}

‎src/analysis/vector/geometry_checker/qgsgeometrymissingvertexcheck.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,43 @@
2323

2424
class QgsCurvePolygon;
2525

26+
/**
27+
* \ingroup analysis
28+
*
29+
* A geometry check error for a missing vertex.
30+
* Includes additional details about the bounding box of the error,
31+
* centered on the missing error location and scaled by taking neighbouring
32+
* vertices into account.
33+
*
34+
* \since QGIS 3.8
35+
*/
36+
class ANALYSIS_EXPORT QgsGeometryMissingVertexCheckError : public QgsGeometryCheckError
37+
{
38+
public:
39+
40+
/**
41+
* Create a new missing vertex check error.
42+
*/
43+
QgsGeometryMissingVertexCheckError( const QgsGeometryCheck *check,
44+
const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
45+
const QgsPointXY &errorLocation,
46+
QgsVertexId vidx = QgsVertexId(),
47+
const QVariant &value = QVariant(),
48+
ValueType valueType = ValueOther );
49+
50+
QgsRectangle affectedAreaBBox() const override;
51+
52+
/**
53+
* Set the bounding box of the affected area.
54+
*
55+
* \since QGIS 3.8
56+
*/
57+
void setAffectedAreaBBox( const QgsRectangle &affectedAreaBBox );
58+
59+
private:
60+
QgsRectangle mAffectedAreaBBox;
61+
};
62+
2663
/**
2764
* \ingroup analysis
2865
*
@@ -66,6 +103,8 @@ class ANALYSIS_EXPORT QgsGeometryMissingVertexCheck : public QgsGeometryCheck
66103

67104
private:
68105
void processPolygon( const QgsCurvePolygon *polygon, QgsFeaturePool *featurePool, QList<QgsGeometryCheckError *> &errors, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, QgsFeedback *feedback ) const;
106+
107+
QgsRectangle contextBoundingBox( const QgsCurvePolygon *polygon, const QgsVertexId &vertexId, const QgsPoint &point ) const;
69108
};
70109

71110

0 commit comments

Comments
 (0)
Please sign in to comment.