Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Geometry checker] Add dangle check
- Loading branch information
1 parent
84184d4
commit 7fb1c55
Showing
7 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/plugins/geometry_checker/checks/qgsgeometrydanglecheck.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/*************************************************************************** | ||
qgsgeometrydanglecheck.cpp | ||
--------------------- | ||
begin : June 2017 | ||
copyright : (C) 2017 by Sandro Mani / Sourcepole AG | ||
email : smani at sourcepole dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsgeometrydanglecheck.h" | ||
#include "qgslinestring.h" | ||
|
||
void QgsGeometryDangleCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &/*messages*/, QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const | ||
{ | ||
QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds() : ids; | ||
QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds, mCompatibleGeometryTypes, progressCounter ); | ||
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures ) | ||
{ | ||
const QgsAbstractGeometry *geom = layerFeature.geometry(); | ||
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart ) | ||
{ | ||
const QgsLineString *line = dynamic_cast<const QgsLineString *>( QgsGeometryCheckerUtils::getGeomPart( geom, iPart ) ); | ||
if ( !line ) | ||
{ | ||
// Should not happen | ||
continue; | ||
} | ||
// Check that start and end node lie on a line | ||
int nVerts = geom->vertexCount( iPart, 0 ); | ||
const QgsPoint &p1 = geom->vertexAt( QgsVertexId( iPart, 0, 0 ) ); | ||
const QgsPoint &p2 = geom->vertexAt( QgsVertexId( iPart, 0, nVerts - 1 ) ); | ||
|
||
bool p1touches = QgsGeometryCheckerUtils::pointOnLine( p1, line, mContext->tolerance, true ); | ||
bool p2touches = QgsGeometryCheckerUtils::pointOnLine( p2, line, mContext->tolerance, true ); | ||
|
||
if ( p1touches && p2touches ) | ||
{ | ||
// Both endpoints lie on line itself | ||
continue; | ||
} | ||
|
||
// Check whether endpoints line on another line in the layer | ||
QgsGeometryCheckerUtils::LayerFeatures checkFeatures( mContext->featurePools, QList<QString>() << layerFeature.layer().id(), line->boundingBox(), {QgsWkbTypes::LineGeometry} ); | ||
for ( const QgsGeometryCheckerUtils::LayerFeature &checkFeature : checkFeatures ) | ||
{ | ||
if ( checkFeature.feature().id() == layerFeature.feature().id() ) | ||
{ | ||
// Skip current feature, it was already checked above | ||
continue; | ||
} | ||
const QgsAbstractGeometry *testGeom = checkFeature.geometry(); | ||
for ( int jPart = 0, mParts = testGeom->partCount(); jPart < mParts; ++jPart ) | ||
{ | ||
const QgsLineString *testLine = dynamic_cast<const QgsLineString *>( QgsGeometryCheckerUtils::getGeomPart( testGeom, jPart ) ); | ||
if ( !testLine ) | ||
{ | ||
continue; | ||
} | ||
p1touches = p1touches || QgsGeometryCheckerUtils::pointOnLine( p1, testLine, mContext->tolerance ); | ||
p2touches = p2touches || QgsGeometryCheckerUtils::pointOnLine( p2, testLine, mContext->tolerance ); | ||
if ( p1touches && p2touches ) | ||
{ | ||
break; | ||
} | ||
} | ||
if ( p1touches && p2touches ) | ||
{ | ||
break; | ||
} | ||
} | ||
if ( p1touches && p2touches ) | ||
{ | ||
continue; | ||
} | ||
if ( !p1touches ) | ||
{ | ||
errors.append( new QgsGeometryCheckError( this, layerFeature, p1, QgsVertexId( iPart, 0, 0 ) ) ); | ||
} | ||
if ( !p2touches ) | ||
{ | ||
errors.append( new QgsGeometryCheckError( this, layerFeature, p2, QgsVertexId( iPart, 0, nVerts - 1 ) ) ); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void QgsGeometryDangleCheck::fixError( QgsGeometryCheckError *error, int method, const QMap<QString, int> & /*mergeAttributeIndices*/, Changes & /*changes*/ ) const | ||
{ | ||
if ( method == NoChange ) | ||
{ | ||
error->setFixed( method ); | ||
} | ||
else | ||
{ | ||
error->setFixFailed( tr( "Unknown method" ) ); | ||
} | ||
} | ||
|
||
QStringList QgsGeometryDangleCheck::getResolutionMethods() const | ||
{ | ||
static QStringList methods = QStringList() << tr( "No action" ); | ||
return methods; | ||
} |
38 changes: 38 additions & 0 deletions
38
src/plugins/geometry_checker/checks/qgsgeometrydanglecheck.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/*************************************************************************** | ||
qgsgeometrydanglecheck.h | ||
--------------------- | ||
begin : June 2017 | ||
copyright : (C) 2017 by Sandro Mani / Sourcepole AG | ||
email : smani at sourcepole dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSGEOMETRYDANGLECHECK_H | ||
#define QGSGEOMETRYDANGLECHECK_H | ||
|
||
#include "qgsgeometrycheck.h" | ||
|
||
class QgsGeometryDangleCheck : public QgsGeometryCheck | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsGeometryDangleCheck( QgsGeometryCheckerContext *context ) | ||
: QgsGeometryCheck( FeatureNodeCheck, {QgsWkbTypes::LineGeometry}, context ) | ||
{} | ||
void collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &messages, QAtomicInt *progressCounter = nullptr, const QMap<QString, QgsFeatureIds> &ids = QMap<QString, QgsFeatureIds>() ) const override; | ||
void fixError( QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override; | ||
QStringList getResolutionMethods() const override; | ||
QString errorDescription() const override { return tr( "Dangle" ); } | ||
QString errorName() const override { return QStringLiteral( "QgsGeometryDangleCheck" ); } | ||
private: | ||
enum ResolutionMethod { NoChange }; | ||
}; | ||
|
||
#endif // QGSGEOMETRYDANGLECHECK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters