Skip to content
Permalink
Browse files

[Geometry checker] Adapt for API changes

  • Loading branch information
manisandro committed Jun 15, 2017
1 parent b52b2c5 commit 1642eb1601b7e013d02ccb2e1e03b7eca4b9d3a2
Showing with 102 additions and 81 deletions.
  1. +4 −2 src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp
  2. +4 −1 src/plugins/geometry_checker/checks/qgsgeometryareacheck.cpp
  3. +2 −5 src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp
  4. +6 −4 src/plugins/geometry_checker/checks/qgsgeometrycheck.h
  5. +5 −6 src/plugins/geometry_checker/checks/qgsgeometrycontainedcheck.cpp
  6. +1 −1 src/plugins/geometry_checker/checks/qgsgeometrycontainedcheck.h
  7. +4 −1 src/plugins/geometry_checker/checks/qgsgeometrydegeneratepolygoncheck.cpp
  8. +5 −6 src/plugins/geometry_checker/checks/qgsgeometryduplicatecheck.cpp
  9. +1 −1 src/plugins/geometry_checker/checks/qgsgeometryduplicatecheck.h
  10. +6 −3 src/plugins/geometry_checker/checks/qgsgeometryduplicatenodescheck.cpp
  11. +7 −11 src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp
  12. +4 −1 src/plugins/geometry_checker/checks/qgsgeometryholecheck.cpp
  13. +4 −1 src/plugins/geometry_checker/checks/qgsgeometrymultipartcheck.cpp
  14. +2 −5 src/plugins/geometry_checker/checks/qgsgeometryoverlapcheck.cpp
  15. +1 −1 src/plugins/geometry_checker/checks/qgsgeometryoverlapcheck.h
  16. +4 −1 src/plugins/geometry_checker/checks/qgsgeometrysegmentlengthcheck.cpp
  17. +6 −3 src/plugins/geometry_checker/checks/qgsgeometryselfcontactcheck.cpp
  18. +4 −1 src/plugins/geometry_checker/checks/qgsgeometryselfintersectioncheck.cpp
  19. +1 −1 src/plugins/geometry_checker/checks/qgsgeometryselfintersectioncheck.h
  20. +4 −1 src/plugins/geometry_checker/checks/qgsgeometrytypecheck.cpp
  21. +1 −1 src/plugins/geometry_checker/checks/qgsgeometrytypecheck.h
  22. +5 −8 src/plugins/geometry_checker/ui/qgsgeometrycheckerresulttab.cpp
  23. +4 −2 src/plugins/geometry_checker/ui/qgsgeometrycheckersetuptab.cpp
  24. +2 −1 src/plugins/geometry_checker/utils/qgsfeaturepool.cpp
  25. +4 −2 src/plugins/geometry_checker/utils/qgsfeaturepool.h
  26. +7 −8 src/plugins/geometry_checker/utils/qgsgeometrycheckerutils.cpp
  27. +4 −3 src/plugins/geometry_checker/utils/qgsgeometrycheckerutils.h
@@ -51,11 +51,13 @@ void QgsGeometryAngleCheck::collectErrors( QList<QgsGeometryCheckError *> &error
continue;
}

double angle = std::acos( v21 * v23 ) / M_PI * 180.0;
double angle = qAcos( v21 * v23 ) / M_PI * 180.0;
if ( angle < mMinAngle )
{
QgsAbstractGeometry *part = QgsGeometryCheckerUtils::getGeomPart( geom, iPart )->clone();
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), part, p2, QgsVertexId( iPart, iRing, iVert ), angle ) );
part->transform( layerFeature.mapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );
QgsPointXY pos = layerFeature.mapToLayerTransform().transform( p2, QgsCoordinateTransform::ReverseTransform );
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), part, pos, QgsVertexId( iPart, iRing, iVert ), angle ) );
}
}
}
@@ -44,7 +44,10 @@ void QgsGeometryAreaCheck::collectErrors( QList<QgsGeometryCheckError *> &errors
double value;
if ( checkThreshold( mapToLayerUnits, geom, value ) )
{
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), geom->clone(), geom->centroid(), QgsVertexId( 0 ), value / ( mapToLayerUnits * mapToLayerUnits ), QgsGeometryCheckError::ValueArea ) );
QgsAbstractGeometry *g = geom->clone();
g->transform( layerFeature.mapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );
QgsPoint pos = g->centroid();
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), g, pos, QgsVertexId( 0 ), value / ( mapToLayerUnits * mapToLayerUnits ), QgsGeometryCheckError::ValueArea ) );
}
}
}
@@ -13,7 +13,6 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometrycollection.h"
#include "qgscurvepolygon.h"
#include "qgsgeometrycheck.h"
@@ -30,7 +29,7 @@ QgsGeometryCheckerContext::QgsGeometryCheckerContext( int _precision, const QStr

QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check, const QString &layerId,
QgsFeatureId featureId, QgsAbstractGeometry *geometry,
const QgsPoint &errorLocation,
const QgsPointXY &errorLocation,
QgsVertexId vidx,
const QVariant &value, ValueType valueType )
: mCheck( check )
@@ -47,9 +46,7 @@ QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check, con

