Skip to content

Commit

Permalink
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
luipir committed Jan 23, 2017
1 parent 1746b32 commit dd82e32
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -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" )
{
Expand All @@ -2592,7 +2593,15 @@ bool QgsSymbolLayerV2Utils::functionFromSldElement( QDomElement &element, QStrin
return false;
}

// check if it is a single string value
if ( elem.hasChildNodes() &&
elem.firstChild().nodeType() == QDomNode::TextNode )
{
function = elem.firstChild().nodeValue();
return true;
}

// 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 @@

"""
***************************************************************************
<<<<<<< 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
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 rormat 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 no 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 dd82e32

Please sign in to comment.