Skip to content

Commit

Permalink
feat(avoidIntersections): add a new return value when the geom is not…
Browse files Browse the repository at this point in the history
… modified
  • Loading branch information
Koyaani committed Nov 29, 2022
1 parent ec689c5 commit 864ed43
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/geometry/qgsgeometry.sip.in
Expand Up @@ -2343,6 +2343,7 @@ Modifies geometry to avoid intersections with the layers specified in project pr
1 if geometry is not of polygon type,
2 if avoid intersection would change the geometry type,
3 at least one geometry intersected is invalid. The algorithm may not work and return the same geometry as the input. You must fix your intersecting geometries.
4 if the geometry is not intersected by one of the geometries present in the provided layers.

.. versionadded:: 1.5
%End
Expand Down
5 changes: 5 additions & 0 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -2850,15 +2850,20 @@ int QgsGeometry::avoidIntersections( const QList<QgsVectorLayer *> &avoidInterse
QgsWkbTypes::Type geomTypeBeforeModification = wkbType();

bool haveInvalidGeometry = false;
bool geomModified = false;

std::unique_ptr< QgsAbstractGeometry > diffGeom = QgsGeometryEditUtils::avoidIntersections( *( d->geometry ), avoidIntersectionsLayers, haveInvalidGeometry, ignoreFeatures );
if ( diffGeom )
{
reset( std::move( diffGeom ) );
geomModified = true;
}

if ( geomTypeBeforeModification != wkbType() )
return 2;
if ( haveInvalidGeometry )
return 3;
if ( !geomModified )
return 4;

return 0;
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgsgeometry.h
Expand Up @@ -2406,6 +2406,7 @@ class CORE_EXPORT QgsGeometry
* 1 if geometry is not of polygon type,
* 2 if avoid intersection would change the geometry type,
* 3 at least one geometry intersected is invalid. The algorithm may not work and return the same geometry as the input. You must fix your intersecting geometries.
* 4 if the geometry is not intersected by one of the geometries present in the provided layers.
* \since QGIS 1.5
*/
int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
Expand Down
4 changes: 4 additions & 0 deletions src/core/geometry/qgsgeometryeditutils.cpp
Expand Up @@ -343,6 +343,10 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeometryEditUtils::avoidIntersections( c
}

std::unique_ptr< QgsAbstractGeometry > diffGeom( geomEngine->difference( combinedGeometries.get() ) );
if ( geomEngine->isEqual( diffGeom.get() ) )
{
return nullptr;
}

return diffGeom;
}

0 comments on commit 864ed43

Please sign in to comment.