QgsRectangle QgsGeometryCheckError::affectedAreaBBox() const
{
QString srcCrs = mCheck->getContext()->featurePools[ layerId() ]->getLayer()->crs().authid();
QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( srcCrs, mCheck->getContext()->mapCrs );
return t.transformBoundingBox( mGeometry->boundingBox() );
return mGeometry->boundingBox();
}

bool QgsGeometryCheckError::handleChanges( const QgsGeometryCheck::Changes &changes )
@@ -99,7 +99,7 @@ class QgsGeometryCheckError
const QString &layerId,
QgsFeatureId featureId,
QgsAbstractGeometry *geometry,
const QgsPoint &errorLocation,
const QgsPointXY &errorLocation,
QgsVertexId vidx = QgsVertexId(),
const QVariant &value = QVariant(),
ValueType valueType = ValueOther );
@@ -113,11 +113,13 @@ class QgsGeometryCheckError
const QgsGeometryCheck *check() const { return mCheck; }
const QString &layerId() const { return mLayerId; }
QgsFeatureId featureId() const { return mFeatureId; }
QgsAbstractGeometry *geometry() const { return mGeometry; }
// In map units
const QgsAbstractGeometry *geometry() const { return mGeometry; }
// In map units
virtual QgsRectangle affectedAreaBBox() const;
virtual QString description() const { return mCheck->errorDescription(); }
const QgsPoint &location() const { return mErrorLocation; }
// In map units
const QgsPointXY &location() const { return mErrorLocation; }
// Lengths, areas in map units
QVariant value() const { return mValue; }
ValueType valueType() const { return mValueType; }
@@ -165,7 +167,7 @@ class QgsGeometryCheckError
QString mLayerId;
QgsFeatureId mFeatureId;
QgsAbstractGeometry *mGeometry;
QgsPoint mErrorLocation;
QgsPointXY mErrorLocation;
QgsVertexId mVidx;
QVariant mValue;
ValueType mValueType;
@@ -13,7 +13,6 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometryengine.h"
#include "qgsgeometrycontainedcheck.h"
#include "../utils/qgsfeaturepool.h"
@@ -32,7 +31,9 @@ void QgsGeometryContainedCheck::collectErrors( QList<QgsGeometryCheckError *> &e
QString errMsg;
if ( geomEngineA->within( *layerFeatureB.geometry(), &errMsg ) )
{
errors.append( new QgsGeometryContainedCheckError( this, layerFeatureA.layer().id(), layerFeatureA.feature().id(), layerFeatureA.geometry()->clone(), layerFeatureA.geometry()->centroid(), qMakePair( layerFeatureB.layer().id(), layerFeatureB.feature().id() ) ) );
QgsAbstractGeometry *g = layerFeatureA.geometry()->clone();
QgsPoint pos = g->centroid();
errors.append( new QgsGeometryContainedCheckError( this, layerFeatureA.layer().id(), layerFeatureA.feature().id(), g, pos, qMakePair( layerFeatureB.layer().id(), layerFeatureB.feature().id() ) ) );
}
else if ( !errMsg.isEmpty() )
{
@@ -56,16 +57,14 @@ void QgsGeometryContainedCheck::fixError( QgsGeometryCheckError *error, int meth
error->setObsolete();
return;
}
QgsCoordinateTransform crstA = QgsCoordinateTransformCache::instance()->transform( featurePoolA->getLayer()->crs().authid(), mContext->mapCrs );
QgsCoordinateTransform crstB = QgsCoordinateTransformCache::instance()->transform( featurePoolB->getLayer()->crs().authid(), mContext->mapCrs );

// Check if error still applies
QgsAbstractGeometry *featureGeomA = featureA.geometry().geometry()->clone();
featureGeomA->transform( crstA );
featureGeomA->transform( featurePoolA->getMapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );
QSharedPointer<QgsGeometryEngine> geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( featureGeomA, mContext->tolerance );

QgsAbstractGeometry *featureGeomB = featureB.geometry().geometry()->clone();
featureGeomB->transform( crstB );
featureGeomB->transform( featurePoolB->getMapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );

bool within = geomEngineA->within( *featureGeomB );
delete featureGeomA;
@@ -25,7 +25,7 @@ class QgsGeometryContainedCheckError : public QgsGeometryCheckError
const QString &layerId,
QgsFeatureId featureId,
QgsAbstractGeometry *geometry,
const QgsPoint &errorLocation,
const QgsPointXY &errorLocation,
const QPair<QString, QgsFeatureId> &containingFeature
)
: QgsGeometryCheckError( check, layerId, featureId, geometry, errorLocation, QgsVertexId(), QString( "%1:%2" ).arg( containingFeature.first ).arg( containingFeature.second ), ValueOther )
@@ -29,7 +29,10 @@ void QgsGeometryDegeneratePolygonCheck::collectErrors( QList<QgsGeometryCheckErr
{
if ( QgsGeometryCheckerUtils::polyLineSize( geom, iPart, iRing ) < 3 )
{
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), geom->clone(), geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) ), QgsVertexId( iPart, iRing ) ) );
QgsAbstractGeometry *g = geom->clone();
g->transform( layerFeature.mapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );
QgsPointXY pos = layerFeature.mapToLayerTransform().transform( geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) ), QgsCoordinateTransform::ReverseTransform );
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), g, pos, QgsVertexId( iPart, iRing ) ) );
}
}
}
@@ -13,7 +13,6 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometryengine.h"
#include "qgsgeometryduplicatecheck.h"
#include "qgsspatialindex.h"
@@ -56,7 +55,9 @@ void QgsGeometryDuplicateCheck::collectErrors( QList<QgsGeometryCheckError *> &e
}
if ( !duplicates.isEmpty() )
{
errors.append( new QgsGeometryDuplicateCheckError( this, layerFeatureA.layer().id(), layerFeatureA.feature().id(), layerFeatureA.geometry()->clone(), layerFeatureA.geometry()->centroid(), duplicates ) );
QgsAbstractGeometry *g = layerFeatureA.geometry()->clone();
QgsPoint pos = g->centroid();
errors.append( new QgsGeometryDuplicateCheckError( this, layerFeatureA.layer().id(), layerFeatureA.feature().id(), g, pos, duplicates ) );
}
}
}
@@ -77,16 +78,14 @@ void QgsGeometryDuplicateCheck::fixError( QgsGeometryCheckError *error, int meth
}
else if ( method == RemoveDuplicates )
{
QgsCoordinateTransform crstA = QgsCoordinateTransformCache::instance()->transform( featurePoolA->getLayer()->crs().authid(), mContext->mapCrs );
QgsAbstractGeometry *featureGeomA = featureA.geometry().geometry()->clone();
featureGeomA->transform( crstA );
featureGeomA->transform( featurePoolA->getMapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );
QSharedPointer<QgsGeometryEngine> geomEngine = QgsGeometryCheckerUtils::createGeomEngine( featureGeomA, mContext->tolerance );

QgsGeometryDuplicateCheckError *duplicateError = static_cast<QgsGeometryDuplicateCheckError *>( error );
for ( const QString &layerIdB : duplicateError->duplicates().keys() )
{
QgsFeaturePool *featurePoolB = mContext->featurePools[ layerIdB ];
QgsCoordinateTransform crstB = QgsCoordinateTransformCache::instance()->transform( featurePoolB->getLayer()->crs().authid(), mContext->mapCrs );
for ( QgsFeatureId idB : duplicateError->duplicates()[layerIdB] )
{
QgsFeature featureB;
@@ -95,7 +94,7 @@ void QgsGeometryDuplicateCheck::fixError( QgsGeometryCheckError *error, int meth
continue;
}
QgsAbstractGeometry *featureGeomB = featureB.geometry().geometry()->clone();
featureGeomB->transform( crstB );
featureGeomB->transform( featurePoolB->getMapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );
QgsAbstractGeometry *diffGeom = geomEngine->symDifference( *featureGeomB );
if ( diffGeom && diffGeom->area() < mContext->tolerance )
{
@@ -25,7 +25,7 @@ class QgsGeometryDuplicateCheckError : public QgsGeometryCheckError
const QString &layerId,
QgsFeatureId featureId,
QgsAbstractGeometry *geometry,
const QgsPoint &errorLocation,
const QgsPointXY &errorLocation,
const QMap<QString, QList<QgsFeatureId>> &duplicates )
: QgsGeometryCheckError( check, layerId, featureId, geometry, errorLocation, QgsVertexId(), duplicatesString( duplicates ) )
, mDuplicates( duplicates )
@@ -33,11 +33,14 @@ void QgsGeometryDuplicateNodesCheck::collectErrors( QList<QgsGeometryCheckError
continue;
for ( int iVert = nVerts - 1, jVert = 0; jVert < nVerts; iVert = jVert++ )
{
QgsPointV2 pi = geom->vertexAt( QgsVertexId( iPart, iRing, iVert ) );
QgsPointV2 pj = geom->vertexAt( QgsVertexId( iPart, iRing, jVert ) );
QgsPoint pi = geom->vertexAt( QgsVertexId( iPart, iRing, iVert ) );
QgsPoint pj = geom->vertexAt( QgsVertexId( iPart, iRing, jVert ) );
if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) < mContext->tolerance )
{
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), geom->clone(), pj, QgsVertexId( iPart, iRing, jVert ) ) );
QgsAbstractGeometry *g = geom->clone();
g->transform( layerFeature.mapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );
QgsPointXY pos = layerFeature.mapToLayerTransform().transform( pj, QgsCoordinateTransform::ReverseTransform );
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), g, pos, QgsVertexId( iPart, iRing, jVert ) ) );
}
}
}
@@ -13,7 +13,6 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometryengine.h"
#include "qgsgeometrygapcheck.h"
#include "qgsgeometrycollection.h"
@@ -100,12 +99,11 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors,
for ( const QString &layerId : featureIds.keys() )
{
QgsFeaturePool *featurePool = mContext->featurePools[ layerId ];
QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( mContext->mapCrs, featurePool->getLayer()->crs().authid() );
QgsRectangle gapAreaLayerBBox = t.transform( gapGeom->boundingBox() ); // Don't use gapAreaBBox since it is updated below
QgsRectangle gapAreaLayerBBox = featurePool->getMapToLayerTransform().transform( gapGeom->boundingBox() ); // Don't use gapAreaBBox since it is updated below

QgsFeatureIds intersectIds = featurePool->getIntersects( gapAreaLayerBBox );
QgsAbstractGeometry *gapLayerGeom = gapGeom->clone();
gapLayerGeom->transform( t );
gapLayerGeom->transform( featurePool->getMapToLayerTransform() );

for ( QgsFeatureId id : intersectIds )
{
@@ -118,9 +116,9 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors,
if ( QgsGeometryCheckerUtils::sharedEdgeLength( gapLayerGeom, featureGeom, mContext->reducedTolerance ) > 0 )
{
neighboringIds[layerId].insert( feature.id() );
gapAreaLayerBBox.unionRect( featureGeom->boundingBox() );
gapAreaLayerBBox.combineExtentWith( featureGeom->boundingBox() );
}
gapAreaBBox.unionRect( t.transform( gapAreaLayerBBox, QgsCoordinateTransform::ReverseTransform ) );
gapAreaBBox.combineExtentWith( featurePool->getMapToLayerTransform().transform( gapAreaLayerBBox, QgsCoordinateTransform::ReverseTransform ) );
}
delete gapLayerGeom;
}
@@ -170,15 +168,14 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError *err, Chan
QgsFeature mergeFeature;
int mergePartIdx = -1;

