Skip to content

Commit

Permalink
Use implicitly shared QgsGeometry
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Sep 11, 2018
1 parent 6ab1aa7 commit b60cf05
Show file tree
Hide file tree
Showing 26 changed files with 70 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void QgsGeometryAngleCheck::collectErrors( QList<QgsGeometryCheckError *> &error
QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds, mCompatibleGeometryTypes, progressCounter, context() );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
const QgsAbstractGeometry *geom = layerFeature.geometry();
const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
for ( int iRing = 0, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void QgsGeometryAreaCheck::collectErrors( QList<QgsGeometryCheckError *> &errors
QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds, mCompatibleGeometryTypes, progressCounter, mContext );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
const QgsAbstractGeometry *geom = layerFeature.geometry();
const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();
double layerToMapUnits = mContext->layerScaleFactor( layerFeature.layer() );
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
Expand Down
12 changes: 6 additions & 6 deletions src/analysis/vector/geometry_checker/qgsgeometrycheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ double QgsGeometryCheckerContext::layerScaleFactor( const QPointer<QgsVectorLaye
}

QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check, const QString &layerId,
QgsFeatureId featureId, QgsAbstractGeometry *geometry,
QgsFeatureId featureId, const QgsGeometry &geometry,
const QgsPointXY &errorLocation,
QgsVertexId vidx,
const QVariant &value, ValueType valueType )
Expand Down Expand Up @@ -103,28 +103,28 @@ QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check,
{
if ( vidx.part != -1 )
{
mGeometry.reset( QgsGeometryCheckerUtils::getGeomPart( layerFeature.geometry(), vidx.part )->clone() );
mGeometry = QgsGeometry( QgsGeometryCheckerUtils::getGeomPart( layerFeature.geometry().constGet(), vidx.part )->clone() );
}
else
{
mGeometry.reset( layerFeature.geometry()->clone() );
mGeometry = layerFeature.geometry();
}
if ( !layerFeature.useMapCrs() )
{
const QgsCoordinateTransform &transform = check->context()->layerTransform( layerFeature.layer() );
mGeometry->transform( transform );
mGeometry.transform( transform );
mErrorLocation = transform.transform( mErrorLocation );
}
}

const QgsAbstractGeometry *QgsGeometryCheckError::geometry() const
{
return mGeometry.get();
return mGeometry.constGet();
}

QgsRectangle QgsGeometryCheckError::affectedAreaBBox() const
{
return mGeometry->boundingBox();
return mGeometry.boundingBox();
}

bool QgsGeometryCheckError::handleChanges( const QgsGeometryCheck::Changes &changes )
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/vector/geometry_checker/qgsgeometrycheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ANALYSIS_EXPORT QgsGeometryCheckError
mErrorLocation = other->mErrorLocation;
mVidx = other->mVidx;
mValue = other->mValue;
mGeometry.reset( other->mGeometry->clone() );
mGeometry = other->mGeometry;
}

