Skip to content

Commit 5c2fec3

Browse files
committed
SLD parsing: handling ogc:Literal within CssParameter
1 parent 2de18c9 commit 5c2fec3

7 files changed

Lines changed: 107 additions & 0 deletions

File tree

‎tests/src/python/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ ADD_PYTHON_TEST(PyQgsSQLStatement test_qgssqlstatement.py)
104104
ADD_PYTHON_TEST(PyQgsStringStatisticalSummary test_qgsstringstatisticalsummary.py)
105105
ADD_PYTHON_TEST(PyQgsSymbolLayer test_qgssymbollayer.py)
106106
ADD_PYTHON_TEST(PyQgsSymbolLayerCreateSld test_qgssymbollayer_createsld.py)
107+
ADD_PYTHON_TEST(PyQgsSymbolLayerReadSld test_qgssymbollayer_readsld.py)
107108
ADD_PYTHON_TEST(PyQgsArrowSymbolLayer test_qgsarrowsymbollayer.py)
108109
ADD_PYTHON_TEST(PyQgsSymbolExpressionVariables test_qgssymbolexpressionvariables.py)
109110
ADD_PYTHON_TEST(PyQgsSyntacticSugar test_syntactic_sugar.py)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
test_qgssymbollayer_readsld.py
6+
---------------------
7+
Date : January 2017
8+
Copyright : (C) 2017, Jorge Gustavo Rocha
9+
Email : jgr at di dot uminho dot pt
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Jorge Gustavo Rocha'
21+
__date__ = 'January 2017'
22+
__copyright__ = '(C) 2017, Jorge Gustavo Rocha'
23+
# This will get replaced with a git SHA1 when you do a git archive
24+
__revision__ = '$Format:%H$'
25+
26+
import qgis # NOQA
27+
28+
import os
29+
from qgis.testing import start_app, unittest
30+
from qgis.core import (QgsVectorLayer,
31+
QgsProject,
32+
QgsRectangle,
33+
QgsMultiRenderChecker,
34+
QgsSingleSymbolRenderer,
35+
QgsFillSymbol,
36+
QgsFeatureRequest
37+
)
38+
from qgis.testing import unittest
39+
from qgis.testing.mocked import get_iface
40+
from utilities import unitTestDataPath
41+
42+
start_app()
43+
44+
TEST_DATA_DIR = unitTestDataPath()
45+
46+
class TestQgsSymbolLayerReadSld(unittest.TestCase):
47+
48+
"""
49+
This class loads an SLD style and checks if the styling was properly applied
50+
"""
51+
52+
def setUp(self):
53+
self.iface = get_iface()
54+
myShpFile = os.path.join(TEST_DATA_DIR, 'streams.shp')
55+
self.layer = QgsVectorLayer(myShpFile, 'streams', 'ogr')
56+
mFilePath = os.path.join(TEST_DATA_DIR, 'symbol_layer/external_sld/simple_streams.sld')
57+
self.layer.loadSldStyle(mFilePath)
58+
self.props = self.layer.renderer().symbol().symbolLayers()[0].properties()
59+
60+
def testLineColor(self):
61+
# stroke CSSParameter within ogc:Literal
62+
# expected color is #003EBA, RGB 0,62,186
63+
self.assertEqual(self.layer.renderer().symbol().symbolLayers()[0].color().name(), '#003eba')
64+
65+
def testLineWidth(self):
66+
# stroke-width CSSParameter within ogc:Literal
67+
self.assertEqual(self.props['line_width'], '2')
68+
69+
def testLineOpacity(self):
70+
# stroke-opacity CSSParameter NOT within ogc:Literal
71+
# stroke-opacity=0.1
72+
self.assertEqual(self.props['line_color'], '0,62,186,25')
73+
74+
if __name__ == '__main__':
75+
unittest.main()

‎tests/testdata/streams.dbf‎

9.44 KB
Binary file not shown.

‎tests/testdata/streams.prj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PROJCS["NAD27 / UTM zone 13N", GEOGCS["NAD27", DATUM["North American Datum 1927", SPHEROID["Clarke 1866", 6378206.4, 294.9786982138982, AUTHORITY["EPSG","7008"]], TOWGS84[-4.2, 135.4, 181.9, 0.0, 0.0, 0.0, 0.0], AUTHORITY["EPSG","6267"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4267"]], PROJECTION["Transverse Mercator", AUTHORITY["EPSG","9807"]], PARAMETER["central_meridian", -105.0], PARAMETER["latitude_of_origin", 0.0], PARAMETER["scale_factor", 0.9996], PARAMETER["false_easting", 500000.0], PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH], AUTHORITY["EPSG","26713"]]

‎tests/testdata/streams.shp‎

62.9 KB
Binary file not shown.

‎tests/testdata/streams.shx‎

932 Bytes
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
3+
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
5+
<NamedLayer>
6+
<Name>Simple Streams</Name>
7+
<UserStyle>
8+
9+
<Title>Default Styler for streams segments</Title>
10+
<Abstract>Blue lines, 2px wide</Abstract>
11+
<FeatureTypeStyle>
12+
<FeatureTypeName>Feature</FeatureTypeName>
13+
<Rule>
14+
<Title>Streams</Title>
15+
<LineSymbolizer>
16+
<Stroke>
17+
<CssParameter name="stroke">
18+
<ogc:Literal>#003EBA</ogc:Literal>
19+
</CssParameter>
20+
<CssParameter name="stroke-width">
21+
<ogc:Literal>2</ogc:Literal>
22+
</CssParameter>
23+
<CssParameter name="stroke-opacity">0.1</CssParameter>
24+
</Stroke>
25+
</LineSymbolizer>
26+
</Rule>
27+
</FeatureTypeStyle>
28+
</UserStyle>
29+
</NamedLayer>
30+
</StyledLayerDescriptor>

0 commit comments

Comments
 (0)