Skip to content

Commit

Permalink
[refFunctions] honor testOnly parameter for geometry_overlay_nearest too
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdalang committed Aug 20, 2020
1 parent 6daafef commit 6c5ee80
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -5875,17 +5875,31 @@ static QVariant indexedFilteredOverlay( QgsExpression &subExp, QgsExpressionCont
}
}

static QVariantList indexedFilteredNearest( QgsExpression &subExp, QgsExpressionContext &subContext, const QgsSpatialIndex &spatialIndex, std::shared_ptr<QgsVectorLayer> cachedTarget, const QgsGeometry &geometry, bool testOnly, bool invert, QVariant currentFeatId, int neighbors, double max_distance, double bboxGrow = 0 )
static QVariant indexedFilteredNearest( QgsExpression &subExp, QgsExpressionContext &subContext, const QgsSpatialIndex &spatialIndex, std::shared_ptr<QgsVectorLayer> cachedTarget, const QgsGeometry &geometry, bool testOnly, bool invert, QVariant currentFeatId, int neighbors, double max_distance, double bboxGrow = 0 )
{

bool found = false;
const QList<QgsFeatureId> targetFeatureIds = spatialIndex.nearestNeighbor( geometry, neighbors, max_distance );
QVariantList results;
for ( QgsFeatureId id : targetFeatureIds )
{
found = true;
// We just want a single boolean result if there is any intersect: finish and return true
if ( testOnly )
break;

QgsFeature feat = cachedTarget->getFeature( id );
subContext.setFeature( feat );
results.append( subExp.evaluate( &subContext ) );
}

if ( testOnly )
{
if ( invert )
found = !found;//for disjoint condition
return found;
}

return results;
}

Expand Down

0 comments on commit 6c5ee80

Please sign in to comment.