virtual bool handleChanges( const QgsGeometryCheck::Changes &changes );
Expand All @@ -198,7 +198,7 @@ class ANALYSIS_EXPORT QgsGeometryCheckError
QgsGeometryCheckError( const QgsGeometryCheck *check,
const QString &layerId,
QgsFeatureId featureId,
QgsAbstractGeometry *geometry,
const QgsGeometry &geometry,
const QgsPointXY &errorLocation,
QgsVertexId vidx = QgsVertexId(),
const QVariant &value = QVariant(),
Expand All @@ -207,7 +207,7 @@ class ANALYSIS_EXPORT QgsGeometryCheckError
const QgsGeometryCheck *mCheck = nullptr;
QString mLayerId;
QgsFeatureId mFeatureId;
std::unique_ptr<QgsAbstractGeometry> mGeometry;
QgsGeometry mGeometry;
QgsPointXY mErrorLocation;
QgsVertexId mVidx;
QVariant mValue;
Expand Down
15 changes: 8 additions & 7 deletions src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,14 @@ namespace QgsGeometryCheckerUtils
, mFeature( feature )
, mMapCrs( useMapCrs )
{
mGeometry = feature.geometry().constGet()->clone();
mGeometry = feature.geometry();
const QgsCoordinateTransform &transform = context->layerTransform( mFeaturePool->layerPtr() );
if ( useMapCrs && context->mapCrs.isValid() && !transform.isShortCircuited() )
{
mGeometry->transform( transform );
mGeometry.transform( transform );
}
}

LayerFeature::~LayerFeature()
{
delete mGeometry;
}

QPointer<QgsVectorLayer> LayerFeature::layer() const
{
return mFeaturePool->layerPtr();
Expand All @@ -57,6 +52,12 @@ namespace QgsGeometryCheckerUtils
return mFeaturePool->layerId();
}

const QgsGeometry &LayerFeature::geometry() const
{
return mGeometry;

}

QString LayerFeature::id() const
{
return QString( "%1:%2" ).arg( layer()->name() ).arg( mFeature.id() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,10 @@ namespace QgsGeometryCheckerUtils
{
public:
LayerFeature( const QgsFeaturePool *pool, const QgsFeature &feature, QgsGeometryCheckerContext *context, bool useMapCrs );
~LayerFeature();
const QgsFeature &feature() const { return mFeature; }
QPointer<QgsVectorLayer> layer() const;
QString layerId() const;
double layerToMapUnits() const;
const QgsCoordinateTransform &layerToMapTransform() const;
const QgsAbstractGeometry *geometry() const { return mGeometry; }
QString geometryCrs() const { return mMapCrs ? layerToMapTransform().destinationCrs().authid() : layerToMapTransform().sourceCrs().authid(); }
const QgsGeometry &geometry() const;
QString id() const;
bool operator==( const LayerFeature &other ) const;
bool operator!=( const LayerFeature &other ) const;
Expand All @@ -51,7 +47,7 @@ namespace QgsGeometryCheckerUtils
private:
const QgsFeaturePool *mFeaturePool;
QgsFeature mFeature;
QgsAbstractGeometry *mGeometry = nullptr;
QgsGeometry mGeometry;
bool mMapCrs;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void QgsGeometryContainedCheck::collectErrors( QList<QgsGeometryCheckError *> &e
QgsGeometryCheckerUtils::LayerFeatures layerFeaturesA( mContext->featurePools, featureIds, mCompatibleGeometryTypes, progressCounter, mContext );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureA : layerFeaturesA )
{
QgsRectangle bboxA = layerFeatureA.geometry()->boundingBox();
std::unique_ptr< QgsGeometryEngine > geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureA.geometry(), mContext->tolerance );
QgsRectangle bboxA = layerFeatureA.geometry().boundingBox();
std::unique_ptr< QgsGeometryEngine > geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureA.geometry().constGet(), mContext->tolerance );
if ( !geomEngineA->isValid() )
{
messages.append( tr( "Contained check failed for (%1): the geometry is invalid" ).arg( layerFeatureA.id() ) );
Expand All @@ -39,17 +39,17 @@ void QgsGeometryContainedCheck::collectErrors( QList<QgsGeometryCheckError *> &e
{
continue;
}
std::unique_ptr< QgsGeometryEngine > geomEngineB = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureB.geometry(), mContext->tolerance );
std::unique_ptr< QgsGeometryEngine > geomEngineB = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureB.geometry().constGet(), mContext->tolerance );
if ( !geomEngineB->isValid() )
{
messages.append( tr( "Contained check failed for (%1): the geometry is invalid" ).arg( layerFeatureB.id() ) );
continue;
}
QString errMsg;
// If A contains B and B contains A, it would mean that the geometries are identical, which is covered by the duplicate check
if ( geomEngineA->contains( layerFeatureB.geometry(), &errMsg ) && !geomEngineB->contains( layerFeatureA.geometry(), &errMsg ) && errMsg.isEmpty() )
if ( geomEngineA->contains( layerFeatureB.geometry().constGet(), &errMsg ) && !geomEngineB->contains( layerFeatureA.geometry().constGet(), &errMsg ) && errMsg.isEmpty() )
{
errors.append( new QgsGeometryContainedCheckError( this, layerFeatureB, layerFeatureB.geometry()->centroid(), layerFeatureA ) );
errors.append( new QgsGeometryContainedCheckError( this, layerFeatureB, layerFeatureB.geometry().constGet()->centroid(), layerFeatureA ) );
}
else if ( !errMsg.isEmpty() )
{
Expand Down Expand Up @@ -78,10 +78,10 @@ void QgsGeometryContainedCheck::fixError( QgsGeometryCheckError *error, int meth
QgsGeometryCheckerUtils::LayerFeature layerFeatureA( featurePoolA, featureA, mContext, true );
QgsGeometryCheckerUtils::LayerFeature layerFeatureB( featurePoolB, featureB, mContext, true );

std::unique_ptr< QgsGeometryEngine > geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureA.geometry(), mContext->tolerance );
std::unique_ptr< QgsGeometryEngine > geomEngineB = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureB.geometry(), mContext->tolerance );
std::unique_ptr< QgsGeometryEngine > geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureA.geometry().constGet(), mContext->tolerance );
std::unique_ptr< QgsGeometryEngine > geomEngineB = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureB.geometry().constGet(), mContext->tolerance );

if ( !( geomEngineB->contains( layerFeatureA.geometry() ) && !geomEngineA->contains( layerFeatureB.geometry() ) ) )
if ( !( geomEngineB->contains( layerFeatureA.geometry().constGet() ) && !geomEngineA->contains( layerFeatureB.geometry().constGet() ) ) )
{
error->setObsolete();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void QgsGeometryDangleCheck::collectErrors( QList<QgsGeometryCheckError *> &erro
QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds, mCompatibleGeometryTypes, progressCounter, mContext );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
const QgsAbstractGeometry *geom = layerFeature.geometry();
const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
const QgsLineString *line = dynamic_cast<const QgsLineString *>( QgsGeometryCheckerUtils::getGeomPart( geom, iPart ) );
Expand All @@ -50,7 +50,7 @@ void QgsGeometryDangleCheck::collectErrors( QList<QgsGeometryCheckError *> &erro
QgsGeometryCheckerUtils::LayerFeatures checkFeatures( mContext->featurePools, QList<QString>() << layerFeature.layer()->id(), line->boundingBox(), {QgsWkbTypes::LineGeometry}, mContext );
for ( const QgsGeometryCheckerUtils::LayerFeature &checkFeature : checkFeatures )
{
const QgsAbstractGeometry *testGeom = checkFeature.geometry();
const QgsAbstractGeometry *testGeom = checkFeature.geometry().constGet();
for ( int jPart = 0, mParts = testGeom->partCount(); jPart < mParts; ++jPart )
{
if ( checkFeature.feature().id() == layerFeature.feature().id() && iPart == jPart )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void QgsGeometryDegeneratePolygonCheck::collectErrors( QList<QgsGeometryCheckErr
QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds, mCompatibleGeometryTypes, progressCounter, mContext );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
const QgsAbstractGeometry *geom = layerFeature.geometry();
const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
for ( int iRing = 0, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ void QgsGeometryDuplicateCheck::collectErrors( QList<QgsGeometryCheckError *> &e
// Ensure each pair of layers only gets compared once: remove the current layer from the layerIds, but add it to the layerList for layerFeaturesB
layerIds.removeOne( layerFeatureA.layer()->id() );

QgsRectangle bboxA = layerFeatureA.geometry()->boundingBox();
std::unique_ptr< QgsGeometryEngine > geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureA.geometry(), mContext->tolerance );
QgsRectangle bboxA = layerFeatureA.geometry().boundingBox();
std::unique_ptr< QgsGeometryEngine > geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureA.geometry().constGet(), mContext->tolerance );
if ( !geomEngineA->isValid() )
{
messages.append( tr( "Duplicate check failed for (%1): the geometry is invalid" ).arg( layerFeatureA.id() ) );
Expand All @@ -66,7 +66,7 @@ void QgsGeometryDuplicateCheck::collectErrors( QList<QgsGeometryCheckError *> &e
continue;
}
QString errMsg;
QgsAbstractGeometry *diffGeom = geomEngineA->symDifference( layerFeatureB.geometry(), &errMsg );
QgsAbstractGeometry *diffGeom = geomEngineA->symDifference( layerFeatureB.geometry().constGet(), &errMsg );
if ( errMsg.isEmpty() && diffGeom && diffGeom->isEmpty() )
{
duplicates[layerFeatureB.layer()->id()].append( layerFeatureB.feature().id() );
Expand All @@ -79,7 +79,7 @@ void QgsGeometryDuplicateCheck::collectErrors( QList<QgsGeometryCheckError *> &e
}
if ( !duplicates.isEmpty() )
{
errors.append( new QgsGeometryDuplicateCheckError( this, layerFeatureA, layerFeatureA.geometry()->centroid(), duplicates ) );
errors.append( new QgsGeometryDuplicateCheckError( this, layerFeatureA, layerFeatureA.geometry().constGet()->centroid(), duplicates ) );
}
}
}
Expand All @@ -101,7 +101,7 @@ void QgsGeometryDuplicateCheck::fixError( QgsGeometryCheckError *error, int meth
else if ( method == RemoveDuplicates )
{
QgsGeometryCheckerUtils::LayerFeature layerFeatureA( featurePoolA, featureA, mContext, true );
std::unique_ptr< QgsGeometryEngine > geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureA.geometry(), mContext->tolerance );
std::unique_ptr< QgsGeometryEngine > geomEngineA = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureA.geometry().constGet(), mContext->tolerance );

QgsGeometryDuplicateCheckError *duplicateError = static_cast<QgsGeometryDuplicateCheckError *>( error );
for ( const QString &layerIdB : duplicateError->duplicates().keys() )
Expand All @@ -115,7 +115,7 @@ void QgsGeometryDuplicateCheck::fixError( QgsGeometryCheckError *error, int meth
continue;
}
QgsGeometryCheckerUtils::LayerFeature layerFeatureB( featurePoolB, featureB, mContext, true );
QgsAbstractGeometry *diffGeom = geomEngineA->symDifference( layerFeatureB.geometry() );
QgsAbstractGeometry *diffGeom = geomEngineA->symDifference( layerFeatureB.geometry().constGet() );
if ( diffGeom && diffGeom->isEmpty() )
{
featurePoolB->deleteFeature( featureB.id() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void QgsGeometryDuplicateNodesCheck::collectErrors( QList<QgsGeometryCheckError
QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds, mCompatibleGeometryTypes, progressCounter, mContext );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
const QgsAbstractGeometry *geom = layerFeature.geometry();
const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
for ( int iRing = 0, nRings = geom->ringCount( iPart ); iRing < nRings; ++iRing )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void QgsGeometryFollowBoundariesCheck::collectErrors( QList<QgsGeometryCheckErro
QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds, mCompatibleGeometryTypes, progressCounter, mContext );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
const QgsAbstractGeometry *geom = layerFeature.geometry();
const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();

// The geometry to crs of the check layer
QgsCoordinateTransform crst( layerFeature.layer()->crs(), mCheckLayer->crs(), QgsProject::instance() );
Expand Down
8 changes: 4 additions & 4 deletions src/analysis/vector/geometry_checker/qgsgeometrygapcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors,
const QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds, mCompatibleGeometryTypes, nullptr, mContext, true );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
geomList.append( layerFeature.geometry()->clone() );
geomList.append( layerFeature.geometry().constGet()->clone() );
}

if ( geomList.isEmpty() )
Expand Down Expand Up @@ -98,10 +98,10 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors,
const QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds.keys(), gapAreaBBox, mCompatibleGeometryTypes, mContext );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
if ( QgsGeometryCheckerUtils::sharedEdgeLength( gapGeom.get(), layerFeature.geometry(), mContext->reducedTolerance ) > 0 )
if ( QgsGeometryCheckerUtils::sharedEdgeLength( gapGeom.get(), layerFeature.geometry().constGet(), mContext->reducedTolerance ) > 0 )
{
neighboringIds[layerFeature.layer()->id()].insert( layerFeature.feature().id() );
gapAreaBBox.combineExtentWith( layerFeature.geometry()->boundingBox() );
gapAreaBBox.combineExtentWith( layerFeature.geometry().constGet()->boundingBox() );
}
}

Expand All @@ -112,7 +112,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors,

// Add error
double area = gapGeom->area();
errors.append( new QgsGeometryGapCheckError( this, QString(), gapGeom.release(), neighboringIds, area, gapAreaBBox ) );
errors.append( new QgsGeometryGapCheckError( this, QString(), QgsGeometry( gapGeom.release() ), neighboringIds, area, gapAreaBBox ) );

}
}
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/geometry_checker/qgsgeometrygapcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class ANALYSIS_EXPORT QgsGeometryGapCheckError : public QgsGeometryCheckError
public:
QgsGeometryGapCheckError( const QgsGeometryCheck *check,
const QString &layerId,
QgsAbstractGeometry *geometry,
const QgsGeometry &geometry,
const QMap<QString, QgsFeatureIds> &neighbors,
double area,
const QgsRectangle &gapAreaBBox )
: QgsGeometryCheckError( check, layerId, FEATUREID_NULL, geometry, geometry->centroid(), QgsVertexId(), area, ValueArea )
: QgsGeometryCheckError( check, layerId, FEATUREID_NULL, geometry, geometry.constGet()->centroid(), QgsVertexId(), area, ValueArea )
, mNeighbors( neighbors )
, mGapAreaBBox( gapAreaBBox )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void QgsGeometryHoleCheck::collectErrors( QList<QgsGeometryCheckError *> &errors
QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds, mCompatibleGeometryTypes, progressCounter, mContext );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
const QgsAbstractGeometry *geom = layerFeature.geometry();
const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();
for ( int iPart = 0, nParts = geom->partCount(); iPart < nParts; ++iPart )
{
const QgsCurvePolygon *poly = dynamic_cast<const QgsCurvePolygon *>( QgsGeometryCheckerUtils::getGeomPart( geom, iPart ) );
Expand Down

0 comments on commit b60cf05

Please sign in to comment.