Skip to content
Permalink
Browse files

Merge pull request #3366 from aaime/sld_filter_fix

Do not generate a ogc:Filter where a ogc:Expression is expected.
  • Loading branch information
elpaso committed Aug 15, 2016
2 parents 1cb48dd + 1140437 commit 4e82767fcf1b5a7ddceb7917d2b0bf6a7c63282d
@@ -59,5 +59,11 @@ class QgsOgcUtils
*/
static QDomElement expressionToOgcFilter( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage /Out/ );

/** Creates an OGC expression XML element.
* @return valid OGC expression QDomElement on success,
* otherwise null QDomElement
*/
static QDomElement expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr );

};

@@ -2045,6 +2045,12 @@ QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp, QDomDo
"geometry", QString(), false, false, errorMessage );
}

QDomElement QgsOgcUtils::expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage )
{
return expressionToOgcExpression( exp, doc, GML_2_1_2, FILTER_OGC_1_0,
"geometry", QString(), false, false, errorMessage );
}

QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp,
QDomDocument& doc,
GMLVersion gmlVersion,
@@ -2082,6 +2088,45 @@ QDomElement QgsOgcUtils::expressionToOgcFilter( const QgsExpression& exp,
return filterElem;
}

QDomElement QgsOgcUtils::expressionToOgcExpression( const QgsExpression& exp,
QDomDocument& doc,
GMLVersion gmlVersion,
FilterVersion filterVersion,
const QString& geometryName,
const QString& srsName,
bool honourAxisOrientation,
bool invertAxisOrientation,
QString* errorMessage )
{
const QgsExpression::Node* node = exp.rootNode();
if ( !node )
return QDomElement();

switch ( node->nodeType() )
{
case QgsExpression::ntFunction:
case QgsExpression::ntLiteral:
case QgsExpression::ntColumnRef:
{
QgsOgcUtilsExprToFilter utils( doc, gmlVersion, filterVersion, geometryName, srsName, honourAxisOrientation, invertAxisOrientation );
QDomElement exprRootElem = utils.expressionNodeToOgcFilter( node );

if ( errorMessage )
*errorMessage = utils.errorMessage();

if ( !exprRootElem.isNull() )
{
return exprRootElem;
}
break;
}
default:
*errorMessage = QObject::tr( "Node type not supported in expression translation: %1" ).arg( node->nodeType() );
}
// got an error
return QDomElement();
}

QDomElement QgsOgcUtils::SQLStatementToOgcFilter( const QgsSQLStatement& statement,
QDomDocument& doc,
GMLVersion gmlVersion,
@@ -161,6 +161,26 @@ class CORE_EXPORT QgsOgcUtils
bool invertAxisOrientation,
QString* errorMessage = nullptr );

/** Creates an OGC expression XML element.
* @return valid OGC expression QDomElement on success,
* otherwise null QDomElement
*/
static QDomElement expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr );

/** Creates an OGC expression XML element.
* @return valid OGC expression QDomElement on success,
* otherwise null QDomElement
*/
static QDomElement expressionToOgcExpression( const QgsExpression& exp,
QDomDocument& doc,
GMLVersion gmlVersion,
FilterVersion filterVersion,
const QString& geometryName,
const QString& srsName,
bool honourAxisOrientation,
bool invertAxisOrientation,
QString* errorMessage = nullptr );

/** \ingroup core
* Layer properties. Used by SQLStatementToOgcFilter().
* @note Added in QGIS 2.16
@@ -2514,7 +2514,7 @@ bool QgsSymbolLayerUtils::createFunctionElement( QDomDocument &doc, QDomElement
element.appendChild( doc.createComment( "Parser Error: " + expr.parserErrorString() + " - Expression was: " + function ) );
return false;
}
QDomElement filterElem = QgsOgcUtils::expressionToOgcFilter( expr, doc );
QDomElement filterElem = QgsOgcUtils::expressionToOgcExpression( expr, doc );
if ( !filterElem.isNull() )
element.appendChild( filterElem );
return true;
@@ -85,6 +85,7 @@ ADD_PYTHON_TEST(PyQgsSpatialiteProvider test_provider_spatialite.py)
ADD_PYTHON_TEST(PyQgsSQLStatement test_qgssqlstatement.py)
ADD_PYTHON_TEST(PyQgsStringStatisticalSummary test_qgsstringstatisticalsummary.py)
ADD_PYTHON_TEST(PyQgsSymbolLayer test_qgssymbollayer.py)
ADD_PYTHON_TEST(PyQgsSymbolLayerCreateSld test_qgssymbollayer_createsld.py)
ADD_PYTHON_TEST(PyQgsArrowSymbolLayer test_qgsarrowsymbollayer.py)
ADD_PYTHON_TEST(PyQgsSymbolExpressionVariables test_qgssymbolexpressionvariables.py)
ADD_PYTHON_TEST(PyQgsSyntacticSugar test_syntactic_sugar.py)
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
test_qgssymbollayer_createsld.py
---------------------
Date : July 2016
Copyright : (C) 2016 by Andrea Aime
Email : andrea dot aime at geosolutions dot it
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *less
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Andrea Aime'
__date__ = 'July 2016'
__copyright__ = '(C) 2012, Andrea Aime'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # NOQA

import os

from qgis.PyQt.QtCore import pyqtWrapperType, Qt, QDir, QFile, QIODevice, QPointF
from qgis.PyQt.QtXml import (QDomDocument, QDomElement)
from qgis.PyQt.QtGui import QColor

from qgis.core import QgsSimpleMarkerSymbolLayer
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath

# Convenience instances in case you may need them
# not used in this test
start_app()


class TestQgsSymbolLayerCreateSld(unittest.TestCase):

"""
This class tests the creation of SLD from QGis layers
"""

def testSimpleMarkerSymbolLayer(self):
symbol = QgsSimpleMarkerSymbolLayer(
'star', QColor(255, 0, 0), QColor(0, 255, 0), 10)
symbol.setAngle(50)
dom = QDomDocument()
root = dom.createElement("FakeRoot")
dom.appendChild(root)
symbol.toSld(dom, root, {})
# print "This is the dom: " + dom.toString()

# Check the rotation element is a literal, not a
rotation = root.elementsByTagName('se:Rotation').item(0)
literal = rotation.firstChild()
self.assertEquals("ogc:Literal", literal.nodeName())
self.assertEquals('50', literal.firstChild().nodeValue())


if __name__ == '__main__':
unittest.main()

0 comments on commit 4e82767

Please sign in to comment.
You can’t perform that action at this time.