Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a parameter to return if there is an error with a geometry
  • Loading branch information
lbartoletti authored and nyalldawson committed Feb 12, 2021
1 parent a208ec9 commit 9783710
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -2602,12 +2602,13 @@ int QgsGeometry::avoidIntersections( const QList<QgsVectorLayer *> &avoidInterse
return 1;
}

std::unique_ptr< QgsAbstractGeometry > diffGeom = QgsGeometryEditUtils::avoidIntersections( *( d->geometry ), avoidIntersectionsLayers, ignoreFeatures );
bool haveGeometryError = false;
std::unique_ptr< QgsAbstractGeometry > diffGeom = QgsGeometryEditUtils::avoidIntersections( *( d->geometry ), avoidIntersectionsLayers, haveGeometryError, ignoreFeatures );
if ( diffGeom )
{
reset( std::move( diffGeom ) );
}
return 0;
return haveGeometryError ? 3 : 0;
}


Expand Down
10 changes: 8 additions & 2 deletions src/core/geometry/qgsgeometryeditutils.cpp
Expand Up @@ -224,7 +224,9 @@ bool QgsGeometryEditUtils::deletePart( QgsAbstractGeometry *geom, int partNum )

std::unique_ptr<QgsAbstractGeometry> QgsGeometryEditUtils::avoidIntersections( const QgsAbstractGeometry &geom,
const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures )
bool &haveGeometryError,
const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures
)
{
std::unique_ptr<QgsGeometryEngine> geomEngine( QgsGeometry::createGeometryEngine( &geom ) );
if ( !geomEngine )
Expand Down Expand Up @@ -265,7 +267,11 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeometryEditUtils::avoidIntersections( c
if ( !f.hasGeometry() )
continue;

nearGeometries << f.geometry().makeValid();
QgsGeometry geomValid = f.geometry().makeValid();
if ( geomValid.isNull() )
haveGeometryError = true;
nearGeometries << geomValid;

}
}

Expand Down

0 comments on commit 9783710

Please sign in to comment.