Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Better error location for missing vertex errors
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 Feb 27, 2019
1 parent c748aac commit 50f8f90
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
Expand Up @@ -135,7 +135,7 @@ void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polyg
const int numRings = polygon->numInteriorRings(); const int numRings = polygon->numInteriorRings();
for ( int i = 0; i < numRings; ++i ) 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 ) ); boundaries->addGeometry( geomEngine->buffer( mContext->tolerance, 5 ) );
} }


Expand Down Expand Up @@ -177,14 +177,36 @@ void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polyg
} }
} }
if ( !alreadyReported ) 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 QString QgsGeometryMissingVertexCheck::id() const
{ {
return factoryId(); return factoryId();
Expand Down Expand Up @@ -236,3 +258,18 @@ QgsGeometryCheck::CheckType QgsGeometryMissingVertexCheck::factoryCheckType()
return QgsGeometryCheck::LayerCheck; return QgsGeometryCheck::LayerCheck;
} }
///@endcond private ///@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; 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 * \ingroup analysis
* *
Expand Down Expand Up @@ -73,6 +110,8 @@ class ANALYSIS_EXPORT QgsGeometryMissingVertexCheck : public QgsGeometryCheck


private: private:
void processPolygon( const QgsCurvePolygon *polygon, QgsFeaturePool *featurePool, QList<QgsGeometryCheckError *> &errors, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, QgsFeedback *feedback ) const; 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 50f8f90

Please sign in to comment.