Skip to content
Permalink
Browse files

Merge pull request #7462 from tcoupin/fix-wms

[server] Multiples fixes for wms server
  • Loading branch information
rldhont committed Aug 1, 2018
2 parents ada8933 + 906022e commit ad7417a5cc74ce25f424ca1d934a944917e775f6
@@ -9910,7 +9910,7 @@ void QgisApp::legendGroupSetWmsData()
QgsGroupWmsDataDialog *dlg = new QgsGroupWmsDataDialog( this );
dlg->setGroupShortName( currentGroup->customProperty( QStringLiteral( "wmsShortName" ) ).toString() );
dlg->setGroupTitle( currentGroup->customProperty( QStringLiteral( "wmsTitle" ) ).toString() );
dlg->setGroupTitle( currentGroup->customProperty( QStringLiteral( "wmsAbstract" ) ).toString() );
dlg->setGroupAbstract( currentGroup->customProperty( QStringLiteral( "wmsAbstract" ) ).toString() );
if ( dlg->exec() )
{
currentGroup->setCustomProperty( QStringLiteral( "wmsShortName" ), dlg->groupShortName() );
@@ -20,6 +20,7 @@
#include "qgslayertreemodel.h"
#include "qgslayertreeutils.h"
#include "qgssettings.h"
#include "qgsziputils.h"

#include <QDomDocument>
#include <QFileDialog>
@@ -54,7 +55,7 @@ QgsProjectLayerGroupDialog::QgsProjectLayerGroupDialog( QWidget *parent, const Q
QgsSettings settings;

mProjectFileWidget->setStorageMode( QgsFileWidget::GetFile );
mProjectFileWidget->setFilter( tr( "QGIS files" ) + QStringLiteral( " (*.qgs *.QGS)" ) );
mProjectFileWidget->setFilter( tr( "QGIS files" ) + QStringLiteral( " (*.qgs *.QGS *.qgz *.QGZ)" ) );
mProjectFileWidget->setDialogTitle( tr( "Select Project File" ) );
mProjectFileWidget->setDefaultRoot( settings.value( QStringLiteral( "/qgis/last_embedded_project_path" ), QDir::homePath() ).toString() );
if ( !projectFile.isEmpty() )
@@ -168,11 +169,37 @@ void QgsProjectLayerGroupDialog::changeProjectFile()
}

QDomDocument projectDom;
if ( QgsZipUtils::isZipFile( mProjectFileWidget->filePath() ) )
{
QgsProjectArchive archive;

// unzip the archive
if ( !archive.unzip( mProjectFileWidget->filePath() ) )
{
return;
}

// test if zip provides a .qgs file
if ( archive.projectFile().isEmpty() )
{
return;
}

projectFile.setFileName( archive.projectFile() );
if ( !projectFile.exists() )
{
return;
}
}

if ( !projectDom.setContent( &projectFile ) )
{
return;
}




mRootGroup->removeAllChildren();

QDomElement layerTreeElem = projectDom.documentElement().firstChildElement( QStringLiteral( "layer-tree-group" ) );
@@ -947,7 +947,7 @@ namespace QgsWms
// remove unwanted layers (restricted layers, ...)
removeUnwantedLayers( layers, scaleDenominator );
// remove non identifiable layers
removeNonIdentifiableLayers( layers );
//removeNonIdentifiableLayers( layers );

Q_FOREACH ( QgsMapLayer *layer, layers )
{
@@ -1245,11 +1245,17 @@ namespace QgsWms
Q_FOREACH ( QString queryLayer, queryLayers )
{
bool validLayer = false;
bool queryableLayer = true;
Q_FOREACH ( QgsMapLayer *layer, layers )
{
if ( queryLayer == layerNickname( *layer ) )
{
validLayer = true;
queryableLayer = !mProject->nonIdentifiableLayers().contains( layer->id() ) ;
if ( !queryableLayer )
{
break;
}

QDomElement layerElement;
if ( infoFormat == QgsWmsParameters::Format::GML )
@@ -1312,12 +1318,16 @@ namespace QgsWms
break;
}
}

if ( !validLayer && !mNicknameLayers.contains( queryLayer ) )
if ( !validLayer && !mNicknameLayers.contains( queryLayer ) && !mLayerGroups.contains( queryLayer ) )
{
QString msg = QObject::tr( "Layer '%1' not found" ).arg( queryLayer );
throw QgsBadRequestException( QStringLiteral( "LayerNotDefined" ), msg );
}
else if ( ( validLayer && !queryableLayer ) || ( !validLayer && mLayerGroups.contains( queryLayer ) ) )
{
QString msg = QObject::tr( "Layer '%1' is not queryable" ).arg( queryLayer );
throw QgsBadRequestException( QStringLiteral( "LayerNotQueryable" ), msg );
}
}

if ( featuresRect )
@@ -2411,7 +2421,13 @@ namespace QgsWms
{
if ( child->nodeType() == QgsLayerTreeNode::NodeGroup )
{
initLayerGroupsRecursive( static_cast<const QgsLayerTreeGroup *>( child ), child->name() );
QString name = child->customProperty( QStringLiteral( "wmsShortName" ) ).toString();

if ( name.isEmpty() )
name = child->name();

initLayerGroupsRecursive( static_cast<const QgsLayerTreeGroup *>( child ), name );

}
}
}
@@ -57,6 +57,33 @@ def testGetFeatureInfo(self):
'query_layers=testlayer%20%C3%A8%C3%A9&X=190&Y=320',
'wms_getfeatureinfo-text-xml')

