Skip to content

Commit 864ed43

Browse files
committedNov 29, 2022
feat(avoidIntersections): add a new return value when the geom is not modified
1 parent ec689c5 commit 864ed43

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed
 

‎python/core/auto_generated/geometry/qgsgeometry.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,6 +2343,7 @@ Modifies geometry to avoid intersections with the layers specified in project pr
23432343
1 if geometry is not of polygon type,
23442344
2 if avoid intersection would change the geometry type,
23452345
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.
2346+
4 if the geometry is not intersected by one of the geometries present in the provided layers.
23462347

23472348
.. versionadded:: 1.5
23482349
%End

‎src/core/geometry/qgsgeometry.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,15 +2850,20 @@ int QgsGeometry::avoidIntersections( const QList<QgsVectorLayer *> &avoidInterse
28502850
QgsWkbTypes::Type geomTypeBeforeModification = wkbType();
28512851

28522852
bool haveInvalidGeometry = false;
2853+
bool geomModified = false;
2854+
28532855
std::unique_ptr< QgsAbstractGeometry > diffGeom = QgsGeometryEditUtils::avoidIntersections( *( d->geometry ), avoidIntersectionsLayers, haveInvalidGeometry, ignoreFeatures );
28542856
if ( diffGeom )
28552857
{
28562858
reset( std::move( diffGeom ) );
2859+
geomModified = true;
28572860
}
28582861

28592862
if ( geomTypeBeforeModification != wkbType() )
28602863
return 2;
28612864
if ( haveInvalidGeometry )
2865+
return 3;
2866+
if ( !geomModified )
28622867
return 4;
28632868

28642869
return 0;

‎src/core/geometry/qgsgeometry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,6 +2406,7 @@ class CORE_EXPORT QgsGeometry
24062406
* 1 if geometry is not of polygon type,
24072407
* 2 if avoid intersection would change the geometry type,
24082408
* 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.
2409+
* 4 if the geometry is not intersected by one of the geometries present in the provided layers.
24092410
* \since QGIS 1.5
24102411
*/
24112412
int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers,

‎src/core/geometry/qgsgeometryeditutils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeometryEditUtils::avoidIntersections( c
343343
}
344344

345345
std::unique_ptr< QgsAbstractGeometry > diffGeom( geomEngine->difference( combinedGeometries.get() ) );
346+
if ( geomEngine->isEqual( diffGeom.get() ) )
347+
{
348+
return nullptr;
349+
}
346350

347351
return diffGeom;
348352
}

0 commit comments

Comments
 (0)
Please sign in to comment.