Skip to content

Commit

Permalink
[Geometry checker] Adapt for API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 23, 2017
1 parent b52b2c5 commit 1642eb1
Show file tree
Hide file tree
Showing 27 changed files with 102 additions and 81 deletions.
6 changes: 4 additions & 2 deletions src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/geometry_checker/checks/qgsgeometryareacheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometrycollection.h"
#include "qgscurvepolygon.h"
#include "qgsgeometrycheck.h"
Expand All @@ -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 )
Expand All @@ -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 )
Expand Down
10 changes: 6 additions & 4 deletions src/plugins/geometry_checker/checks/qgsgeometrycheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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; }
Expand Down Expand Up @@ -165,7 +167,7 @@ class QgsGeometryCheckError
QString mLayerId;
QgsFeatureId mFeatureId;
QgsAbstractGeometry *mGeometry;
QgsPoint mErrorLocation;
QgsPointXY mErrorLocation;
QgsVertexId mVidx;
QVariant mValue;
ValueType mValueType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometryengine.h"
#include "qgsgeometrycontainedcheck.h"
#include "../utils/qgsfeaturepool.h"
Expand All @@ -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() )
{
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometryengine.h"
#include "qgsgeometryduplicatecheck.h"
#include "qgsspatialindex.h"
Expand Down Expand Up @@ -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 ) );
}
}
}
Expand All @@ -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;
Expand All @@ -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 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometryengine.h"
#include "qgsgeometrygapcheck.h"
#include "qgsgeometrycollection.h"
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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;
}
Expand Down Expand Up @@ -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] )
{
Expand Down Expand Up @@ -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 );
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/geometry_checker/checks/qgsgeometryholecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometryengine.h"
#include "qgsgeometryoverlapcheck.h"
#include "../utils/qgsfeaturepool.h"
Expand Down Expand Up @@ -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 ) )
{
Expand Down
Loading

0 comments on commit 1642eb1

Please sign in to comment.