Skip to content

Commit b627401

Browse files
aaimerldhont
authored andcommittedOct 1, 2016
Do not generate a ogc:Filter where a ogc:Expression is expected. Fixes #10076 and #11202
1 parent 8a28f9b commit b627401

File tree

6 files changed

+138
-1
lines changed

6 files changed

+138
-1
lines changed
 

‎python/core/qgsogcutils.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,11 @@ class QgsOgcUtils
5959
*/
6060
static QDomElement expressionToOgcFilter( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage /Out/ );
6161

62+
/** Creates an OGC expression XML element.
63+
* @return valid OGC expression QDomElement on success,
64+
* otherwise null QDomElement
65+
*/
66+
static QDomElement expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr );
67+
6268
};
6369

‎src/core/qgsogcutils.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,12 @@ QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp, QDomDo
20302030
"geometry", QString(), false, false, errorMessage );
20312031
}
20322032

2033+
QDomElement QgsOgcUtils::expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage )
2034+
{
2035+
return expressionToOgcExpression( exp, doc, GML_2_1_2, FILTER_OGC_1_0,
2036+
"geometry", QString(), false, false, errorMessage );
2037+
}
2038+
20332039
QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp,
20342040
QDomDocument& doc,
20352041
GMLVersion gmlVersion,
@@ -2067,6 +2073,44 @@ QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp,
20672073
return filterElem;
20682074
}
20692075

2076+
QDomElement QgsOgcUtils::expressionToOgcExpression( const QgsExpression& exp,
2077+
QDomDocument& doc,
2078+
GMLVersion gmlVersion,
2079+
FilterVersion filterVersion,
2080+
const QString& geometryName,
2081+
const QString& srsName,
2082+
bool honourAxisOrientation,
2083+
bool invertAxisOrientation,
2084+
QString* errorMessage )
2085+
{
2086+
const QgsExpression::Node* node = exp.rootNode();
2087+
if ( !node )
2088+
return QDomElement();
2089+
2090+
switch ( node->nodeType() )
2091+
{
2092+
case QgsExpression::ntFunction:
2093+
case QgsExpression::ntLiteral:
2094+
case QgsExpression::ntColumnRef:
2095+
{
2096+
QgsOgcUtilsExprToFilter utils( doc, gmlVersion, filterVersion, geometryName, srsName, honourAxisOrientation, invertAxisOrientation );
2097+
QDomElement exprRootElem = utils.expressionNodeToOgcFilter( node );
2098+
2099+
if ( errorMessage )
2100+
*errorMessage = utils.errorMessage();
2101+
2102+
if ( !exprRootElem.isNull() )
2103+
{
2104+
return exprRootElem;
2105+
}
2106+
break;
2107+
}
2108+
default:
2109+
*errorMessage = QObject::tr( "Node type not supported in expression translation: %1" ).arg( node->nodeType() );
2110+
}
2111+
// got an error
2112+
return QDomElement();
2113+
}
20702114

20712115
QDomElement QgsOgcUtilsExprToFilter::expressionNodeToOgcFilter( const QgsExpression::Node* node )
20722116
{

‎src/core/qgsogcutils.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,25 @@ class CORE_EXPORT QgsOgcUtils
159159
bool invertAxisOrientation,
160160
QString* errorMessage = nullptr );
161161

162+
/** Creates an OGC expression XML element.
163+
* @return valid OGC expression QDomElement on success,
164+
* otherwise null QDomElement
165+
*/
166+
static QDomElement expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr );
167+
168+
/** Creates an OGC expression XML element.
169+
* @return valid OGC expression QDomElement on success,
170+
* otherwise null QDomElement
171+
*/
172+
static QDomElement expressionToOgcExpression( const QgsExpression& exp,
173+
QDomDocument& doc,
174+
GMLVersion gmlVersion,
175+
FilterVersion filterVersion,
176+
const QString& geometryName,
177+
const QString& srsName,
178+
bool honourAxisOrientation,
179+
bool invertAxisOrientation,
180+
QString* errorMessage = nullptr );
162181
private:
163182

