Skip to content

Commit 4e82767

Browse files
authoredAug 15, 2016
Merge pull request #3366 from aaime/sld_filter_fix
Do not generate a ogc:Filter where a ogc:Expression is expected.
2 parents 1cb48dd + 1140437 commit 4e82767

File tree

6 files changed

+140
-1
lines changed

6 files changed

+140
-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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,12 @@ QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp, QDomDo
20452045
"geometry", QString(), false, false, errorMessage );
20462046
}
20472047

2048+
QDomElement QgsOgcUtils::expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage )
2049+
{
2050+
return expressionToOgcExpression( exp, doc, GML_2_1_2, FILTER_OGC_1_0,
2051+
"geometry", QString(), false, false, errorMessage );
2052+
}
2053+
20482054
QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp,
20492055
QDomDocument& doc,
20502056
GMLVersion gmlVersion,
@@ -2082,6 +2088,45 @@ QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp,
20822088
return filterElem;
20832089
}
20842090

2091+
QDomElement QgsOgcUtils::expressionToOgcExpression( const QgsExpression& exp,
2092+
QDomDocument& doc,
2093+
GMLVersion gmlVersion,
2094+
FilterVersion filterVersion,
2095+
const QString& geometryName,
2096+
const QString& srsName,
2097+
bool honourAxisOrientation,
2098+
bool invertAxisOrientation,
2099+
QString* errorMessage )
2100+
{
2101+
const QgsExpression::Node* node = exp.rootNode();
2102+
if ( !node )
2103+
return QDomElement();
2104+
2105+
switch ( node->nodeType() )
2106+
{
2107+
case QgsExpression::ntFunction:
2108+
case QgsExpression::ntLiteral:
2109+
case QgsExpression::ntColumnRef:
2110+
{
2111+
QgsOgcUtilsExprToFilter utils( doc, gmlVersion, filterVersion, geometryName, srsName, honourAxisOrientation, invertAxisOrientation );
2112+
QDomElement exprRootElem = utils.expressionNodeToOgcFilter( node );
2113+
2114+
if ( errorMessage )
2115+
*errorMessage = utils.errorMessage();
2116+
2117+
if ( !exprRootElem.isNull() )
2118+
{
2119+
return exprRootElem;
2120+
}
2121+
break;
2122+
}
2123+
default:
2124+
*errorMessage = QObject::tr( "Node type not supported in expression translation: %1" ).arg( node->nodeType() );
2125+
}
2126+
// got an error
2127+
return QDomElement();
2128+
}
2129+
20852130
QDomElement QgsOgcUtils::SQLStatementToOgcFilter( const QgsSQLStatement& statement,
20862131
QDomDocument& doc,
20872132
GMLVersion gmlVersion,

‎src/core/qgsogcutils.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ class CORE_EXPORT QgsOgcUtils
161161
bool invertAxisOrientation,
162162
QString* errorMessage = nullptr );
163163

164+
/** Creates an OGC expression XML element.
165+
* @return valid OGC expression QDomElement on success,
166+
* otherwise null QDomElement
167+
*/
168+
static QDomElement expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr );
169+
170+
/** Creates an OGC expression XML element.
171+
* @return valid OGC expression QDomElement on success,
172+
* otherwise null QDomElement
173+
*/
174+
static QDomElement expressionToOgcExpression( const QgsExpression& exp,
175+
QDomDocument& doc,
176+
GMLVersion gmlVersion,
177+
FilterVersion filterVersion,
178+
const QString& geometryName,
179+
const QString& srsName,
180+
bool honourAxisOrientation,
181+
bool invertAxisOrientation,
182+
QString* errorMessage = nullptr );
183+
164184
/** \ingroup core
165185
* Layer properties. Used by SQLStatementToOgcFilter().
166186
* @note Added in QGIS 2.16

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ bool QgsSymbolLayerUtils::createFunctionElement( QDomDocument &doc, QDomElement
25142514
element.appendChild( doc.createComment( "Parser Error: " + expr.parserErrorString() + " - Expression was: " + function ) );
25152515
return false;
25162516
}
2517-
QDomElement filterElem = QgsOgcUtils::expressionToOgcFilter( expr, doc );
2517+
QDomElement filterElem = QgsOgcUtils::expressionToOgcExpression( expr, doc );
25182518
if ( !filterElem.isNull() )
25192519
element.appendChild( filterElem );
25202520
return true;

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ ADD_PYTHON_TEST(PyQgsSpatialiteProvider test_provider_spatialite.py)
8585
ADD_PYTHON_TEST(PyQgsSQLStatement test_qgssqlstatement.py)
8686
ADD_PYTHON_TEST(PyQgsStringStatisticalSummary test_qgsstringstatisticalsummary.py)
8787
ADD_PYTHON_TEST(PyQgsSymbolLayer test_qgssymbollayer.py)
88+
ADD_PYTHON_TEST(PyQgsSymbolLayerCreateSld test_qgssymbollayer_createsld.py)
8889
ADD_PYTHON_TEST(PyQgsArrowSymbolLayer test_qgsarrowsymbollayer.py)
8990
ADD_PYTHON_TEST(PyQgsSymbolExpressionVariables test_qgssymbolexpressionvariables.py)
9091
ADD_PYTHON_TEST(PyQgsSyntacticSugar test_syntactic_sugar.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.