Skip to content

Commit

Permalink
[Geometry checker] QgsGeomUtils -> QgsGeometryCheckerUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Jul 14, 2016
1 parent 97861cd commit 54e424f
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 66 deletions.
4 changes: 2 additions & 2 deletions src/plugins/geometry_checker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ SET (geometrychecker_SRCS
ui/qgsgeometrycheckfixdialog.cpp
ui/qgsgeometrycheckerfixsummarydialog.cpp
utils/qgsfeaturepool.cpp
utils/qgsgeomutils.cpp
utils/qgsgeometrycheckerutils.cpp
)

SET (geometrychecker_HDRS
checks/qgsgeometrycheck.h
qgsgeometrycheckerplugin.h
qgsgeometrycheckfactory.h
utils/qgsfeaturepool.h
utils/qgsgeomutils.h
utils/qgsgeometrycheckerutils.h
)

SET (geometrychecker_MOC_HDRS
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void QgsGeometryAngleCheck::collectErrors( QList<QgsGeometryCheckError*>& errors
{
for ( int iRing = 0, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
{
int nVerts = QgsGeomUtils::polyLineSize( geom, iPart, iRing );
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, iPart, iRing );
// Less than three points, no angles to check
if ( nVerts < 3 )
{
Expand Down Expand Up @@ -85,7 +85,7 @@ void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError* error, int method,
}

// Check if error still applies
int n = QgsGeomUtils::polyLineSize( geometry, vidx.part, vidx.ring );
int n = QgsGeometryCheckerUtils::polyLineSize( geometry, vidx.part, vidx.ring );
const QgsPointV2& p1 = geometry->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex - 1 + n ) % n ) );
const QgsPointV2& p2 = geometry->vertexAt( vidx );
const QgsPointV2& p3 = geometry->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + 1 ) % n ) );
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/geometry_checker/checks/qgsgeometryareacheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( QgsFeature& feature, int partIdx,
{
continue;
}
double len = QgsGeomUtils::sharedEdgeLength( QgsGeomUtils::getGeomPart( geom, partIdx ), QgsGeomUtils::getGeomPart( testGeom, testPartIdx ), QgsGeometryCheckPrecision::reducedTolerance() );
double len = QgsGeometryCheckerUtils::sharedEdgeLength( QgsGeometryCheckerUtils::getGeomPart( geom, partIdx ), QgsGeometryCheckerUtils::getGeomPart( testGeom, testPartIdx ), QgsGeometryCheckPrecision::reducedTolerance() );
if ( len > 0. )
{
if ( method == MergeLongestEdge || method == MergeLargestArea )
Expand Down Expand Up @@ -192,8 +192,8 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( QgsFeature& feature, int partIdx,

// Merge geometries
QgsAbstractGeometryV2* mergeGeom = mergeFeature.geometry()->geometry();
QgsGeometryEngine* geomEngine = QgsGeomUtils::createGeomEngine( QgsGeomUtils::getGeomPart( mergeGeom, mergePartIdx ), QgsGeometryCheckPrecision::tolerance() );
QgsAbstractGeometryV2* combinedGeom = geomEngine->combine( *QgsGeomUtils::getGeomPart( geom, partIdx ), &errMsg );
QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( QgsGeometryCheckerUtils::getGeomPart( mergeGeom, mergePartIdx ), QgsGeometryCheckPrecision::tolerance() );
QgsAbstractGeometryV2* combinedGeom = geomEngine->combine( *QgsGeometryCheckerUtils::getGeomPart( geom, partIdx ), &errMsg );
delete geomEngine;
if ( !combinedGeom || combinedGeom->isEmpty() )
{
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ QgsAbstractGeometryV2 *QgsGeometryCheckError::geometry()
if ( mCheck->getFeaturePool()->get( featureId(), f ) && f.geometry() )
{
QgsAbstractGeometryV2* geom = f.geometry()->geometry();
return mVidx.part >= 0 ? QgsGeomUtils::getGeomPart( geom, mVidx.part )->clone() : geom->clone();
return mVidx.part >= 0 ? QgsGeometryCheckerUtils::getGeomPart( geom, mVidx.part )->clone() : geom->clone();
}
return nullptr;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ void QgsGeometryCheck::deleteFeatureGeometryPart( QgsFeature &feature, int partI

void QgsGeometryCheck::deleteFeatureGeometryRing( QgsFeature &feature, int partIdx, int ringIdx, Changes &changes ) const
{
QgsAbstractGeometryV2* partGeom = QgsGeomUtils::getGeomPart( feature.geometry()->geometry(), partIdx );
QgsAbstractGeometryV2* partGeom = QgsGeometryCheckerUtils::getGeomPart( feature.geometry()->geometry(), partIdx );
if ( dynamic_cast<QgsCurvePolygonV2*>( partGeom ) )
{
// If we delete the exterior ring of a polygon, it makes no sense to keep the interiors
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/geometry_checker/checks/qgsgeometrycheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "qgsfeature.h"
#include "qgsvectorlayer.h"
#include "geometry/qgsgeometry.h"
#include "../utils/qgsgeomutils.h"
#include "../utils/qgsgeometrycheckerutils.h"
#include "geos_c.h"
#include <QApplication>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void QgsGeometryContainedCheck::collectErrors( QList<QgsGeometryCheckError*>& er
continue;
}

QgsGeometryEngine* geomEngine = QgsGeomUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );
QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );

QgsFeatureIds ids = mFeaturePool->getIntersects( feature.geometry()->geometry()->boundingBox() );
Q_FOREACH ( QgsFeatureId otherid, ids )
Expand Down Expand Up @@ -72,7 +72,7 @@ void QgsGeometryContainedCheck::fixError( QgsGeometryCheckError* error, int meth
}

// Check if error still applies
QgsGeometryEngine* geomEngine = QgsGeomUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );
QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );

if ( !geomEngine->within( *otherFeature.geometry()->geometry() ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void QgsGeometryDegeneratePolygonCheck::collectErrors( QList<QgsGeometryCheckErr
{
for ( int iRing = 0, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
{
if ( QgsGeomUtils::polyLineSize( geom, iPart, iRing ) < 3 )
if ( QgsGeometryCheckerUtils::polyLineSize( geom, iPart, iRing ) < 3 )
{
errors.append( new QgsGeometryCheckError( this, featureid, geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) ), QgsVertexId( iPart, iRing ) ) );
}
Expand Down Expand Up @@ -60,7 +60,7 @@ void QgsGeometryDegeneratePolygonCheck::fixError( QgsGeometryCheckError* error,
}

// Check if error still applies
if ( QgsGeomUtils::polyLineSize( geom, vidx.part, vidx.ring ) >= 3 )
if ( QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring ) >= 3 )
{
error->setObsolete();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void QgsGeometryDuplicateCheck::collectErrors( QList<QgsGeometryCheckError*>& er
{
continue;
}
QgsGeometryEngine* geomEngine = QgsGeomUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );
QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );

QList<QgsFeatureId> duplicates;
QgsFeatureIds ids = mFeaturePool->getIntersects( feature.geometry()->geometry()->boundingBox() );
Expand Down Expand Up @@ -82,7 +82,7 @@ void QgsGeometryDuplicateCheck::fixError( QgsGeometryCheckError* error, int meth
}
else if ( method == RemoveDuplicates )
{
QgsGeometryEngine* geomEngine = QgsGeomUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );
QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );

QgsGeometryDuplicateCheckError* duplicateError = static_cast<QgsGeometryDuplicateCheckError*>( error );
Q_FOREACH ( QgsFeatureId id, duplicateError->duplicates() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void QgsGeometryDuplicateNodesCheck::collectErrors( QList<QgsGeometryCheckError*
{
for ( int iRing = 0, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
{
int nVerts = QgsGeomUtils::polyLineSize( geom, iPart, iRing );
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, iPart, iRing );
if ( nVerts < 2 )
continue;
for ( int iVert = nVerts - 1, jVert = 0; jVert < nVerts; iVert = jVert++ )
Expand Down Expand Up @@ -70,7 +70,7 @@ void QgsGeometryDuplicateNodesCheck::fixError( QgsGeometryCheckError* error, int
}

// Check if error still applies
int nVerts = QgsGeomUtils::polyLineSize( geom, vidx.part, vidx.ring );
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring );
QgsPointV2 pi = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + nVerts - 1 ) % nVerts ) );
QgsPointV2 pj = geom->vertexAt( error->vidx() );
if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) >= QgsGeometryCheckPrecision::tolerance() * QgsGeometryCheckPrecision::tolerance() )
Expand All @@ -87,7 +87,7 @@ void QgsGeometryDuplicateNodesCheck::fixError( QgsGeometryCheckError* error, int
else if ( method == RemoveDuplicates )
{
geom->deleteVertex( error->vidx() );
if ( QgsGeomUtils::polyLineSize( geom, vidx.part, vidx.ring ) < 3 )
if ( QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring ) < 3 )
{
error->setFixFailed( tr( "Resulting geometry is degenerate" ) );
}
Expand Down
20 changes: 10 additions & 10 deletions src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError*>& errors,
return;
}

QgsGeometryEngine* geomEngine = QgsGeomUtils::createGeomEngine( nullptr, QgsGeometryCheckPrecision::tolerance() );
QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( nullptr, QgsGeometryCheckPrecision::tolerance() );

// Create union of geometry
QString errMsg;
Expand All @@ -55,7 +55,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError*>& errors,
}

// Get envelope of union
geomEngine = QgsGeomUtils::createGeomEngine( unionGeom, QgsGeometryCheckPrecision::tolerance() );
geomEngine = QgsGeometryCheckerUtils::createGeomEngine( unionGeom, QgsGeometryCheckPrecision::tolerance() );
QgsAbstractGeometryV2* envelope = geomEngine->envelope( &errMsg );
delete geomEngine;
if ( !envelope )
Expand All @@ -66,14 +66,14 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError*>& errors,
}

