Skip to content

Commit 31cc65d

Browse files
committedOct 23, 2017
[Geometry checker] Initial multi-layer support
1 parent e3fc73f commit 31cc65d

File tree

51 files changed

+1488
-1086
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1488
-1086
lines changed
 

‎src/plugins/geometry_checker/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ SET (geometrychecker_SRCS
2020
checks/qgsgeometrysegmentlengthcheck.cpp
2121
checks/qgsgeometryselfcontactcheck.cpp
2222
checks/qgsgeometryselfintersectioncheck.cpp
23+
checks/qgsgeometrysliverpolygoncheck.cpp
2324
checks/qgsgeometrytypecheck.cpp
2425
ui/qgsgeometrycheckerdialog.cpp
2526
ui/qgsgeometrycheckersetuptab.cpp

‎src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,61 +17,68 @@
1717
#include "qgsgeometryutils.h"
1818
#include "../utils/qgsfeaturepool.h"
1919

20-
void QgsGeometryAngleCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &/*messages*/, QAtomicInt *progressCounter, const QgsFeatureIds &ids ) const
20+
void QgsGeometryAngleCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &/*messages*/, QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const
2121
{
22-
const QgsFeatureIds &featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
23-
Q_FOREACH ( QgsFeatureId featureid, featureIds )
22+
QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds() : ids;
23+
for ( const QString &layerId : featureIds.keys() )
2424
{
25-
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
26-
QgsFeature feature;
27-
if ( !mFeaturePool->get( featureid, feature ) )
25+
if ( !getCompatibility( getFeaturePool( layerId )->getLayer()->geometryType() ) )
2826
{
2927
continue;
3028
}
31-
QgsGeometry g = feature.geometry();
32-
const QgsAbstractGeometry *geom = g.geometry();
33-
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
29+
for ( QgsFeatureId featureid : featureIds[layerId] )
3430
{
35-
for ( int iRing = 0, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
31+
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
32+
QgsFeature feature;
33+
if ( !getFeaturePool( layerId )->get( featureid, feature ) )
3634
{
37-
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, iPart, iRing );
38-
// Less than three points, no angles to check
39-
if ( nVerts < 3 )
40-
{
41-
continue;
42-
}
43-
for ( int iVert = 0; iVert < nVerts; ++iVert )
35+
continue;
36+
}
37+
QgsGeometry g = feature.geometry();
38+
const QgsAbstractGeometry *geom = g.geometry();
39+
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
40+
{
41+
for ( int iRing = 0, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
4442
{
45-
const QgsPoint &p1 = geom->vertexAt( QgsVertexId( iPart, iRing, ( iVert - 1 + nVerts ) % nVerts ) );
46-
const QgsPoint &p2 = geom->vertexAt( QgsVertexId( iPart, iRing, iVert ) );
47-
const QgsPoint &p3 = geom->vertexAt( QgsVertexId( iPart, iRing, ( iVert + 1 ) % nVerts ) );
48-
QgsVector v21, v23;
49-
try
43+
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, iPart, iRing );
44+
// Less than three points, no angles to check
45+
if ( nVerts < 3 )
5046
{
51-
v21 = QgsVector( p1.x() - p2.x(), p1.y() - p2.y() ).normalized();
52-
v23 = QgsVector( p3.x() - p2.x(), p3.y() - p2.y() ).normalized();
53-
}
54-
catch ( const QgsException & )
55-
{
56-
// Zero length vectors
5747
continue;
5848
}
59-
60-
double angle = std::acos( v21 * v23 ) / M_PI * 180.0;
61-
if ( angle < mMinAngle )
49+
for ( int iVert = 0; iVert < nVerts; ++iVert )
6250
{
63-
errors.append( new QgsGeometryCheckError( this, featureid, p2, QgsVertexId( iPart, iRing, iVert ), angle ) );
51+
const QgsPoint &p1 = geom->vertexAt( QgsVertexId( iPart, iRing, ( iVert - 1 + nVerts ) % nVerts ) );
52+
const QgsPoint &p2 = geom->vertexAt( QgsVertexId( iPart, iRing, iVert ) );
53+
const QgsPoint &p3 = geom->vertexAt( QgsVertexId( iPart, iRing, ( iVert + 1 ) % nVerts ) );
54+
QgsVector v21, v23;
55+
try
56+
{
57+
v21 = QgsVector( p1.x() - p2.x(), p1.y() - p2.y() ).normalized();
58+
v23 = QgsVector( p3.x() - p2.x(), p3.y() - p2.y() ).normalized();
59+
}
60+
catch ( const QgsException & )
61+
{
62+
// Zero length vectors
63+
continue;
64+
}
65+
66+
double angle = std::acos( v21 * v23 ) / M_PI * 180.0;
67+
if ( angle < mMinAngle )
68+
{
69+
errors.append( new QgsGeometryCheckError( this, layerId, featureid, p2, QgsVertexId( iPart, iRing, iVert ), angle ) );
70+
}
6471
}
6572
}
6673
}
6774
}
6875
}
6976
}
7077

71-
void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError *error, int method, int /*mergeAttributeIndex*/, Changes &changes ) const
78+
void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError *error, int method, const QMap<QString, int> & /*mergeAttributeIndices*/, Changes &changes ) const
7279
{
7380
QgsFeature feature;
74-
if ( !mFeaturePool->get( error->featureId(), feature ) )
81+
if ( !getFeaturePool( error->layerId() )->get( error->featureId(), feature ) )
7582
{
7683
error->setObsolete();
7784
return;
@@ -132,15 +139,15 @@ void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError *error, int method,
132139
}
133140
else
134141
{
135-
changes[error->featureId()].append( Change( ChangeNode, ChangeRemoved, vidx ) );
142+
changes[error->layerId()][error->featureId()].append( Change( ChangeNode, ChangeRemoved, vidx ) );
136143
if ( QgsGeometryUtils::sqrDistance2D( p1, p3 ) < QgsGeometryCheckPrecision::tolerance() * QgsGeometryCheckPrecision::tolerance()
137144
&& QgsGeometryCheckerUtils::canDeleteVertex( geometry, vidx.part, vidx.ring ) &&
138145
geometry->deleteVertex( error->vidx() ) ) // error->vidx points to p3 after removing p2
139146
{
140-
changes[error->featureId()].append( Change( ChangeNode, ChangeRemoved, QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + 1 ) % n ) ) );
147+
changes[error->layerId()][error->featureId()].append( Change( ChangeNode, ChangeRemoved, QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + 1 ) % n ) ) );
141148
}
142149
feature.setGeometry( g );
143-
mFeaturePool->updateFeature( feature );
150+
getFeaturePool( error->layerId() )->updateFeature( feature );
144151
error->setFixed( method );
145152
}
146153
}

0 commit comments

Comments
 (0)
Please sign in to comment.