@@ -5652,7 +5652,7 @@ static QVariant fcnFromBase64( const QVariantList &values, const QgsExpressionCo
5652
5652
5653
5653
typedef std::function < QVariant( QgsExpression &subExp, QgsExpressionContext &subContext, const QgsSpatialIndex &spatialIndex, std::shared_ptr<QgsVectorLayer> cachedTarget, const QgsGeometry &geometry, bool testOnly, bool invert, int neighbors, double max_distance, double bboxGrow ) > overlayFunc;
5654
5654
5655
- static QVariant executeGeomOverlay ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, bool testOnly, const overlayFunc &overlayFunction, bool invert = false , double bboxGrow = 0 )
5655
+ static QVariant executeGeomOverlay ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, bool testOnly, const overlayFunc &overlayFunction, bool invert = false , double bboxGrow = 0 )
5656
5656
{
5657
5657
// First parameter is the overlay layer
5658
5658
QgsExpressionNode *node = QgsExpressionUtils::getNode ( values.at ( 0 ), parent );
@@ -5667,8 +5667,9 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
5667
5667
node = QgsExpressionUtils::getNode ( values.at ( 1 ), parent );
5668
5668
ENSURE_NO_EVAL_ERROR
5669
5669
subExpString = node->dump ();
5670
- if ( subExpString == " NULL" ) {
5671
- testOnly = true ;
5670
+ if ( subExpString == " NULL" )
5671
+ {
5672
+ testOnly = true ;
5672
5673
}
5673
5674
5674
5675
QgsSpatialIndex spatialIndex;
@@ -5686,10 +5687,13 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
5686
5687
node = QgsExpressionUtils::getNode ( values.at ( 2 ), parent );
5687
5688
ENSURE_NO_EVAL_ERROR
5688
5689
filterString = node->dump ();
5689
- if ( filterString != " NULL" ) request.setFilterExpression (filterString); // filter cached features
5690
+ if ( filterString != " NULL" )
5691
+ {
5692
+ request.setFilterExpression ( filterString ); // filter cached features
5693
+ }
5690
5694
5691
5695
int limit = QgsExpressionUtils::getIntValue ( values.at ( 3 ), parent ); // in expressions overlay functions throw the exception: Eval Error: Cannot convert '' to int
5692
- if (limit > 0 ) request.setLimit ( limit);
5696
+ request.setLimit ( limit );
5693
5697
5694
5698
int neighbors = 1 ;
5695
5699
/*
@@ -5755,7 +5759,10 @@ template <t_relationFunction T>
5755
5759
static QVariant indexedFilteredOverlay ( QgsExpression &subExp, QgsExpressionContext &subContext, const QgsSpatialIndex &spatialIndex, std::shared_ptr<QgsVectorLayer> cachedTarget, const QgsGeometry &geometry, bool testOnly, bool invert, int neighbors, double max_distance, double bboxGrow = 0 )
5756
5760
{
5757
5761
QgsRectangle intDomain = geometry.boundingBox ();
5758
- if ( bboxGrow != 0 ) intDomain.grow (bboxGrow); // optional parameter to enlarge boundary context for touches and equals methods
5762
+ if ( bboxGrow != 0 )
5763
+ {
5764
+ intDomain.grow ( bboxGrow ); // optional parameter to enlarge boundary context for touches and equals methods
5765
+ }
5759
5766
5760
5767
const QList<QgsFeatureId> targetFeatureIds = spatialIndex.intersects ( intDomain );
5761
5768
@@ -5775,46 +5782,58 @@ static QVariant indexedFilteredOverlay( QgsExpression &subExp, QgsExpressionCont
5775
5782
break ;
5776
5783
5777
5784
// We want a list of attributes / geometries / other expression values, evaluate now
5778
- if (!invert){
5779
- subContext.setFeature ( feat );
5780
- results.append ( subExp.evaluate ( &subContext ) );
5781
- } else {
5782
- results.append (id);
5785
+ if ( !invert )
5786
+ {
5787
+ subContext.setFeature ( feat );
5788
+ results.append ( subExp.evaluate ( &subContext ) );
5789
+ }
5790
+ else
5791
+ {
5792
+ results.append ( id );
5783
5793
}
5784
5794
}
5785
5795
}
5786
- if ( testOnly ){
5787
- if ( invert ) found = !found;// for disjoint condition
5788
- return found;
5789
- } else {
5790
- if ( !invert ) return results;
5791
- else { // for disjoint condition returns the results for cached layers not intersected feats
5792
- QVariantList disjoint_results;
5793
- QgsFeature feat;
5794
- QgsFeatureIterator fi = cachedTarget->getFeatures ();
5795
- while ( fi.nextFeature ( feat ) ) {
5796
- if ( !results.contains (feat.id ()) ) {
5797
- subContext.setFeature ( feat );
5798
- disjoint_results.append ( subExp.evaluate ( &subContext ) );
5799
- }
5796
+ if ( testOnly )
5797
+ {
5798
+ if ( invert )
5799
+ found = !found;// for disjoint condition
5800
+ return found;
5801
+ }
5802
+ else
5803
+ {
5804
+ if ( !invert )
5805
+ return results;
5806
+ else
5807
+ {
5808
+ // for disjoint condition returns the results for cached layers not intersected feats
5809
+ QVariantList disjoint_results;
5810
+ QgsFeature feat;
5811
+ QgsFeatureIterator fi = cachedTarget->getFeatures ();
5812
+ while ( fi.nextFeature ( feat ) )
5813
+ {
5814
+ if ( !results.contains ( feat.id () ) )
5815
+ {
5816
+ subContext.setFeature ( feat );
5817
+ disjoint_results.append ( subExp.evaluate ( &subContext ) );
5800
5818
}
5801
- return disjoint_results;
5819
+ }
5820
+ return disjoint_results;
5802
5821
}
5803
5822
}
5804
5823
}
5805
5824
5806
- static QVariantList indexedFilteredNearest ( QgsExpression &subExp, QgsExpressionContext &subContext, const QgsSpatialIndex &spatialIndex, std::shared_ptr<QgsVectorLayer> cachedTarget, const QgsGeometry &geometry, bool testOnly, bool invert, int neighbors, double max_distance, double bboxGrow = 0 )
5825
+ static QVariantList indexedFilteredNearest ( QgsExpression &subExp, QgsExpressionContext &subContext, const QgsSpatialIndex &spatialIndex, std::shared_ptr<QgsVectorLayer> cachedTarget, const QgsGeometry &geometry, bool testOnly, bool invert, int neighbors, double max_distance, double bboxGrow = 0 )
5807
5826
{
5808
5827
5809
- const QList<QgsFeatureId> targetFeatureIds = spatialIndex.nearestNeighbor ( geometry, neighbors, max_distance );
5810
- QVariantList results;
5811
- for ( QgsFeatureId id : targetFeatureIds )
5812
- {
5813
- QgsFeature feat = cachedTarget->getFeature ( id );
5814
- subContext.setFeature ( feat );
5815
- results.append ( subExp.evaluate ( &subContext ) );
5816
- }
5817
- return results;
5828
+ const QList<QgsFeatureId> targetFeatureIds = spatialIndex.nearestNeighbor ( geometry, neighbors, max_distance );
5829
+ QVariantList results;
5830
+ for ( QgsFeatureId id : targetFeatureIds )
5831
+ {
5832
+ QgsFeature feat = cachedTarget->getFeature ( id );
5833
+ subContext.setFeature ( feat );
5834
+ results.append ( subExp.evaluate ( &subContext ) );
5835
+ }
5836
+ return results;
5818
5837
}
5819
5838
5820
5839
static QVariant fcnGeomOverlayIntersects ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )
@@ -5849,7 +5868,7 @@ static QVariant fcnTestGeomOverlayCrosses( const QVariantList &values, const Qgs
5849
5868
5850
5869
static QVariant fcnGeomOverlayEquals ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )
5851
5870
{
5852
- return executeGeomOverlay ( values, context, parent, false , indexedFilteredOverlay<&QgsGeometry::equals>, false , 0.01 ); // grow amount should adapt to current units
5871
+ return executeGeomOverlay ( values, context, parent, false , indexedFilteredOverlay<&QgsGeometry::equals>, false , 0.01 ); // grow amount should adapt to current units
5853
5872
}
5854
5873
5855
5874
static QVariant fcnTestGeomOverlayEquals ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )
@@ -5889,7 +5908,7 @@ static QVariant fcnTestGeomOverlayDisjoint( const QVariantList &values, const Qg
5889
5908
5890
5909
static QVariant fcnGeomOverlayNearest ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )
5891
5910
{
5892
- return executeGeomOverlay ( values, context, parent, false , indexedFilteredNearest, false );
5911
+ return executeGeomOverlay ( values, context, parent, false , indexedFilteredNearest, false );
5893
5912
}
5894
5913
5895
5914
const QList<QgsExpressionFunction *> &QgsExpression::Functions ()
@@ -6265,7 +6284,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
6265
6284
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " layer" ) )
6266
6285
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " expression" ), true , QVariant (), true )
6267
6286
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " filter" ), true , QVariant (), true )
6268
- << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , 0 ),
6287
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , - 1 ),
6269
6288
fcnGeomOverlayIntersects, QStringLiteral ( " GeometryGroup" ), QString (), false , QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
6270
6289
6271
6290
// The current feature is accessed for the geometry, so this should not be cached
@@ -6285,7 +6304,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
6285
6304
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " layer" ) )
6286
6305
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " expression" ), true , QVariant (), true )
6287
6306
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " filter" ), true , QVariant (), true )
6288
- << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , 0 ),
6307
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , - 1 ),
6289
6308
// TODO: limit param
6290
6309
fcnGeomOverlayContains, QStringLiteral ( " GeometryGroup" ), QString (), false , QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
6291
6310
// The current feature is accessed for the geometry, so this should not be cached
@@ -6305,7 +6324,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
6305
6324
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " layer" ) )
6306
6325
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " expression" ), true , QVariant (), true )
6307
6326
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " filter" ), true , QVariant (), true )
6308
- << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , 0 ),
6327
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , - 1 ),
6309
6328
fcnGeomOverlayCrosses, QStringLiteral ( " GeometryGroup" ), QString (), false , QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
6310
6329
// The current feature is accessed for the geometry, so this should not be cached
6311
6330
fcnGeomOverlayCrossesFunc->setIsStatic ( false );
@@ -6324,7 +6343,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
6324
6343
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " layer" ) )
6325
6344
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " expression" ), true , QVariant (), true )
6326
6345
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " filter" ), true , QVariant (), true )
6327
- << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , 0 ),
6346
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , - 1 ),
6328
6347
fcnGeomOverlayEquals, QStringLiteral ( " GeometryGroup" ), QString (), false , QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
6329
6348
// The current feature is accessed for the geometry, so this should not be cached
6330
6349
fcnGeomOverlayEqualsFunc->setIsStatic ( false );
@@ -6343,7 +6362,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
6343
6362
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " layer" ) )
6344
6363
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " expression" ), true , QVariant (), true )
6345
6364
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " filter" ), true , QVariant (), true )
6346
- << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , 0 ),
6365
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , - 1 ),
6347
6366
fcnGeomOverlayTouches, QStringLiteral ( " GeometryGroup" ), QString (), false , QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
6348
6367
// The current feature is accessed for the geometry, so this should not be cached
6349
6368
fcnGeomOverlayTouchesFunc->setIsStatic ( false );
@@ -6362,7 +6381,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
6362
6381
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " layer" ) )
6363
6382
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " expression" ), true , QVariant (), true )
6364
6383
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " filter" ), true , QVariant (), true )
6365
- << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , 0 ),
6384
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , - 1 ),
6366
6385
fcnGeomOverlayDisjoint, QStringLiteral ( " GeometryGroup" ), QString (), false , QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
6367
6386
// The current feature is accessed for the geometry, so this should not be cached
6368
6387
fcnGeomOverlayDisjointFunc->setIsStatic ( false );
@@ -6381,7 +6400,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
6381
6400
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " layer" ) )
6382
6401
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " expression" ), true , QVariant (), true )
6383
6402
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " filter" ), true , QVariant (), true )
6384
- << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , 0 ),
6403
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , - 1 ),
6385
6404
fcnGeomOverlayWithin, QStringLiteral ( " GeometryGroup" ), QString (), false , QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
6386
6405
// The current feature is accessed for the geometry, so this should not be cached
6387
6406
fcnGeomOverlayWithinFunc->setIsStatic ( false );
@@ -6400,9 +6419,9 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
6400
6419
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " layer" ) )
6401
6420
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " expression" ), true , QVariant (), true )
6402
6421
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " filter" ), true , QVariant (), true )
6403
- << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , 0 )
6422
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " limit" ), true , - 1 )
6404
6423
<< QgsExpressionFunction::Parameter ( QStringLiteral ( " neighbors" ), true , 1 )
6405
- << QgsExpressionFunction::Parameter ( QStringLiteral ( " max_distance" ), true , 0 ),
6424
+ << QgsExpressionFunction::Parameter ( QStringLiteral ( " max_distance" ), true , 0 ),
6406
6425
// << QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true ),
6407
6426
fcnGeomOverlayNearest, QStringLiteral ( " GeometryGroup" ), QString (), false , QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
6408
6427
// The current feature is accessed for the geometry, so this should not be cached
0 commit comments