Skip to content

Commit 50e07df

Browse files
enricoferm-kuhn
authored andcommittedJul 3, 2020
limit parameter default changed to -1
1 parent cc5102e commit 50e07df

File tree

1 file changed

+66
-47
lines changed

1 file changed

+66
-47
lines changed
 

‎src/core/expression/qgsexpressionfunction.cpp

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5652,7 +5652,7 @@ static QVariant fcnFromBase64( const QVariantList &values, const QgsExpressionCo
56525652

56535653
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;
56545654

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 )
56565656
{
56575657
// First parameter is the overlay layer
56585658
QgsExpressionNode *node = QgsExpressionUtils::getNode( values.at( 0 ), parent );
@@ -5667,8 +5667,9 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
56675667
node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
56685668
ENSURE_NO_EVAL_ERROR
56695669
subExpString = node->dump();
5670-
if ( subExpString == "NULL" ) {
5671-
testOnly = true;
5670+
if ( subExpString == "NULL" )
5671+
{
5672+
testOnly = true;
56725673
}
56735674

56745675
QgsSpatialIndex spatialIndex;
@@ -5686,10 +5687,13 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
56865687
node = QgsExpressionUtils::getNode( values.at( 2 ), parent );
56875688
ENSURE_NO_EVAL_ERROR
56885689
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+
}
56905694

56915695
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 );
56935697

56945698
int neighbors = 1;
56955699
/*
@@ -5755,7 +5759,10 @@ template <t_relationFunction T>
57555759
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 )
57565760
{
57575761
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+
}
57595766

57605767
const QList<QgsFeatureId> targetFeatureIds = spatialIndex.intersects( intDomain );
57615768

@@ -5775,46 +5782,58 @@ static QVariant indexedFilteredOverlay( QgsExpression &subExp, QgsExpressionCont
57755782
break;
57765783

57775784
// 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 );
57835793
}
57845794
}
57855795
}
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 ) );
58005818
}
5801-
return disjoint_results;
5819+
}
5820+
return disjoint_results;
58025821
}
58035822
}
58045823
}
58055824

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 )
58075826
{
58085827

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;
58185837
}
58195838

58205839
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
58495868

58505869
static QVariant fcnGeomOverlayEquals( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )
58515870
{
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
58535872
}
58545873

58555874
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
58895908

58905909
static QVariant fcnGeomOverlayNearest( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )
58915910
{
5892-
return executeGeomOverlay( values, context, parent, false, indexedFilteredNearest, false);
5911+
return executeGeomOverlay( values, context, parent, false, indexedFilteredNearest, false );
58935912
}
58945913

58955914
const QList<QgsExpressionFunction *> &QgsExpression::Functions()
@@ -6265,7 +6284,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
62656284
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
62666285
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
62676286
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
6268-
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, 0 ),
6287+
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
62696288
fcnGeomOverlayIntersects, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
62706289

62716290
// The current feature is accessed for the geometry, so this should not be cached
@@ -6285,7 +6304,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
62856304
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
62866305
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
62876306
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
6288-
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, 0 ),
6307+
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
62896308
// TODO: limit param
62906309
fcnGeomOverlayContains, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
62916310
// The current feature is accessed for the geometry, so this should not be cached
@@ -6305,7 +6324,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
63056324
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
63066325
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
63076326
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
6308-
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, 0 ),
6327+
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
63096328
fcnGeomOverlayCrosses, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
63106329
// The current feature is accessed for the geometry, so this should not be cached
63116330
fcnGeomOverlayCrossesFunc->setIsStatic( false );
@@ -6324,7 +6343,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
63246343
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
63256344
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
63266345
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
6327-
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, 0 ),
6346+
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
63286347
fcnGeomOverlayEquals, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
63296348
// The current feature is accessed for the geometry, so this should not be cached
63306349
fcnGeomOverlayEqualsFunc->setIsStatic( false );
@@ -6343,7 +6362,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
63436362
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
63446363
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
63456364
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
6346-
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, 0 ),
6365+
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
63476366
fcnGeomOverlayTouches, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
63486367
// The current feature is accessed for the geometry, so this should not be cached
63496368
fcnGeomOverlayTouchesFunc->setIsStatic( false );
@@ -6362,7 +6381,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
63626381
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
63636382
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
63646383
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
6365-
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, 0 ),
6384+
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
63666385
fcnGeomOverlayDisjoint, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
63676386
// The current feature is accessed for the geometry, so this should not be cached
63686387
fcnGeomOverlayDisjointFunc->setIsStatic( false );
@@ -6381,7 +6400,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
63816400
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
63826401
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
63836402
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
6384-
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, 0 ),
6403+
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 ),
63856404
fcnGeomOverlayWithin, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
63866405
// The current feature is accessed for the geometry, so this should not be cached
63876406
fcnGeomOverlayWithinFunc->setIsStatic( false );
@@ -6400,9 +6419,9 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
64006419
<< QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
64016420
<< QgsExpressionFunction::Parameter( QStringLiteral( "expression" ), true, QVariant(), true )
64026421
<< QgsExpressionFunction::Parameter( QStringLiteral( "filter" ), true, QVariant(), true )
6403-
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, 0 )
6422+
<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true, -1 )
64046423
<< QgsExpressionFunction::Parameter( QStringLiteral( "neighbors" ), true, 1 )
6405-
<< QgsExpressionFunction::Parameter( QStringLiteral( "max_distance" ), true, 0),
6424+
<< QgsExpressionFunction::Parameter( QStringLiteral( "max_distance" ), true, 0 ),
64066425
//<< QgsExpressionFunction::Parameter( QStringLiteral( "limit" ), true ),
64076426
fcnGeomOverlayNearest, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>() << QgsFeatureRequest::ALL_ATTRIBUTES, true );
64086427
// The current feature is accessed for the geometry, so this should not be cached

0 commit comments

Comments
 (0)
Please sign in to comment.