164183
/** Static method that creates geometry from GML Point */

‎src/core/symbology-ng/qgssymbollayerv2utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2553,7 +2553,7 @@ bool QgsSymbolLayerV2Utils::createFunctionElement( QDomDocument &doc, QDomElemen
25532553
element.appendChild( doc.createComment( "Parser Error: " + expr.parserErrorString() + " - Expression was: " + function ) );
25542554
return false;
25552555
}
2556-
QDomElement filterElem = QgsOgcUtils::expressionToOgcFilter( expr, doc );
2556+
QDomElement filterElem = QgsOgcUtils::expressionToOgcExpression( expr, doc );
25572557
if ( !filterElem.isNull() )
25582558
element.appendChild( filterElem );
25592559
return true;

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ADD_PYTHON_TEST(PyQgsOGRProvider test_provider_ogr.py)
6464
ADD_PYTHON_TEST(PyQgsSpatialIndex test_qgsspatialindex.py)
6565
ADD_PYTHON_TEST(PyQgsSpatialiteProvider test_provider_spatialite.py)
6666
ADD_PYTHON_TEST(PyQgsSymbolLayerV2 test_qgssymbollayerv2.py)
67+
ADD_PYTHON_TEST(PyQgsSymbolLayerCreateSld test_qgssymbollayer_createsld.py)
6768
ADD_PYTHON_TEST(PyQgsSymbolExpressionVariables test_qgssymbolexpressionvariables.py)
6869
ADD_PYTHON_TEST(PyQgsSyntacticSugar test_syntactic_sugar.py)
6970
ADD_PYTHON_TEST(PyQgsSymbolV2 test_qgssymbolv2.py)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
test_qgssymbollayer_createsld.py
6+
---------------------
7+
Date : July 2016
8+
Copyright : (C) 2016 by Andrea Aime
9+
Email : andrea dot aime at geosolutions dot it
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *less
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Andrea Aime'
21+
__date__ = 'July 2016'
22+
__copyright__ = '(C) 2012, Andrea Aime'
23+
# This will get replaced with a git SHA1 when you do a git archive
24+
__revision__ = '$Format:%H$'
25+
26+
import qgis # NOQA
27+
28+
import os
29+
30+
from qgis.PyQt.QtCore import pyqtWrapperType, Qt, QDir, QFile, QIODevice, QPointF
31+
from qgis.PyQt.QtXml import (QDomDocument, QDomElement)
32+
from qgis.PyQt.QtGui import QColor
33+
34+
from qgis.core import QgsSimpleMarkerSymbolLayer
35+
from qgis.testing import start_app, unittest
36+
from utilities import unitTestDataPath
37+
38+
# Convenience instances in case you may need them
39+
# not used in this test
40+
start_app()
41+
42+
43+
class TestQgsSymbolLayerCreateSld(unittest.TestCase):
44+
45+
"""
46+
This class tests the creation of SLD from QGis layers
47+
"""
48+
49+
def testSimpleMarkerSymbolLayer(self):
50+
symbol = QgsSimpleMarkerSymbolLayer(
51+
'star', QColor(255, 0, 0), QColor(0, 255, 0), 10)
52+
symbol.setAngle(50)
53+
dom = QDomDocument()
54+
root = dom.createElement("FakeRoot")
55+
dom.appendChild(root)
56+
symbol.toSld(dom, root, {})
57+
# print "This is the dom: " + dom.toString()
58+
59+
# Check the rotation element is a literal, not a
60+
rotation = root.elementsByTagName('se:Rotation').item(0)
61+
literal = rotation.firstChild()
62+
self.assertEquals("ogc:Literal", literal.nodeName())
63+
self.assertEquals('50', literal.firstChild().nodeValue())
64+
65+
66+
if __name__ == '__main__':
67+
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.