@@ -6545,7 +6545,7 @@ static QVariant fcnFromBase64( const QVariantList &values, const QgsExpressionCo
6545
6545
6546
6546
typedef bool ( QgsGeometry::*RelationFunction )( const QgsGeometry &geometry ) const ;
6547
6547
6548
- static QVariant executeGeomOverlay ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const RelationFunction &relationFunction, bool invert = false , double bboxGrow = 0 , bool isNearestFunc = false )
6548
+ static QVariant executeGeomOverlay ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const RelationFunction &relationFunction, bool invert = false , double bboxGrow = 0 , bool isNearestFunc = false , bool isIntersectsFunc = false )
6549
6549
{
6550
6550
6551
6551
const QVariant sourceLayerRef = context->variable ( QStringLiteral ( " layer" ) ); // used to detect if sourceLayer and targetLayer are the same
@@ -6611,6 +6611,18 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
6611
6611
ENSURE_NO_EVAL_ERROR
6612
6612
bool cacheEnabled = cacheValue.toBool ();
6613
6613
6614
+ // Sixth parameter (for intersects only) is the min area
6615
+ double minArea { -1 };
6616
+ if ( isIntersectsFunc )
6617
+ {
6618
+ // Fourth parameter is the limit
6619
+ node = QgsExpressionUtils::getNode ( values.at ( 5 ), parent ); // in expressions overlay functions throw the exception: Eval Error: Cannot convert '' to int
6620
+ ENSURE_NO_EVAL_ERROR
6621
+ const QVariant minAreaValue = node->eval ( parent, context );
6622
+ ENSURE_NO_EVAL_ERROR
6623
+ minArea = QgsExpressionUtils::getDoubleValue ( minAreaValue, parent );
6624
+ }
6625
+
6614
6626
6615
6627
FEAT_FROM_CONTEXT ( context, feat )
6616
6628
const QgsGeometry geometry = feat.geometry ();
@@ -6732,6 +6744,13 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
6732
6744
6733
6745
if ( ! relationFunction || ( geometry.*relationFunction )( feat2.geometry () ) ) // Calls the method provided as template argument for the function (e.g. QgsGeometry::intersects)
6734
6746
{
6747
+
6748
+ // Check min area for intersection (if set)
6749
+ if ( isIntersectsFunc && minArea != -1 && geometry.intersection ( feat2.geometry () ).area () <= minArea )
6750
+ {
6751
+ continue ;
6752
+ }
6753
+
6735
6754
found = true ;
6736
6755
foundCount++;
6737
6756
@@ -6787,7 +6806,7 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
6787
6806
6788
6807
static QVariant fcnGeomOverlayIntersects ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )
6789
6808
{
6790
- return executeGeomOverlay ( values, context, parent, &QgsGeometry::intersects );
6809
+ return executeGeomOverlay ( values, context, parent, &QgsGeometry::intersects, false , 0 , false , true );
6791
6810
}
6792
6811
6793
6812
static QVariant fcnGeomOverlayContains ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )
@@ -6817,7 +6836,7 @@ static QVariant fcnGeomOverlayWithin( const QVariantList &values, const QgsExpre
6817
6836
6818
6837
static QVariant fcnGeomOverlayDisjoint ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )
6819
6838
{
6820
- return executeGeomOverlay ( values, context, parent, &QgsGeometry::intersects, true );
6839
+ return executeGeomOverlay ( values, context, parent, &QgsGeometry::intersects, true , 0 , false , true );
6821
6840
}
6822
6841
6823
6842
static QVariant fcnGeomOverlayNearest ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )
@@ -7230,7 +7249,8 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
7230
7249
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " expression" ), true , QVariant (), true )
7231
7250
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " filter" ), true , QVariant (), true )
7232
7251
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , QVariant ( -1 ), true )
7233
- << QgsExpressionFunction::Parameter ( QStringLiteral ( " cache" ), true , QVariant ( false ), false ),
7252
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " cache" ), true , QVariant ( false ), false )
7253
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " min_intersection_area" ), true , QVariant ( -1 ), false ),
7234
7254
i.value (), QStringLiteral ( " GeometryGroup" ), QString (), true , QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
7235
7255
7236
7256
// The current feature is accessed for the geometry, so this should not be cached
0 commit comments