diff --git a/python/PyQt6/core/auto_generated/vector/qgsvectorlayer.sip.in b/python/PyQt6/core/auto_generated/vector/qgsvectorlayer.sip.in index 2cf57cdf6761..c9924db14036 100644 --- a/python/PyQt6/core/auto_generated/vector/qgsvectorlayer.sip.in +++ b/python/PyQt6/core/auto_generated/vector/qgsvectorlayer.sip.in @@ -145,8 +145,8 @@ Also note: - You can use various functions available in the QGIS Expression list, however the function must exist server side and have the same name and arguments to work. -- Use the special $geometry parameter to provide the layer geometry column as input - into the spatial binary operators e.g intersects($geometry, geomFromWKT('POINT (5 6)')) +- Use the special ``@geometry`` parameter to provide the layer geometry column as input + into the spatial binary operators e.g ``intersects(@geometry, geomFromWKT('POINT (5 6)'))`` OGC API Features data provider (oapif) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/python/core/auto_generated/vector/qgsvectorlayer.sip.in b/python/core/auto_generated/vector/qgsvectorlayer.sip.in index 2cf57cdf6761..c9924db14036 100644 --- a/python/core/auto_generated/vector/qgsvectorlayer.sip.in +++ b/python/core/auto_generated/vector/qgsvectorlayer.sip.in @@ -145,8 +145,8 @@ Also note: - You can use various functions available in the QGIS Expression list, however the function must exist server side and have the same name and arguments to work. -- Use the special $geometry parameter to provide the layer geometry column as input - into the spatial binary operators e.g intersects($geometry, geomFromWKT('POINT (5 6)')) +- Use the special ``@geometry`` parameter to provide the layer geometry column as input + into the spatial binary operators e.g ``intersects(@geometry, geomFromWKT('POINT (5 6)'))`` OGC API Features data provider (oapif) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/core/qgsogcutils.cpp b/src/core/qgsogcutils.cpp index a68a730f9ba2..16a3d25f3e1f 100644 --- a/src/core/qgsogcutils.cpp +++ b/src/core/qgsogcutils.cpp @@ -2318,7 +2318,7 @@ static bool isGeometryColumn( const QgsExpressionNode *node ) const QgsExpressionNodeFunction *fn = static_cast( node ); QgsExpressionFunction *fd = QgsExpression::Functions()[fn->fnIndex()]; - return fd->name() == QLatin1String( "$geometry" ); + return fd->name() == QLatin1String( "$geometry" ) || ( fd->name() == QLatin1String( "var" ) && fn->referencedVariables().contains( QLatin1String( "geometry" ) ) ); } static QgsGeometry geometryFromConstExpr( const QgsExpressionNode *node ) @@ -2382,7 +2382,7 @@ QDomElement QgsOgcUtilsExprToFilter::expressionFunctionToOgcFilter( const QgsExp } else { - mErrorMessage = QObject::tr( " is currently supported only in form: bbox($geometry, geomFromWKT('…'))" ); + mErrorMessage = QObject::tr( " is currently supported only in form: bbox(@geometry, geomFromWKT('…'))" ); return QDomElement(); } } diff --git a/src/core/vector/qgsvectorlayer.h b/src/core/vector/qgsvectorlayer.h index 4e3f5ba6145d..725e53fc6e19 100644 --- a/src/core/vector/qgsvectorlayer.h +++ b/src/core/vector/qgsvectorlayer.h @@ -216,8 +216,8 @@ typedef QSet QgsAttributeIds; * * - You can use various functions available in the QGIS Expression list, * however the function must exist server side and have the same name and arguments to work. - * - Use the special $geometry parameter to provide the layer geometry column as input - * into the spatial binary operators e.g intersects($geometry, geomFromWKT('POINT (5 6)')) + * - Use the special ``@geometry`` parameter to provide the layer geometry column as input + * into the spatial binary operators e.g ``intersects(@geometry, geomFromWKT('POINT (5 6)'))`` * * \subsection oapif OGC API Features data provider (oapif) * diff --git a/tests/src/core/testqgsogcutils.cpp b/tests/src/core/testqgsogcutils.cpp index 6237a903b7a4..17b67212dbb4 100644 --- a/tests/src/core/testqgsogcutils.cpp +++ b/tests/src/core/testqgsogcutils.cpp @@ -733,26 +733,47 @@ void TestQgsOgcUtils::testExpressionToOgcFilter_data() "" "" ); - QTest::newRow( "intersects_bbox" ) << QStringLiteral( "intersects_bbox($geometry, geomFromWKT('POINT (5 6)'))" ) << QString( "" - "" - "geometry" - "5,6 5,6" - "" - "" ); - - QTest::newRow( "intersects + wkt" ) << QStringLiteral( "intersects($geometry, geomFromWKT('POINT (5 6)'))" ) << QString( "" - "" - "geometry" - "5,6" - "" - "" ); - - QTest::newRow( "contains + gml" ) << QStringLiteral( "contains($geometry, geomFromGML('5,6'))" ) << QString( "" - "" - "geometry" - "5,6" - "" - "" ); + QTest::newRow( "intersects_bbox $geometry" ) << QStringLiteral( "intersects_bbox($geometry, geomFromWKT('POINT (5 6)'))" ) << QString( "" + "" + "geometry" + "5,6 5,6" + "" + "" ); + + QTest::newRow( "intersects + wkt $geometry" ) << QStringLiteral( "intersects($geometry, geomFromWKT('POINT (5 6)'))" ) << QString( "" + "" + "geometry" + "5,6" + "" + "" ); + + QTest::newRow( "contains + gml $geometry" ) << QStringLiteral( "contains($geometry, geomFromGML('5,6'))" ) << QString( "" + "" + "geometry" + "5,6" + "" + "" ); + + QTest::newRow( "intersects_bbox @geometry" ) << QStringLiteral( "intersects_bbox(@geometry, geomFromWKT('POINT (5 6)'))" ) << QString( "" + "" + "geometry" + "5,6 5,6" + "" + "" ); + + QTest::newRow( "intersects + wkt @geometry" ) << QStringLiteral( "intersects(@geometry, geomFromWKT('POINT (5 6)'))" ) << QString( "" + "" + "geometry" + "5,6" + "" + "" ); + + QTest::newRow( "contains + gml @geometry" ) << QStringLiteral( "contains(@geometry, geomFromGML('5,6'))" ) << QString( "" + "" + "geometry" + "5,6" + "" + "" ); } void TestQgsOgcUtils::testExpressionToOgcFilterWFS11() @@ -791,7 +812,7 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS11_data() QTest::addColumn( "srsName" ); QTest::addColumn( "xmlText" ); - QTest::newRow( "bbox" ) + QTest::newRow( "bbox $geometry" ) << QStringLiteral( "intersects_bbox($geometry, geomFromWKT('POLYGON((2 49,2 50,3 50,3 49,2 49))'))" ) << QStringLiteral( "urn:ogc:def:crs:EPSG::4326" ) << QString( @@ -805,6 +826,21 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS11_data() "" "" ); + + QTest::newRow( "bbox @geometry" ) + << QStringLiteral( "intersects_bbox(@geometry, geomFromWKT('POLYGON((2 49,2 50,3 50,3 49,2 49))'))" ) + << QStringLiteral( "urn:ogc:def:crs:EPSG::4326" ) + << QString( + "" + "" + "my_geometry_name" + "" + "49 2" + "50 3" + "" + "" + "" + ); } void TestQgsOgcUtils::testExpressionToOgcFilterWFS20() @@ -860,7 +896,7 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS20_data() "" ) << QStringLiteral( "myns" ) << QStringLiteral( "http://example.com/myns" ); - QTest::newRow( "bbox" ) + QTest::newRow( "bbox $geometry" ) << QStringLiteral( "intersects_bbox($geometry, geomFromWKT('POLYGON((2 49,2 50,3 50,3 49,2 49))'))" ) << QStringLiteral( "urn:ogc:def:crs:EPSG::4326" ) << QString( @@ -876,7 +912,7 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS20_data() ) << QString() << QString(); - QTest::newRow( "bbox with namespace" ) + QTest::newRow( "bbox with namespace $geometry" ) << QStringLiteral( "intersects_bbox($geometry, geomFromWKT('POLYGON((2 49,2 50,3 50,3 49,2 49))'))" ) << QStringLiteral( "urn:ogc:def:crs:EPSG::4326" ) << QString( @@ -892,7 +928,7 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS20_data() ) << QStringLiteral( "myns" ) << QStringLiteral( "http://example.com/myns" ); - QTest::newRow( "intersects" ) + QTest::newRow( "intersects $geometry" ) << QStringLiteral( "intersects($geometry, geomFromWKT('POLYGON((2 49,2 50,3 50,3 49,2 49))'))" ) << QStringLiteral( "urn:ogc:def:crs:EPSG::4326" ) << QString( @@ -910,6 +946,57 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS20_data() "" ) << QString() << QString(); + + QTest::newRow( "bbox @geometry" ) + << QStringLiteral( "intersects_bbox(@geometry, geomFromWKT('POLYGON((2 49,2 50,3 50,3 49,2 49))'))" ) + << QStringLiteral( "urn:ogc:def:crs:EPSG::4326" ) + << QString( + "" + "" + "my_geometry_name" + "" + "49 2" + "50 3" + "" + "" + "" + ) + << QString() << QString(); + + QTest::newRow( "bbox with namespace @geometry" ) + << QStringLiteral( "intersects_bbox(@geometry, geomFromWKT('POLYGON((2 49,2 50,3 50,3 49,2 49))'))" ) + << QStringLiteral( "urn:ogc:def:crs:EPSG::4326" ) + << QString( + "" + "" + "myns:my_geometry_name" + "" + "49 2" + "50 3" + "" + "" + "" + ) + << QStringLiteral( "myns" ) << QStringLiteral( "http://example.com/myns" ); + + QTest::newRow( "intersects @geometry" ) + << QStringLiteral( "intersects(@geometry, geomFromWKT('POLYGON((2 49,2 50,3 50,3 49,2 49))'))" ) + << QStringLiteral( "urn:ogc:def:crs:EPSG::4326" ) + << QString( + "" + "" + "my_geometry_name" + "" + "" + "" + "49 2 50 2 50 3 49 3 49 2" + "" + "" + "" + "" + "" + ) + << QString() << QString(); } Q_DECLARE_METATYPE( QgsOgcUtils::GMLVersion )