Skip to content
Permalink
Browse files

Tests and fix to read sld:Rotation when does not have ogc sub tags

  • Loading branch information
luipir committed Jan 24, 2017
1 parent b3e8d82 commit 6e20c07ffab76c8cf0c71885f1cdda60d94b2d18
@@ -2499,6 +2499,7 @@ bool QgsSymbolLayerUtils::createFunctionElement( QDomDocument &doc, QDomElement

bool QgsSymbolLayerUtils::functionFromSldElement( QDomElement &element, QString &function )
{
// check if ogc:Filter or containe ogc:Filters
QDomElement elem = element;
if ( element.tagName() != QLatin1String( "Filter" ) )
{
@@ -2514,7 +2515,15 @@ bool QgsSymbolLayerUtils::functionFromSldElement( QDomElement &element, QString
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;
@@ -2,7 +2,11 @@

"""
***************************************************************************
<<<<<<< b3e8d8219090068ba14a67004f9412633a6ec7b3
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 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.renderer().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.renderer().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 6e20c07

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