Skip to content
Permalink
Browse files

Merge pull request #4050 from boundlessgeo/release-2_18-SldRotationFix

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 02c4688 + e4d3da2 commit db91e4049d44ffa78c2915e0ceb5438c8f2c1a75
@@ -1599,6 +1599,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();
@@ -2577,6 +2577,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" )
{
@@ -2592,7 +2593,7 @@ bool QgsSymbolLayerV2Utils::functionFromSldElement( QDomElement &element, QStrin
return false;
}


// parse ogc:Filter
QgsExpression *expr = QgsOgcUtils::expressionFromOgcFilter( elem );
if ( !expr )
return false;
@@ -2,7 +2,11 @@

"""
***************************************************************************
<<<<<<< 1746b32a08acfdaba35068127b25955ba7bd4b3b
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
@@ -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 db91e40

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