Skip to content

Commit

Permalink
Better error location for missing vertex errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
m-kuhn committed Mar 18, 2019
1 parent 146dca4 commit 0984fc8
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
Expand Up @@ -135,7 +135,7 @@ void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polyg
const int numRings = polygon->numInteriorRings();
for ( int i = 0; i < numRings; ++i )
{
geomEngine = QgsGeometryCheckerUtils::createGeomEngine( polygon->exteriorRing(), mContext->tolerance );
geomEngine = QgsGeometryCheckerUtils::createGeomEngine( polygon->interiorRing( i ), mContext->tolerance );
boundaries->addGeometry( geomEngine->buffer( mContext->tolerance, 5 ) );
}

Expand Down Expand Up @@ -177,14 +177,36 @@ void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polyg
}
}
if ( !alreadyReported )
errors.append( new QgsGeometryCheckError( this, layerFeature, QgsPointXY( pt ) ) );
{
std::unique_ptr<QgsGeometryMissingVertexCheckError> error = qgis::make_unique<QgsGeometryMissingVertexCheckError>( this, layerFeature, QgsPointXY( pt ) );
error->setAffectedAreaBBox( contextBoundingBox( polygon, vertexId, pt ) );

errors.append( error.release() );
}
}
}
}
}
}
}

QgsRectangle QgsGeometryMissingVertexCheck::contextBoundingBox( const QgsCurvePolygon *polygon, const QgsVertexId &vertexId, const QgsPoint &point ) const
{
QgsVertexId vertexBefore;
QgsVertexId vertexAfter;

polygon->adjacentVertices( vertexId, vertexBefore, vertexAfter );

QgsPoint ptBefore = polygon->vertexAt( vertexBefore );
QgsPoint ptAt = polygon->vertexAt( vertexId );
QgsPoint ptAfter = polygon->vertexAt( vertexAfter );

double length = std::abs( ptAt.distance( ptBefore ) ) + std::abs( ptAt.distance( ptAfter ) );

QgsRectangle rect( point.x() - length / 2, point.y() - length / 2, point.x() + length / 2, point.y() + length / 2 );
return rect;
}

QString QgsGeometryMissingVertexCheck::id() const
{
return factoryId();
Expand Down Expand Up @@ -234,3 +256,19 @@ QgsGeometryCheck::CheckType QgsGeometryMissingVertexCheck::factoryCheckType()
{
return QgsGeometryCheck::LayerCheck;
}
///@endcond private

QgsGeometryMissingVertexCheckError::QgsGeometryMissingVertexCheckError( const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsPointXY &errorLocation, QgsVertexId vidx, const QVariant &value, QgsGeometryCheckError::ValueType valueType )
: QgsGeometryCheckError( check, layerFeature, errorLocation, vidx, value, valueType )
{
}

QgsRectangle QgsGeometryMissingVertexCheckError::affectedAreaBBox() const
{
return mAffectedAreaBBox;
}

void QgsGeometryMissingVertexCheckError::setAffectedAreaBBox( const QgsRectangle &affectedAreaBBox )
{
mAffectedAreaBBox = affectedAreaBBox;
}
Expand Up @@ -23,6 +23,43 @@

class QgsCurvePolygon;

/**
* \ingroup analysis
*
* A geometry check error for a missing vertex.
* Includes additional details about the bounding box of the error,
* centered on the missing error location and scaled by taking neighbouring
* vertices into account.
*
* \since QGIS 3.8
*/
class ANALYSIS_EXPORT QgsGeometryMissingVertexCheckError : public QgsGeometryCheckError
{
public:

/**
* Create a new missing vertex check error.
*/
QgsGeometryMissingVertexCheckError( const QgsGeometryCheck *check,
const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
const QgsPointXY &errorLocation,
QgsVertexId vidx = QgsVertexId(),
const QVariant &value = QVariant(),
ValueType valueType = ValueOther );

QgsRectangle affectedAreaBBox() const override;

/**
* Set the bounding box of the affected area.
*
* \since QGIS 3.8
*/
void setAffectedAreaBBox( const QgsRectangle &affectedAreaBBox );

private:
QgsRectangle mAffectedAreaBBox;
};

/**
* \ingroup analysis
*
Expand Down Expand Up @@ -66,6 +103,8 @@ class ANALYSIS_EXPORT QgsGeometryMissingVertexCheck : public QgsGeometryCheck

private:
void processPolygon( const QgsCurvePolygon *polygon, QgsFeaturePool *featurePool, QList<QgsGeometryCheckError *> &errors, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, QgsFeedback *feedback ) const;

QgsRectangle contextBoundingBox( const QgsCurvePolygon *polygon, const QgsVertexId &vertexId, const QgsPoint &point ) const;
};


Expand Down

0 comments on commit 0984fc8

Please sign in to comment.