Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFS] Fix filtering by QGIS expression in order to support "@geometry" (Fix #60094) #60105

Merged
merged 5 commits into from
Jan 11, 2025

Conversation

agiudiceandrea
Copy link
Contributor

@agiudiceandrea agiudiceandrea commented Jan 10, 2025

Description

Adds support to @geometry (#50134) besides $geometry in WFS filtering by QGIS expression.

The isGeometryColumn() method has been updated to also recognize the @geometry variable in order for the expressionFunctionToOgcFilter() method to correctly traslate expressions containing the @geometry variable.
(The expressionFromOgcFilter() has not been updated to use @geometry instead $geometry)

Added tests for expressions using @geometry.
Also updated the WFS section of the QgsVectorLayer documentation (following up #60095) substituting $geometry with @geometry (ref. #60095 (comment) @uclaros).

Fixes #60094.

I'm unsure about the correctness of the error message at:

mErrorMessage = QObject::tr( "<BBOX> is currently supported only in form: bbox(@geometry, geomFromWKT('…'))" );

Should it be amended somehow?

@github-actions github-actions bot added this to the 3.42.0 milestone Jan 10, 2025
@agiudiceandrea agiudiceandrea added Bug Either a bug report, or a bug fix. Let's hope for the latter! WFS data provider backport release-3_40 labels Jan 10, 2025
@agiudiceandrea agiudiceandrea force-pushed the fix-60094-wfs-filter-geometry branch from 908712f to 91bdc51 Compare January 10, 2025 10:09
@agiudiceandrea agiudiceandrea force-pushed the fix-60094-wfs-filter-geometry branch from cb63312 to cdb91f5 Compare January 10, 2025 10:31
@agiudiceandrea agiudiceandrea changed the title [WFS] Fix WFS filtering by QGIS expression in order to support "@geometry" [WFS] Fix filtering by QGIS expression in order to support "@geometry" Jan 10, 2025
@agiudiceandrea agiudiceandrea changed the title [WFS] Fix filtering by QGIS expression in order to support "@geometry" [WFS] Fix filtering by QGIS expression in order to support "@geometry" (Fix #60094) Jan 10, 2025
Copy link

github-actions bot commented Jan 10, 2025

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit 9394110)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit 9394110)

@@ -2318,7 +2318,7 @@ static bool isGeometryColumn( const QgsExpressionNode *node )

const QgsExpressionNodeFunction *fn = static_cast<const QgsExpressionNodeFunction *>( node );
QgsExpressionFunction *fd = QgsExpression::Functions()[fn->fnIndex()];
return fd->name() == QLatin1String( "$geometry" );
return fd->name() == QLatin1String( "$geometry" ) || fn->referencedVariables().contains( QLatin1String( "geometry" ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not totally sure about that but couldn't there be situations where a complicated function would be used that would reference the "geometry" variable but also others, and thus would not just be "@geometry" ? If so, the following could be more appropriate:

Suggested change
return fd->name() == QLatin1String( "$geometry" ) || fn->referencedVariables().contains( QLatin1String( "geometry" ) );
return fd->name() == QLatin1String( "$geometry" ) || ( fn->referencedVariables().size() == 1 && fn->referencedVariables().contains( QLatin1String( "geometry" ) ) );

Copy link
Contributor Author

@agiudiceandrea agiudiceandrea Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! Anyway, thinking about it more carefully, it looks like even fn->referencedVariables().size() == 1 && fn->referencedVariables().contains( QLatin1String( "geometry" ) ) wouldn't reject an expression like intersects(centroid(@geometry), geomFromWKT(‘POINT (5 6)’)) while it should be.
It seems to me it should be used instead: fd->name() == QLatin1String( "var" ) && fn->referencedVariables().contains( QLatin1String( "geometry" ) )
so we ensure that the first argument is actually a "var" QgsExpressionNode::ntFunction which can only reference 1 variable, and not a generic function that references a "geometry" variable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t seems to me it should be used instead: fd->name() == QLatin1String( "var" ) && fn->referencedVariables().contains( QLatin1String( "geometry" ) )

yes that looks even better

@rouault rouault merged commit 38ec9ef into qgis:master Jan 11, 2025
31 checks passed
@agiudiceandrea agiudiceandrea deleted the fix-60094-wfs-filter-geometry branch January 12, 2025 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport release-3_40 Bug Either a bug report, or a bug fix. Let's hope for the latter! WFS data provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WFS filtering by QGIS expression supports "$geometry" but not the new "@geometry"
2 participants