Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
180 additions
and 3 deletions.
- +2 −0 src/plugins/geometry_checker/CMakeLists.txt
- +79 −0 src/plugins/geometry_checker/checks/qgsgeometrylineintersectioncheck.cpp
- +38 −0 src/plugins/geometry_checker/checks/qgsgeometrylineintersectioncheck.h
- +30 −0 src/plugins/geometry_checker/qgsgeometrycheckfactory.cpp
- +10 −3 src/plugins/geometry_checker/ui/qgsgeometrycheckersetuptab.ui
- +19 −0 src/plugins/geometry_checker/utils/qgsgeometrycheckerutils.cpp
- +2 −0 src/plugins/geometry_checker/utils/qgsgeometrycheckerutils.h
@@ -0,0 +1,79 @@ | ||
/*************************************************************************** | ||
qgsgeometrylineintersectioncheck.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 "qgsgeometrylineintersectioncheck.h" | ||
#include "qgslinestring.h" | ||
|
||
void QgsGeometryLineIntersectionCheck::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 QgsLineString *line = dynamic_cast<const QgsLineString *>( QgsGeometryCheckerUtils::getGeomPart( geom, iPart ) ); | ||
if ( !line ) | ||
{ | ||
// Should not happen | ||
continue; | ||
} | ||
|
||
// Check whether the line intersects with any other lines | ||
QgsGeometryCheckerUtils::LayerFeatures checkFeatures( mContext->featurePools, featureIds.keys(), line->boundingBox(), {QgsWkbTypes::LineGeometry} ); | ||
for ( const QgsGeometryCheckerUtils::LayerFeature &checkFeature : checkFeatures ) | ||
{ | ||
if ( checkFeature.feature().id() == layerFeature.feature().id() ) | ||
{ | ||
// Skip current feature | ||
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; | ||
} | ||
QgsPoint inter; | ||
if ( QgsGeometryCheckerUtils::linesIntersect( line, testLine, mContext->tolerance, inter ) ) | ||
{ | ||
errors.append( new QgsGeometryCheckError( this, layerFeature, inter ) ); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
void QgsGeometryLineIntersectionCheck::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 QgsGeometryLineIntersectionCheck::getResolutionMethods() const | ||
{ | ||
static QStringList methods = QStringList() << tr( "No action" ); | ||
return methods; | ||
} |
@@ -0,0 +1,38 @@ | ||
/*************************************************************************** | ||
qgsgeometrylineintersectioncheck.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 QGSGEOMETRYLINEINTERSECTIONCHECK_H | ||
#define QGSGEOMETRYLINEINTERSECTIONCHECK_H | ||
|
||
#include "qgsgeometrycheck.h" | ||
|
||
class QgsGeometryLineIntersectionCheck : public QgsGeometryCheck | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsGeometryLineIntersectionCheck( 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( "Intersection" ); } | ||
QString errorName() const override { return QStringLiteral( "QgsGeometryLineIntersectionCheck" ); } | ||
private: | ||
enum ResolutionMethod { NoChange }; | ||
}; | ||
|
||
#endif // QGSGEOMETRYLINEINTERSECTIONCHECK_H |