QgsAbstractGeometry *errGeometry = QgsGeometryCheckerUtils::getGeomPart( err->geometry(), 0 );
const QgsAbstractGeometry *errGeometry = QgsGeometryCheckerUtils::getGeomPart( err->geometry(), 0 );

// Search for touching neighboring geometries
for ( const QString &layerId : err->neighbors().keys() )
{
QgsFeaturePool *featurePool = mContext->featurePools[ err->layerId() ];
QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( mContext->mapCrs, featurePool->getLayer()->crs().authid() );
QgsAbstractGeometry *errLayerGeom = errGeometry->clone();
errLayerGeom->transform( t );
errLayerGeom->transform( featurePool->getMapToLayerTransform() );

for ( QgsFeatureId testId : err->neighbors()[layerId] )
{
@@ -211,9 +208,8 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError *err, Chan

// Merge geometries
QgsFeaturePool *featurePool = mContext->featurePools[ mergeLayerId ];
QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( mContext->mapCrs, featurePool->getLayer()->crs().authid() );
QgsAbstractGeometry *errLayerGeom = errGeometry->clone();
errLayerGeom->transform( t );
errLayerGeom->transform( featurePool->getMapToLayerTransform() );
QgsGeometry mergeFeatureGeom = mergeFeature.geometry();
QgsAbstractGeometry *mergeGeom = mergeFeatureGeom.geometry();
QSharedPointer<QgsGeometryEngine> geomEngine = QgsGeometryCheckerUtils::createGeomEngine( errLayerGeom, mContext->tolerance );
@@ -28,7 +28,10 @@ void QgsGeometryHoleCheck::collectErrors( QList<QgsGeometryCheckError *> &errors
// Rings after the first one are interiors
for ( int iRing = 1, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
{
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), geom->clone(), QgsGeometryCheckerUtils::getGeomPart( geom, iPart )->centroid(), QgsVertexId( iPart, iRing ) ) );
QgsAbstractGeometry *g = geom->clone();
g->transform( layerFeature.mapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );
QgsPointXY pos = layerFeature.mapToLayerTransform().transform( QgsGeometryCheckerUtils::getGeomPart( geom, iPart )->centroid(), QgsCoordinateTransform::ReverseTransform );
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), g, pos, QgsVertexId( iPart, iRing ) ) );
}
}
}
@@ -26,7 +26,10 @@ void QgsGeometryMultipartCheck::collectErrors( QList<QgsGeometryCheckError *> &e
QgsWkbTypes::Type type = geom->wkbType();
if ( geom->partCount() == 1 && QgsWkbTypes::isMultiType( type ) )
{
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), geom->clone(), geom->centroid() ) );
QgsAbstractGeometry *g = geom->clone();
g->transform( layerFeature.mapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );
QgsPoint pos = g->centroid();
errors.append( new QgsGeometryCheckError( this, layerFeature.layer().id(), layerFeature.feature().id(), g, pos ) );
}
}
}
@@ -13,7 +13,6 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometryengine.h"
#include "qgsgeometryoverlapcheck.h"
#include "../utils/qgsfeaturepool.h"
@@ -81,16 +80,14 @@ void QgsGeometryOverlapCheck::fixError( QgsGeometryCheckError *error, int method
error->setObsolete();
return;
}
QgsCoordinateTransform crstA = QgsCoordinateTransformCache::instance()->transform( featurePoolA->getLayer()->crs().authid(), mContext->mapCrs );
QgsCoordinateTransform crstB = QgsCoordinateTransformCache::instance()->transform( featurePoolB->getLayer()->crs().authid(), mContext->mapCrs );

// Check if error still applies
QgsAbstractGeometry *featureGeomA = featureA.geometry().geometry()->clone();
featureGeomA->transform( crstA );
featureGeomA->transform( featurePoolA->getMapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );
QSharedPointer<QgsGeometryEngine> geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( featureGeomA, mContext->reducedTolerance );

QgsAbstractGeometry *featureGeomB = featureB.geometry().geometry()->clone();
featureGeomB->transform( crstB );
featureGeomB->transform( featurePoolB->getMapToLayerTransform(), QgsCoordinateTransform::ReverseTransform );

if ( !geomEngineA->overlaps( *featureGeomB ) )
{

0 comments on commit 1642eb1

Please sign in to comment.
You can’t perform that action at this time.