Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Geometry checker] Add point must be covered by line check
- Loading branch information
1 parent
7fb1c55
commit ee47d42
Showing
6 changed files
with
197 additions
and
35 deletions.
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
86 changes: 86 additions & 0 deletions
86
src/plugins/geometry_checker/checks/qgsgeometrypointcoveredbylinecheck.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,86 @@ | ||
/*************************************************************************** | ||
qgsgeometrypointcoveredbylinecheck.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 "qgsgeometrypointcoveredbylinecheck.h" | ||
#include "qgslinestring.h" | ||
#include "../utils/qgsfeaturepool.h" | ||
|
||
void QgsGeometryPointCoveredByLineCheck::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, true ); | ||
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures ) | ||
{ | ||
const QgsAbstractGeometry *geom = layerFeature.geometry(); | ||
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart ) | ||
{ | ||
const QgsPoint *point = dynamic_cast<const QgsPoint *>( QgsGeometryCheckerUtils::getGeomPart( geom, iPart ) ); | ||
if ( !point ) | ||
{ | ||
// Should not happen | ||
continue; | ||
} | ||
// Check that point lies on a line | ||
bool touches = false; | ||
QgsRectangle rect( point->x() - mContext->tolerance, point->y() - mContext->tolerance, | ||
point->x() + mContext->tolerance, point->y() + mContext->tolerance ); | ||
QgsGeometryCheckerUtils::LayerFeatures checkFeatures( mContext->featurePools, featureIds.keys(), rect, {QgsWkbTypes::LineGeometry} ); | ||
for ( const QgsGeometryCheckerUtils::LayerFeature &checkFeature : checkFeatures ) | ||
{ | ||
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; | ||
} | ||
if ( QgsGeometryCheckerUtils::pointOnLine( *point, testLine, mContext->tolerance ) ) | ||
{ | ||
touches = true; | ||
break; | ||
} | ||
} | ||
if ( touches == true ) | ||
{ | ||
break; | ||
} | ||
} | ||
if ( touches == true ) | ||
{ | ||
continue; | ||
} | ||
errors.append( new QgsGeometryCheckError( this, layerFeature, *point, QgsVertexId( iPart, 0, 0 ) ) ); | ||
} | ||
} | ||
} | ||
|
||
void QgsGeometryPointCoveredByLineCheck::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 QgsGeometryPointCoveredByLineCheck::getResolutionMethods() const | ||
{ | ||
static QStringList methods = QStringList() << tr( "No action" ); | ||
return methods; | ||
} |
38 changes: 38 additions & 0 deletions
38
src/plugins/geometry_checker/checks/qgsgeometrypointcoveredbylinecheck.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 @@ | ||
/*************************************************************************** | ||
qgsgeometrypointcoveredbylinecheck.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 QGSGEOMETRYPOINTCOVEREDBYLINECHECK_H | ||
#define QGSGEOMETRYPOINTCOVEREDBYLINECHECK_H | ||
|
||
#include "qgsgeometrycheck.h" | ||
|
||
class QgsGeometryPointCoveredByLineCheck : public QgsGeometryCheck | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsGeometryPointCoveredByLineCheck( QgsGeometryCheckerContext *context ) | ||
: QgsGeometryCheck( FeatureNodeCheck, {QgsWkbTypes::PointGeometry}, 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( "Point not covered by line" ); } | ||
QString errorName() const override { return QStringLiteral( "QgsGeometryPointCoveredByLineCheck" ); } | ||
private: | ||
enum ResolutionMethod { NoChange }; | ||
}; | ||
|
||
#endif // QGSGEOMETRYPOINTCOVEREDBYLINECHECK_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