// Buffer envelope
geomEngine = QgsGeomUtils::createGeomEngine( envelope, QgsGeometryCheckPrecision::tolerance() );
geomEngine = QgsGeometryCheckerUtils::createGeomEngine( envelope, QgsGeometryCheckPrecision::tolerance() );
QgsAbstractGeometryV2* bufEnvelope = geomEngine->buffer( 2, 0, GEOSBUF_CAP_SQUARE, GEOSBUF_JOIN_MITRE, 4. );
delete geomEngine;
delete envelope;
envelope = bufEnvelope;

// Compute difference between envelope and union to obtain gap polygons
geomEngine = QgsGeomUtils::createGeomEngine( envelope, QgsGeometryCheckPrecision::tolerance() );
geomEngine = QgsGeometryCheckerUtils::createGeomEngine( envelope, QgsGeometryCheckPrecision::tolerance() );
QgsAbstractGeometryV2* diffGeom = geomEngine->difference( *unionGeom, &errMsg );
delete geomEngine;
if ( !diffGeom )
Expand All @@ -87,7 +87,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError*>& errors,
// For each gap polygon which does not lie on the boundary, get neighboring polygons and add error
for ( int iPart = 0, nParts = diffGeom->partCount(); iPart < nParts; ++iPart )
{
QgsAbstractGeometryV2* geom = QgsGeomUtils::getGeomPart( diffGeom, iPart );
QgsAbstractGeometryV2* geom = QgsGeometryCheckerUtils::getGeomPart( diffGeom, iPart );
// Skip the gap between features and boundingbox
if ( geom->boundingBox() == envelope->boundingBox() )
{
Expand All @@ -113,7 +113,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError*>& errors,
continue;
}
QgsAbstractGeometryV2* geom2 = feature.geometry()->geometry();
if ( QgsGeomUtils::sharedEdgeLength( geom, geom2, QgsGeometryCheckPrecision::reducedTolerance() ) > 0 )
if ( QgsGeometryCheckerUtils::sharedEdgeLength( geom, geom2, QgsGeometryCheckPrecision::reducedTolerance() ) > 0 )
{
neighboringIds.insert( feature.id() );
gapAreaBBox.unionRect( geom2->boundingBox() );
Expand Down Expand Up @@ -164,7 +164,7 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError* err, Chan
QgsFeature mergeFeature;
int mergePartIdx = -1;

QgsAbstractGeometryV2* errGeometry = QgsGeomUtils::getGeomPart( err->geometry(), 0 );
QgsAbstractGeometryV2* errGeometry = QgsGeometryCheckerUtils::getGeomPart( err->geometry(), 0 );

// Search for touching neighboring geometries
Q_FOREACH ( QgsFeatureId testId, err->neighbors() )
Expand All @@ -177,7 +177,7 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError* err, Chan
QgsAbstractGeometryV2* testGeom = testFeature.geometry()->geometry();
for ( int iPart = 0, nParts = testGeom->partCount(); iPart < nParts; ++iPart )
{
double len = QgsGeomUtils::sharedEdgeLength( errGeometry, QgsGeomUtils::getGeomPart( testGeom, iPart ), QgsGeometryCheckPrecision::reducedTolerance() );
double len = QgsGeometryCheckerUtils::sharedEdgeLength( errGeometry, QgsGeometryCheckerUtils::getGeomPart( testGeom, iPart ), QgsGeometryCheckPrecision::reducedTolerance() );
if ( len > maxVal )
{
maxVal = len;
Expand All @@ -194,8 +194,8 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError* err, Chan

// Merge geometries
QgsAbstractGeometryV2* mergeGeom = mergeFeature.geometry()->geometry();
QgsGeometryEngine* geomEngine = QgsGeomUtils::createGeomEngine( errGeometry, QgsGeometryCheckPrecision::tolerance() );
QgsAbstractGeometryV2* combinedGeom = geomEngine->combine( *QgsGeomUtils::getGeomPart( mergeGeom, mergePartIdx ), &errMsg );
QgsGeometryEngine* geomEngine = QgsGeometryCheckerUtils::createGeomEngine( errGeometry, QgsGeometryCheckPrecision::tolerance() );
QgsAbstractGeometryV2* combinedGeom = geomEngine->combine( *QgsGeometryCheckerUtils::getGeomPart( mergeGeom, mergePartIdx ), &errMsg );
delete geomEngine;
if ( !combinedGeom || combinedGeom->isEmpty() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/geometry_checker/checks/qgsgeometrygapcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class QgsGeometryGapCheckError : public QgsGeometryCheckError
bool isEqual( QgsGeometryCheckError* other ) const override
{
QgsGeometryGapCheckError* err = dynamic_cast<QgsGeometryGapCheckError*>( other );
return err && QgsGeomUtils::pointsFuzzyEqual( err->location(), location(), QgsGeometryCheckPrecision::reducedTolerance() ) && err->neighbors() == neighbors();
return err && QgsGeometryCheckerUtils::pointsFuzzyEqual( err->location(), location(), QgsGeometryCheckPrecision::reducedTolerance() ) && err->neighbors() == neighbors();
}

bool closeMatch( QgsGeometryCheckError *other ) const override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ 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, featureid, QgsGeomUtils::getGeomPart( geom, iPart )->centroid(), QgsVertexId( iPart, iRing ) ) );
errors.append( new QgsGeometryCheckError( this, featureid, QgsGeometryCheckerUtils::getGeomPart( geom, iPart )->centroid(), QgsVertexId( iPart, iRing ) ) );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void QgsGeometryMultipartCheck::fixError( QgsGeometryCheckError* error, int meth
}
else if ( method == ConvertToSingle )
{
feature.setGeometry( new QgsGeometry( QgsGeomUtils::getGeomPart( geom, 0 )->clone() ) );
feature.setGeometry( new QgsGeometry( QgsGeometryCheckerUtils::getGeomPart( geom, 0 )->clone() ) );
mFeaturePool->updateFeature( feature );
error->setFixed( method );
changes[feature.id()].append( Change( ChangeFeature, ChangeChanged ) );
Expand Down
Loading

0 comments on commit 54e424f

Please sign in to comment.