mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
SLD parsing: handling ogc:Literal within CssParameter
This commit is contained in:
parent
2de18c92fc
commit
5c2fec325a
@ -104,6 +104,7 @@ ADD_PYTHON_TEST(PyQgsSQLStatement test_qgssqlstatement.py)
|
||||
ADD_PYTHON_TEST(PyQgsStringStatisticalSummary test_qgsstringstatisticalsummary.py)
|
||||
ADD_PYTHON_TEST(PyQgsSymbolLayer test_qgssymbollayer.py)
|
||||
ADD_PYTHON_TEST(PyQgsSymbolLayerCreateSld test_qgssymbollayer_createsld.py)
|
||||
ADD_PYTHON_TEST(PyQgsSymbolLayerReadSld test_qgssymbollayer_readsld.py)
|
||||
ADD_PYTHON_TEST(PyQgsArrowSymbolLayer test_qgsarrowsymbollayer.py)
|
||||
ADD_PYTHON_TEST(PyQgsSymbolExpressionVariables test_qgssymbolexpressionvariables.py)
|
||||
ADD_PYTHON_TEST(PyQgsSyntacticSugar test_syntactic_sugar.py)
|
||||
|
75
tests/src/python/test_qgssymbollayer_readsld.py
Normal file
75
tests/src/python/test_qgssymbollayer_readsld.py
Normal file
@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
test_qgssymbollayer_readsld.py
|
||||
---------------------
|
||||
Date : January 2017
|
||||
Copyright : (C) 2017, Jorge Gustavo Rocha
|
||||
Email : jgr at di dot uminho dot pt
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = 'Jorge Gustavo Rocha'
|
||||
__date__ = 'January 2017'
|
||||
__copyright__ = '(C) 2017, Jorge Gustavo Rocha'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import qgis # NOQA
|
||||
|
||||
import os
|
||||
from qgis.testing import start_app, unittest
|
||||
from qgis.core import (QgsVectorLayer,
|
||||
QgsProject,
|
||||
QgsRectangle,
|
||||
QgsMultiRenderChecker,
|
||||
QgsSingleSymbolRenderer,
|
||||
QgsFillSymbol,
|
||||
QgsFeatureRequest
|
||||
)
|
||||
from qgis.testing import unittest
|
||||
from qgis.testing.mocked import get_iface
|
||||
from utilities import unitTestDataPath
|
||||
|
||||
start_app()
|
||||
|
||||
TEST_DATA_DIR = unitTestDataPath()
|
||||
|
||||
class TestQgsSymbolLayerReadSld(unittest.TestCase):
|
||||
|
||||
"""
|
||||
This class loads an SLD style and checks if the styling was properly applied
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.iface = get_iface()
|
||||
myShpFile = os.path.join(TEST_DATA_DIR, 'streams.shp')
|
||||
self.layer = QgsVectorLayer(myShpFile, 'streams', 'ogr')
|
||||
mFilePath = os.path.join(TEST_DATA_DIR, 'symbol_layer/external_sld/simple_streams.sld')
|
||||
self.layer.loadSldStyle(mFilePath)
|
||||
self.props = self.layer.renderer().symbol().symbolLayers()[0].properties()
|
||||
|
||||
def testLineColor(self):
|
||||
# stroke CSSParameter within ogc:Literal
|
||||
# expected color is #003EBA, RGB 0,62,186
|
||||
self.assertEqual(self.layer.renderer().symbol().symbolLayers()[0].color().name(), '#003eba')
|
||||
|
||||
def testLineWidth(self):
|
||||
# stroke-width CSSParameter within ogc:Literal
|
||||
self.assertEqual(self.props['line_width'], '2')
|
||||
|
||||
def testLineOpacity(self):
|
||||
# stroke-opacity CSSParameter NOT within ogc:Literal
|
||||
# stroke-opacity=0.1
|
||||
self.assertEqual(self.props['line_color'], '0,62,186,25')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
BIN
tests/testdata/streams.dbf
vendored
Normal file
BIN
tests/testdata/streams.dbf
vendored
Normal file
Binary file not shown.
1
tests/testdata/streams.prj
vendored
Normal file
1
tests/testdata/streams.prj
vendored
Normal file
@ -0,0 +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"]]
|
BIN
tests/testdata/streams.shp
vendored
Normal file
BIN
tests/testdata/streams.shp
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/streams.shx
vendored
Normal file
BIN
tests/testdata/streams.shx
vendored
Normal file
Binary file not shown.
30
tests/testdata/symbol_layer/external_sld/simple_streams.sld
vendored
Normal file
30
tests/testdata/symbol_layer/external_sld/simple_streams.sld
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
|
||||
<NamedLayer>
|
||||
<Name>Simple Streams</Name>
|
||||
<UserStyle>
|
||||
|
||||
<Title>Default Styler for streams segments</Title>
|
||||
<Abstract>Blue lines, 2px wide</Abstract>
|
||||
<FeatureTypeStyle>
|
||||
<FeatureTypeName>Feature</FeatureTypeName>
|
||||
<Rule>
|
||||
<Title>Streams</Title>
|
||||
<LineSymbolizer>
|
||||
<Stroke>
|
||||
<CssParameter name="stroke">
|
||||
<ogc:Literal>#003EBA</ogc:Literal>
|
||||
</CssParameter>
|
||||
<CssParameter name="stroke-width">
|
||||
<ogc:Literal>2</ogc:Literal>
|
||||
</CssParameter>
|
||||
<CssParameter name="stroke-opacity">0.1</CssParameter>
|
||||
</Stroke>
|
||||
</LineSymbolizer>
|
||||
</Rule>
|
||||
</FeatureTypeStyle>
|
||||
</UserStyle>
|
||||
</NamedLayer>
|
||||
</StyledLayerDescriptor>
|
Loading…
x
Reference in New Issue
Block a user