Skip to content

Commit e79a327

Browse files
author
Patrick Valsecchi
committed
WMS GetCapabilities: override parent's style if they have the same name
When there is a layer group with several sub-layers, the group has a "default" style and the sub-layers each have a "default" layer. QGIS was showing two "default" styles for the sub-layers, which would be confusing to the user and could pick the wrong legend for the sub-layer if the user picked the wrong entry (the first one). Had to create a static lib for wmsprovider in order to unittest it.
1 parent c7a4e5a commit e79a327

File tree

5 files changed

+280
-0
lines changed

5 files changed

+280
-0
lines changed

src/providers/wms/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ INCLUDE_DIRECTORIES(SYSTEM
4141
${QCA_INCLUDE_DIR}
4242
)
4343

44+
ADD_LIBRARY(wmsprovider_a STATIC ${WMS_SRCS} ${WMS_MOC_SRCS})
4445
ADD_LIBRARY(wmsprovider MODULE ${WMS_SRCS} ${WMS_MOC_SRCS})
4546

4647
TARGET_LINK_LIBRARIES(wmsprovider
@@ -50,6 +51,11 @@ TARGET_LINK_LIBRARIES(wmsprovider
5051
${GDAL_LIBRARY} # for OGR_G_CreateGeometryFromJson()
5152
)
5253

54+
TARGET_LINK_LIBRARIES(wmsprovider_a
55+
qgis_core
56+
${QT_QTSCRIPT_LIBRARY}
57+
)
58+
5359
INSTALL (TARGETS wmsprovider
5460
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
5561
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

src/providers/wms/qgswmscapabilities.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,17 @@ void QgsWmsCapabilities::parseLayer( QDomElement const & e, QgsWmsLayerProperty&
905905

906906
parseStyle( e1, styleProperty );
907907

908+
for ( int i = 0; i < layerProperty.style.size(); ++i )
909+
{
910+
if ( layerProperty.style[i].name == styleProperty.name )
911+
{
912+
// override inherited parent's style if it has the same name
913+
// according to the WMS spec, it should not happen, but Mapserver
914+
// does it all the time.
915+
layerProperty.style.remove( i );
916+
break;
917+
}
918+
}
908919
layerProperty.style.push_back( styleProperty );
909920
}
910921
else if ( tagName == "MinScaleDenominator" )

tests/src/providers/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
99
${CMAKE_SOURCE_DIR}/src/core/auth
1010
${CMAKE_SOURCE_DIR}/src/core/geometry
1111
${CMAKE_SOURCE_DIR}/src/core/raster
12+
${CMAKE_SOURCE_DIR}/src/providers/wms
1213
)
1314
INCLUDE_DIRECTORIES(SYSTEM
1415
${QT_INCLUDE_DIR}
@@ -84,6 +85,10 @@ SET_TARGET_PROPERTIES(qgis_wcsprovidertest PROPERTIES
8485
8586
ADD_QGIS_TEST(gdalprovidertest testqgsgdalprovider.cpp)
8687
88+
ADD_QGIS_TEST(wmscapabilititestest
89+
testqgswmscapabilities.cpp)
90+
TARGET_LINK_LIBRARIES(qgis_wmscapabilititestest wmsprovider_a)
91+
8792
#############################################################
8893
# WCS public servers test:
8994
# No need to test on all platforms
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <QFile>
2+
#include <QObject>
3+
#include <QtTest/QtTest>
4+
#include <qgswmscapabilities.h>
5+
#include <qgsapplication.h>
6+
7+
/** \ingroup UnitTests
8+
* This is a unit test for the WMS capabilities parser.
9+
*/
10+
class TestQgsWmsCapabilities: public QObject
11+
{
12+
Q_OBJECT
13+
private slots:
14+
15+
void initTestCase()
16+
{
17+
// init QGIS's paths - true means that all path will be inited from prefix
18+
QgsApplication::init();
19+
QgsApplication::initQgis();
20+
}
21+
22+
//runs after all tests
23+
void cleanupTestCase()
24+
{
25+
QgsApplication::exitQgis();
26+
}
27+
28+
29+
void read()
30+
{
31+
QgsWmsCapabilities capabilities;
32+
33+
QFile file( QString( TEST_DATA_DIR ) + "/provider/GetCapabilities.xml" );
34+
QVERIFY( file.open( QIODevice::ReadOnly | QIODevice::Text ) );
35+
const QByteArray content = file.readAll();
36+
QVERIFY( content.size() > 0 );
37+
const QgsWmsParserSettings config;
38+
39+
QVERIFY( capabilities.parseResponse( content, config ) );
40+
QCOMPARE( capabilities.supportedLayers().size(), 5 );
41+
QCOMPARE( capabilities.supportedLayers()[0].name, QString( "agri_zones" ) );
42+
QCOMPARE( capabilities.supportedLayers()[1].name, QString( "buildings" ) );
43+
QCOMPARE( capabilities.supportedLayers()[2].name, QString( "land_surveing_parcels" ) );
44+
QCOMPARE( capabilities.supportedLayers()[3].name, QString( "cadastre" ) );
45+
QCOMPARE( capabilities.supportedLayers()[4].name, QString( "test" ) );
46+
47+
// make sure the default style is not seen twice in the child layers
48+
QCOMPARE( capabilities.supportedLayers()[3].style.size(), 1 );
49+
QCOMPARE( capabilities.supportedLayers()[3].style[0].name, QString( "default" ) );
50+
QCOMPARE( capabilities.supportedLayers()[1].style.size(), 1 );
51+
QCOMPARE( capabilities.supportedLayers()[1].style[0].name, QString( "default" ) );
52+
QCOMPARE( capabilities.supportedLayers()[2].style.size(), 1 );
53+
QCOMPARE( capabilities.supportedLayers()[2].style[0].name, QString( "default" ) );
54+
55+
// check it can read 2 styles for a layer and that the legend URL is OK
56+
QCOMPARE( capabilities.supportedLayers()[0].style.size(), 2 );
57+
QCOMPARE( capabilities.supportedLayers()[0].style[0].name, QString( "yt_style" ) );
58+
QCOMPARE( capabilities.supportedLayers()[0].style[0].legendUrl.size(), 1 );
59+
QCOMPARE( capabilities.supportedLayers()[0].style[0].legendUrl[0].onlineResource.xlinkHref,
60+
QString( "http://www.example.com/yt.png" ) );
61+
QCOMPARE( capabilities.supportedLayers()[0].style[1].name, QString( "fb_style" ) );
62+
QCOMPARE( capabilities.supportedLayers()[0].style[1].legendUrl.size(), 1 );
63+
QCOMPARE( capabilities.supportedLayers()[0].style[1].legendUrl[0].onlineResource.xlinkHref,
64+
QString( "http://www.example.com/fb.png" ) );
65+
}
66+
67+
};
68+
69+
QTEST_MAIN( TestQgsWmsCapabilities )
70+
#include "testqgswmscapabilities.moc"
+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<WMS_Capabilities version="1.3.0" xmlns="http://www.opengis.net/wms" xmlns:sld="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ms="http://mapserver.gis.umn.edu/mapserver" xsi:schemaLocation="http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/sld_capabilities.xsd http://mapserver.gis.umn.edu/mapserver http://localhost:8380/mapserv?service=WMS&amp;version=1.3.0&amp;request=GetSchemaExtension">
3+
<!-- MapServer version 7.0.1 OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=CAIRO SUPPORTS=SVG_SYMBOLS SUPPORTS=RSVG SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUPPORTS=THREADS SUPPORTS=GEOS INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE -->
4+
<Service>
5+
<Name>WMS</Name>
6+
<Title>Test</Title>
7+
<Abstract>Test</Abstract>
8+
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/>
9+
<ContactInformation>
10+
</ContactInformation>
11+
<MaxWidth>5000</MaxWidth>
12+
<MaxHeight>5000</MaxHeight>
13+
</Service>
14+
15+
<Capability>
16+
<Request>
17+
<GetCapabilities>
18+
<Format>text/xml</Format>
19+
<DCPType>
20+
<HTTP>
21+
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Get>
22+
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Post>
23+
</HTTP>
24+
</DCPType>
25+
</GetCapabilities>
26+
<GetMap>
27+
<Format>image/jpeg</Format>
28+
<Format>image/png</Format>
29+
<DCPType>
30+
<HTTP>
31+
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Get>
32+
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Post>
33+
</HTTP>
34+
</DCPType>
35+
</GetMap>
36+
<GetFeatureInfo>
37+
<Format>text/plain</Format>
38+
<Format>application/vnd.ogc.gml</Format>
39+
<DCPType>
40+
<HTTP>
41+
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Get>
42+
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Post>
43+
</HTTP>
44+
</DCPType>
45+
</GetFeatureInfo>
46+
<sld:DescribeLayer>
47+
<Format>text/xml</Format>
48+
<DCPType>
49+
<HTTP>
50+
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Get>
51+
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Post>
52+
</HTTP>
53+
</DCPType>
54+
</sld:DescribeLayer>
55+
<sld:GetLegendGraphic>
56+
<Format>image/jpeg</Format>
57+
<Format>image/png</Format>
58+
<Format>image/png; mode=8bit</Format>
59+
<DCPType>
60+
<HTTP>
61+
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Get>
62+
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Post>
63+
</HTTP>
64+
</DCPType>
65+
</sld:GetLegendGraphic>
66+
<ms:GetStyles>
67+
<Format>text/xml</Format>
68+
<DCPType>
69+
<HTTP>
70+
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Get>
71+
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost:8380/mapserv?"/></Post>
72+
</HTTP>
73+
</DCPType>
74+
</ms:GetStyles>
75+
</Request>
76+
<Exception>
77+
<Format>XML</Format>
78+
<Format>BLANK</Format>
79+
</Exception>
80+
<sld:UserDefinedSymbolization SupportSLD="1" UserLayer="0" UserStyle="1" RemoteWFS="0" InlineFeature="0" RemoteWCS="0"/>
81+
<Layer>
82+
<Name>test</Name>
83+
<Title>Test</Title>
84+
<Abstract>Test</Abstract>
85+
<CRS>EPSG:2056</CRS>
86+
<EX_GeographicBoundingBox>
87+
<westBoundLongitude>5.01393</westBoundLongitude>
88+
<eastBoundLongitude>11.4774</eastBoundLongitude>
89+
<southBoundLatitude>45.356</southBoundLatitude>
90+
<northBoundLatitude>48.3001</northBoundLatitude>
91+
</EX_GeographicBoundingBox>
92+
<BoundingBox CRS="EPSG:2056" minx="2.42e+06" miny="1.03e+06" maxx="2.9e+06" maxy="1.35e+06"/>
93+
<Layer queryable="1" opaque="0" cascaded="0">
94+
<Name>agri_zones</Name>
95+
<Title>agri_zones</Title>
96+
<CRS>EPSG:2056</CRS>
97+
<EX_GeographicBoundingBox>
98+
<westBoundLongitude>5.01393</westBoundLongitude>
99+
<eastBoundLongitude>11.4774</eastBoundLongitude>
100+
<southBoundLatitude>45.356</southBoundLatitude>
101+
<northBoundLatitude>48.3001</northBoundLatitude>
102+
</EX_GeographicBoundingBox>
103+
<BoundingBox CRS="EPSG:2056" minx="2.42e+06" miny="1.03e+06" maxx="2.9e+06" maxy="1.35e+06"/>
104+
<MetadataURL type="TC211">
105+
<Format>text/html</Format>
106+
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.example.com/bar"/>
107+
</MetadataURL>
108+
<Style>
109+
<Name>yt_style</Name>
110+
<Title>yt_style</Title>
111+
<LegendURL width="23" height="19">
112+
<Format>image/png</Format>
113+
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.example.com/yt.png"/>
114+
</LegendURL>
115+
</Style>
116+
<Style>
117+
<Name>fb_style</Name>
118+
<Title>fb_style</Title>
119+
<LegendURL width="23" height="19">
120+
<Format>image/png</Format>
121+
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.example.com/fb.png"/>
122+
</LegendURL>
123+
</Style>
124+
</Layer>
125+
<Layer>
126+
<Name>cadastre</Name>
127+
<Title>cadastre</Title>
128+
<Abstract>cadastre</Abstract>
129+
<Style>
130+
<Name>default</Name>
131+
<Title>default</Title>
132+
<LegendURL width="88" height="50">
133+
<Format>image/png</Format>
134+
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://localhost:8380/mapserv?version=1.3.0&amp;service=WMS&amp;request=GetLegendGraphic&amp;sld_version=1.1.0&amp;layer=cadastre&amp;format=image/png&amp;STYLE=default"/>
135+
</LegendURL>
136+
</Style>
137+
<Layer queryable="1" opaque="0" cascaded="0">
138+
<Name>buildings</Name>
139+
<Title>buildings</Title>
140+
<CRS>EPSG:2056</CRS>
141+
<EX_GeographicBoundingBox>
142+
<westBoundLongitude>5.01393</westBoundLongitude>
143+
<eastBoundLongitude>11.4774</eastBoundLongitude>
144+
<southBoundLatitude>45.356</southBoundLatitude>
145+
<northBoundLatitude>48.3001</northBoundLatitude>
146+
</EX_GeographicBoundingBox>
147+
<BoundingBox CRS="EPSG:2056" minx="2.42e+06" miny="1.03e+06" maxx="2.9e+06" maxy="1.35e+06"/>
148+
<MetadataURL type="TC211">
149+
<Format>text/html</Format>
150+
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.example.com/bar"/>
151+
</MetadataURL>
152+
<Style>
153+
<Name>default</Name>
154+
<Title>default</Title>
155+
<LegendURL width="88" height="20">
156+
<Format>image/png</Format>
157+
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.example.com/buildings.png"/>
158+
</LegendURL>
159+
</Style>
160+
</Layer>
161+
<Layer queryable="1" opaque="0" cascaded="0">
162+
<Name>land_surveing_parcels</Name>
163+
<Title>land_surveing_parcels</Title>
164+
<CRS>EPSG:2056</CRS>
165+
<EX_GeographicBoundingBox>
166+
<westBoundLongitude>5.01393</westBoundLongitude>
167+
<eastBoundLongitude>11.4774</eastBoundLongitude>
168+
<southBoundLatitude>45.356</southBoundLatitude>
169+
<northBoundLatitude>48.3001</northBoundLatitude>
170+
</EX_GeographicBoundingBox>
171+
<BoundingBox CRS="EPSG:2056" minx="2.42e+06" miny="1.03e+06" maxx="2.9e+06" maxy="1.35e+06"/>
172+
<MetadataURL type="TC211">
173+
<Format>text/html</Format>
174+
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.example.com/bar"/>
175+
</MetadataURL>
176+
<Style>
177+
<Name>default</Name>
178+
<Title>default</Title>
179+
<LegendURL width="84" height="20">
180+
<Format>image/png</Format>
181+
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://localhost:8380/mapserv?version=1.3.0&amp;service=WMS&amp;request=GetLegendGraphic&amp;sld_version=1.1.0&amp;layer=land_surveing_parcels&amp;format=image/png&amp;STYLE=default"/>
182+
</LegendURL>
183+
</Style>
184+
</Layer>
185+
</Layer>
186+
</Layer>
187+
</Capability>
188+
</WMS_Capabilities>

0 commit comments

Comments
 (0)