@@ -2100,15 +2100,61 @@ static bool isGeometryColumn( const QgsExpression::Node* node )
2100
2100
return fd->name () == " $geometry" ;
2101
2101
}
2102
2102
2103
+ static QgsGeometry* geometryFromConstExpr ( const QgsExpression::Node* node )
2104
+ {
2105
+ // Right now we support only geomFromWKT(' ..... ')
2106
+ // Ideally we should support any constant sub-expression (not dependant on feature's geometry or attributes)
2107
+
2108
+ if ( node->nodeType () == QgsExpression::ntFunction )
2109
+ {
2110
+ const QgsExpression::NodeFunction* fnNode = static_cast <const QgsExpression::NodeFunction*>( node );
2111
+ QgsExpression::Function* fnDef = QgsExpression::Functions ()[fnNode->fnIndex ()];
2112
+ if ( fnDef->name () == " geomFromWKT" )
2113
+ {
2114
+ const QList<QgsExpression::Node*>& args = fnNode->args ()->list ();
2115
+ if ( args[0 ]->nodeType () == QgsExpression::ntLiteral )
2116
+ {
2117
+ QString wkt = static_cast <const QgsExpression::NodeLiteral*>( args[0 ] )->value ().toString ();
2118
+ return QgsGeometry::fromWkt ( wkt );
2119
+ }
2120
+ }
2121
+ }
2122
+ return 0 ;
2123
+ }
2124
+
2103
2125
2104
2126
QDomElement QgsOgcUtils::expressionFunctionToOgcFilter ( const QgsExpression::NodeFunction* node, QDomDocument& doc, QString& errorMessage )
2105
2127
{
2106
2128
QgsExpression::Function* fd = QgsExpression::Functions ()[node->fnIndex ()];
2107
2129
2108
2130
if ( fd->name () == " bbox" )
2109
2131
{
2110
- errorMessage = QString ( " <BBOX> is currently not supported." );
2111
- return QDomElement ();
2132
+ QList<QgsExpression::Node*> argNodes = node->args ()->list ();
2133
+ Q_ASSERT ( argNodes.count () == 2 ); // binary spatial ops must have two args
2134
+
2135
+ QgsGeometry* geom = geometryFromConstExpr ( argNodes[1 ] );
2136
+ if ( geom && isGeometryColumn ( argNodes[0 ] ) )
2137
+ {
2138
+ QgsRectangle rect = geom->boundingBox ();
2139
+ delete geom;
2140
+
2141
+ QDomElement elemBox = rectangleToGMLBox ( &rect, doc );
2142
+
2143
+ QDomElement geomProperty = doc.createElement ( " ogc:PropertyName" );
2144
+ geomProperty.appendChild ( doc.createTextNode ( " geometry" ) );
2145
+
2146
+ QDomElement funcElem = doc.createElement ( " ogr:BBOX" );
2147
+ funcElem.appendChild ( geomProperty );
2148
+ funcElem.appendChild ( elemBox );
2149
+ return funcElem;
2150
+ }
2151
+ else
2152
+ {
2153
+ delete geom;
2154
+
2155
+ errorMessage = QString ( " <BBOX> is currently supported only in form: bbox($geometry, geomFromWKT('...'))" );
2156
+ return QDomElement ();
2157
+ }
2112
2158
}
2113
2159
2114
2160
if ( isBinarySpatialOperator ( fd->name () ) )
0 commit comments