Skip to content

Commit

Permalink
Merge pull request #4051 from boundlessgeo/release-2_14-SldRotationFix
Browse files Browse the repository at this point in the history
Tests and fix to read sld:Rotation when does not have ogc sub tags
  • Loading branch information
m-kuhn committed Feb 16, 2017
2 parents 70f51ae + e05a8ca commit 190c31d
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/core/qgsogcutils.cpp
Expand Up @@ -19,6 +19,7 @@
#include "qgsgeometry.h"
#include "qgswkbptr.h"
#include "qgscoordinatereferencesystem.h"
#include "qgslogger.h"

#include <QColor>
#include <QStringList>
Expand Down Expand Up @@ -1584,6 +1585,16 @@ QgsExpression* QgsOgcUtils::expressionFromOgcFilter( const QDomElement& element
if ( element.isNull() || !element.hasChildNodes() )
return nullptr;

// check if it is a single string value => no DomElement
if ( element.firstChild().nodeType() == QDomNode::TextNode )
{
QgsExpression *expr = new QgsExpression( element.firstChild().nodeValue() );
expr->d->mParserErrorString = QString();
return expr;
}

// now parse OGC operators. OGC operator does not have a only text value
// but only sub element operators
QgsExpression *expr = new QgsExpression();

QDomElement childElem = element.firstChildElement();
Expand Down
3 changes: 2 additions & 1 deletion src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -2576,6 +2576,7 @@ bool QgsSymbolLayerV2Utils::createFunctionElement( QDomDocument &doc, QDomElemen

bool QgsSymbolLayerV2Utils::functionFromSldElement( QDomElement &element, QString &function )
{
// check if ogc:Filter or containe ogc:Filters
QDomElement elem = element;
if ( element.tagName() != "Filter" )
{
Expand All @@ -2591,7 +2592,7 @@ bool QgsSymbolLayerV2Utils::functionFromSldElement( QDomElement &element, QStrin
return false;
}


// parse ogc:Filter
QgsExpression *expr = QgsOgcUtils::expressionFromOgcFilter( elem );
if ( !expr )
return false;
Expand Down
30 changes: 30 additions & 0 deletions tests/src/python/test_qgssymbollayerv2_readsld.py
Expand Up @@ -2,7 +2,11 @@

"""
***************************************************************************
<<<<<<< bee5f8063794cb7e5fc48b5e0562c20de3249d74
test_qgssymbollayer_readsld.py
=======
test_qgssymbollayerv2_readsld.py
>>>>>>> Tests and fix to read sld:Rotation when does not have ogc sub tags
---------------------
Date : January 2017
Copyright : (C) 2017, Jorge Gustavo Rocha
Expand Down Expand Up @@ -87,5 +91,31 @@ def testLineOpacity():
testLineWidth()
testLineOpacity()

def testSimpleMarkerRotation(self):
"""
Test if pointMarker property sld:Rotation value can be read if format is:
<sld:Rotation>50.0</sld:Rotation>
or
<se:Rotation><ogc:Literal>50</ogc:Literal></se:Rotation>
"""
# technically it's not necessary to use a real shape, but a empty memory
# layer. In case these tests will upgrate to a rendering where to
# compare also rendering not only properties
#myShpFile = os.path.join(unitTestDataPath(), 'points.shp')
#layer = QgsVectorLayer(myShpFile, 'points', 'ogr')
layer = QgsVectorLayer("Point", "addfeat", "memory")
assert(layer.isValid())
# test if able to read <sld:Rotation>50.0</sld:Rotation>
mFilePath = os.path.join(unitTestDataPath(), 'symbol_layer/external_sld/testSimpleMarkerRotation-directValue.sld')
layer.loadSldStyle(mFilePath)
props = layer.rendererV2().symbol().symbolLayers()[0].properties()
self.assertEqual(props['angle'], '50')
# test if able to read <se:Rotation><ogc:Literal>50</ogc:Literal></se:Rotation>
mFilePath = os.path.join(unitTestDataPath(), 'symbol_layer/external_sld/testSimpleMarkerRotation-ogcLiteral.sld')
layer.loadSldStyle(mFilePath)
props = layer.rendererV2().symbol().symbolLayers()[0].properties()
self.assertEqual(props['angle'], '50')


if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,30 @@
<?xml version="1.0" ?>
<sld:StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:sld="http://www.opengis.net/sld">
<sld:NamedLayer>
<sld:Name>testSimpleMarkerRotation</sld:Name>
<sld:UserStyle>
<sld:Name>testSimpleMarkerRotation</sld:Name>
<sld:FeatureTypeStyle>
<sld:Name>name</sld:Name>
<sld:Rule>
<sld:Name>Single symbol</sld:Name>
<sld:PointSymbolizer>
<sld:Graphic>
<sld:Mark>
<sld:WellKnownName>star</sld:WellKnownName>
<sld:Fill>
<sld:CssParameter name="fill">#ff0000</sld:CssParameter>
</sld:Fill>
<sld:Stroke>
<sld:CssParameter name="stroke">#00ff00</sld:CssParameter>
</sld:Stroke>
</sld:Mark>
<sld:Size>36</sld:Size>
<sld:Rotation>50.0</sld:Rotation>
</sld:Graphic>
</sld:PointSymbolizer>
</sld:Rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:NamedLayer>
</sld:StyledLayerDescriptor>
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:se="http://www.opengis.net/se">
<NamedLayer>
<se:Name>points</se:Name>
<UserStyle>
<se:Name>points</se:Name>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>Single symbol</se:Name>
<se:PointSymbolizer>
<se:Graphic>
<se:Mark>
<se:WellKnownName>regular_star</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#ff0000</se:SvgParameter>
</se:Fill>
<se:Stroke>
<se:SvgParameter name="stroke">#00ff00</se:SvgParameter>
</se:Stroke>
</se:Mark>
<se:Size>10</se:Size>
<se:Rotation>
<ogc:Literal>50</ogc:Literal>
</se:Rotation>
</se:Graphic>
</se:PointSymbolizer>
</se:Rule>
</se:FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

0 comments on commit 190c31d

Please sign in to comment.