# Test getfeatureinfo on non queryable layer
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer3&styles=&' +
'info_format=text%2Fxml&transparent=true&' +
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
'query_layers=testlayer3&X=190&Y=320',
'wms_getfeatureinfo-testlayer3-notqueryable')

# Test getfeatureinfo on group without shortname (no queryable...)
self.wms_request_compare('GetFeatureInfo',
'&layers=groupwithoutshortname&styles=&' +
'info_format=text%2Fxml&transparent=true&' +
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
'query_layers=groupwithoutshortname&X=190&Y=320',
'wms_getfeatureinfo-groupwithoutshortname-notqueryable')

# Test getfeatureinfo on group with shortname (no queryable...)
self.wms_request_compare('GetFeatureInfo',
'&layers=group_name&styles=&' +
'info_format=text%2Fxml&transparent=true&' +
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
'query_layers=group_name&X=190&Y=320',
'wms_getfeatureinfo-group_name-notqueryable')

# Test getfeatureinfo response html
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
@@ -1037,6 +1037,24 @@ def test_wms_getmap_group(self):

self.assertEqual(r_individual, r_group, 'Individual layers query and group layers query results should be identical')

qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectGroupsPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetMap",
"LAYERS": "group_short_name",
"STYLES": "",
"FORMAT": "image/png",
"BBOX": "-16817707,-4710778,5696513,14587125",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857"
}.items())])

r_group, _ = self._result(self._execute_request(qs))

self.assertEqual(r_individual, r_group, 'Individual layers query and group layers query with short name results should be identical')

qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectGroupsPath),
"SERVICE": "WMS",
@@ -116,6 +116,30 @@ Content-Type: text/xml; charset=utf-8
<KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</KeywordList>
<Layer queryable="1">
<Name>layer_with_short_name</Name>
<Title>A Layer with a short name</Title>
<Abstract>A Layer with an abstract</Abstract>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:3857</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>8.20346</westBoundLongitude>
<eastBoundLongitude>8.20355</eastBoundLongitude>
<southBoundLatitude>44.9014</southBoundLatitude>
<northBoundLatitude>44.9015</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox maxy="5.60603e+06" maxx="913215" miny="5.60601e+06" CRS="EPSG:3857" minx="913205"/>
<BoundingBox maxy="8.20355" maxx="44.9015" miny="8.20346" CRS="EPSG:4326" minx="44.9014"/>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?MAP=tests/testdata/qgis_server/test_project.qgs&amp;SERVICE=WMS&amp;VERSION=1.3.0&amp;REQUEST=GetLegendGraphic&amp;LAYER=layer_with_short_name&amp;FORMAT=image/png&amp;STYLE=default" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="1">
<Name>testlayer èé</Name>
<Title>A test vector layer</Title>
@@ -140,6 +164,83 @@ Content-Type: text/xml; charset=utf-8
</LegendURL>
</Style>
</Layer>
<Layer>
<Name>group_name</Name>
<Title>Group title</Title>
<Abstract>Group abstract</Abstract>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:3857</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>8.20346</westBoundLongitude>
<eastBoundLongitude>8.20355</eastBoundLongitude>
<southBoundLatitude>44.9014</southBoundLatitude>
<northBoundLatitude>44.9015</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox maxy="5.60603e+06" maxx="913215" miny="5.60601e+06" CRS="EPSG:3857" minx="913205"/>
<BoundingBox maxy="8.20355" maxx="44.9015" miny="8.20346" CRS="EPSG:4326" minx="44.9014"/>
<Layer queryable="1">
<Name>testlayer2</Name>
<Title>testlayer2</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:3857</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>8.20346</westBoundLongitude>
<eastBoundLongitude>8.20355</eastBoundLongitude>
<southBoundLatitude>44.9014</southBoundLatitude>
<northBoundLatitude>44.9015</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox maxy="5.60603e+06" maxx="913215" miny="5.60601e+06" CRS="EPSG:3857" minx="913205"/>
<BoundingBox maxy="8.20355" maxx="44.9015" miny="8.20346" CRS="EPSG:4326" minx="44.9014"/>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?*****" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</LegendURL>
</Style>
</Layer>
</Layer>
<Layer>
<Name>groupwithoutshortname</Name>
<Title>groupwithoutshortname</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:3857</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>8.20346</westBoundLongitude>
<eastBoundLongitude>8.20355</eastBoundLongitude>
<southBoundLatitude>44.9014</southBoundLatitude>
<northBoundLatitude>44.9015</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox maxy="5.60603e+06" maxx="913215" miny="5.60601e+06" CRS="EPSG:3857" minx="913205"/>
<BoundingBox maxy="8.20355" maxx="44.9015" miny="8.20346" CRS="EPSG:4326" minx="44.9014"/>
<Layer queryable="0">
<Name>testlayer3</Name>
<Title>testlayer3</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:3857</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>8.20346</westBoundLongitude>
<eastBoundLongitude>8.20355</eastBoundLongitude>
<southBoundLatitude>44.9014</southBoundLatitude>
<northBoundLatitude>44.9015</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox maxy="5.60603e+06" maxx="913215" miny="5.60601e+06" CRS="EPSG:3857" minx="913205"/>
<BoundingBox maxy="8.20355" maxx="44.9015" miny="8.20346" CRS="EPSG:4326" minx="44.9014"/>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL>
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?*****" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</LegendURL>
</Style>
</Layer>
</Layer>
</Layer>
</Capability>
</WMS_Capabilities>
@@ -2,9 +2,9 @@
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8"?>
<OWSContext xmlns:ogc="http://www.opengis.net/ogc" version="0.3.1" xmlns:context="http://www.opengis.net/context" xmlns="http://www.opengis.net/ows-context" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ows-context="http://www.opengis.net/ows-context" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" id="ows-context-test_project" xmlns:ows="http://www.opengis.net/ows" xmlns:ns9="http://www.w3.org/2005/Atom" xmlns:ins="http://www.inspire.org">
<OWSContext xmlns:gml="http://www.opengis.net/gml" xmlns:context="http://www.opengis.net/context" xmlns:ows="http://www.opengis.net/ows" xmlns="http://www.opengis.net/ows-context" xmlns:ins="http://www.inspire.org" id="ows-context-test_project" xmlns:ogc="http://www.opengis.net/ogc" xmlns:ows-context="http://www.opengis.net/ows-context" xmlns:ns9="http://www.w3.org/2005/Atom" xmlns:kml="http://www.opengis.net/kml/2.2" version="0.3.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sld="http://www.opengis.net/sld" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<General>
<Window width="800" height="600"/>
<Window height="600" width="800"/>
<ows:Title>QGIS TestProject</ows:Title>
<ows:Abstract><![CDATA[Some UTF8 text èòù]]></ows:Abstract>
<ows:BoundingBox crs="EPSG:4326">
@@ -13,10 +13,36 @@ Content-Type: text/xml; charset=utf-8
</ows:BoundingBox>
</General>
<ResourceList>
<Layer group="groupwithoutshortname" hidden="true" queryable="false" id="testlayer3" name="testlayer3" opacity="1">
<ows:Title>testlayer3</ows:Title>
<ows:OutputFormat>image/png</ows:OutputFormat>
<Server default="true" service="urn:ogc:serviceType:WMS" version="1.3.0">
<OnlineResource xlink:href="https://www.qgis.org/?*****"/>
</Server>
<StyleList>
<Style current="true">
<Name>default</Name>
<Title>default</Title>
</Style>
</StyleList>
</Layer>
<Layer group="groupwithshortname" hidden="true" queryable="true" id="testlayer2" name="testlayer2" opacity="1">
<ows:Title>testlayer2</ows:Title>
<ows:OutputFormat>image/png</ows:OutputFormat>
<Server default="true" service="urn:ogc:serviceType:WMS" version="1.3.0">
<OnlineResource xlink:href="https://www.qgis.org/?*****"/>
</Server>
<StyleList>
<Style current="true">
<Name>default</Name>
<Title>default</Title>
</Style>
</StyleList>
</Layer>
<Layer hidden="true" queryable="true" id="testlayer_èé" name="testlayer èé" opacity="1">
<ows:Title>A test vector layer</ows:Title>
<ows:OutputFormat>image/png</ows:OutputFormat>
<Server version="1.3.0" default="true" service="urn:ogc:serviceType:WMS">
<Server default="true" service="urn:ogc:serviceType:WMS" version="1.3.0">
<OnlineResource xlink:href="https://www.qgis.org/?*****"/>
</Server>
<ows:Abstract>A test vector layer with unicode òà</ows:Abstract>
@@ -27,5 +53,19 @@ Content-Type: text/xml; charset=utf-8
</Style>
</StyleList>
</Layer>
<Layer hidden="true" queryable="true" id="layer_with_short_name" name="layer_with_short_name" opacity="1">
<ows:Title>A Layer with a short name</ows:Title>
<ows:OutputFormat>image/png</ows:OutputFormat>
<Server default="true" service="urn:ogc:serviceType:WMS" version="1.3.0">
<OnlineResource xlink:href="https://www.qgis.org/?*****"/>
</Server>
<ows:Abstract>A Layer with an abstract</ows:Abstract>
<StyleList>
<Style current="true">
<Name>default</Name>
<Title>default</Title>
</Style>
</StyleList>
</Layer>
</ResourceList>
</OWSContext>
</OWSContext>

0 comments on commit ad7417a

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