Skip to content

Commit

Permalink
Do not generate a ogc:Filter where a ogc:Expression is expected. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime authored and rldhont committed Oct 1, 2016
1 parent 8a28f9b commit b627401
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 1 deletion.
6 changes: 6 additions & 0 deletions python/core/qgsogcutils.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

};

44 changes: 44 additions & 0 deletions src/core/qgsogcutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,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,
Expand Down Expand Up @@ -2067,6 +2073,44 @@ 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 QgsOgcUtilsExprToFilter::expressionNodeToOgcFilter( const QgsExpression::Node* node )
{
Expand Down
19 changes: 19 additions & 0 deletions src/core/qgsogcutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ 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 );
private:

/** Static method that creates geometry from GML Point */
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbollayerv2utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2553,7 +2553,7 @@ bool QgsSymbolLayerV2Utils::createFunctionElement( QDomDocument &doc, QDomElemen
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;
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ADD_PYTHON_TEST(PyQgsOGRProvider test_provider_ogr.py)
ADD_PYTHON_TEST(PyQgsSpatialIndex test_qgsspatialindex.py)
ADD_PYTHON_TEST(PyQgsSpatialiteProvider test_provider_spatialite.py)
ADD_PYTHON_TEST(PyQgsSymbolLayerV2 test_qgssymbollayerv2.py)
ADD_PYTHON_TEST(PyQgsSymbolLayerCreateSld test_qgssymbollayer_createsld.py)
ADD_PYTHON_TEST(PyQgsSymbolExpressionVariables test_qgssymbolexpressionvariables.py)
ADD_PYTHON_TEST(PyQgsSyntacticSugar test_syntactic_sugar.py)
ADD_PYTHON_TEST(PyQgsSymbolV2 test_qgssymbolv2.py)
Expand Down
67 changes: 67 additions & 0 deletions tests/src/python/test_qgssymbollayer_createsld.py
Original file line number Diff line number Diff line change
@@ -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 b627401

Please sign in to comment.