Skip to content

Commit

Permalink
Merge pull request #8220 from pblottiere/server_invalid_bbox
Browse files Browse the repository at this point in the history
[server] Fixes #5520 - Invalid BBOX in WMS GetCapabilities
  • Loading branch information
pblottiere committed Oct 24, 2018
2 parents b8469dc + e1cdd7e commit c41a5d0
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 15 deletions.
19 changes: 18 additions & 1 deletion src/server/services/wms/qgswmsgetcapabilities.cpp
Expand Up @@ -1017,7 +1017,24 @@ namespace QgsWms
appendCrsElementsToLayer( doc, layerElem, crsList, outputCrsList );

//Ex_GeographicBoundingBox
appendLayerBoundingBoxes( doc, layerElem, l->extent(), l->crs(), crsList, outputCrsList, project );
QgsRectangle extent = l->extent(); // layer extent by default
if ( l->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( l );
if ( vl && vl->featureCount() == 0 )
{
// if there's no feature, use the wms extent defined in the
// project...
extent = QgsServerProjectUtils::wmsExtent( *project );
if ( extent.isNull() )
{
// or the CRS extent otherwise
extent = vl->crs().bounds();
}
}
}

appendLayerBoundingBoxes( doc, layerElem, extent, l->crs(), crsList, outputCrsList, project );
}

// add details about supported styles of the layer
Expand Down
21 changes: 7 additions & 14 deletions tests/src/python/test_qgsserver_wms.py
Expand Up @@ -153,19 +153,15 @@ def test_wms_getcapabilities_without_title(self):
# Empty title in project leads to a Layer element without Name, Title
# and Abstract tags. However, it should still have a CRS and a BBOX
# according to OGC specifications tests.
project = os.path.join(self.testdata_path, "test_project_without_title.qgs")
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(project),
"SERVICE": "WMS",
"VERSION": "1.3.0",
"REQUEST": "GetCapabilities",
"STYLES": ""
}.items())])

r, h = self._result(self._execute_request(qs))

self.wms_request_compare('GetCapabilities', reference_file='wms_getcapabilities_without_title', project='test_project_without_title.qgs')

def test_wms_getcapabilitie_empty_spatial_layer(self):
# The project contains a spatial layer without feature and the WMS
# extent is not configured in the project.
self.wms_request_compare('GetCapabilities',
reference_file='wms_getcapabilities_empty_spatial_layer',
project='test_project_empty_spatial_layer.qgz')

def test_wms_getcapabilities_versions(self):
# default version 1.3.0 when empty VERSION parameter
project = os.path.join(self.testdata_path, "test_project.qgs")
Expand All @@ -175,7 +171,6 @@ def test_wms_getcapabilities_versions(self):
"REQUEST": "GetCapabilities",
}.items())])

r, h = self._result(self._execute_request(qs))
self.wms_request_compare(qs, reference_file='wms_getcapabilities_1_3_0', version='')

# default version 1.3.0 when VERSION = 1.3.0 parameter
Expand All @@ -186,7 +181,6 @@ def test_wms_getcapabilities_versions(self):
"REQUEST": "GetCapabilities",
}.items())])

r, h = self._result(self._execute_request(qs))
self.wms_request_compare(qs, reference_file='wms_getcapabilities_1_3_0', version='1.3.0')

# version 1.1.1
Expand All @@ -207,7 +201,6 @@ def test_wms_getcapabilities_versions(self):
"REQUEST": "GetCapabilities",
}.items())])

r, h = self._result(self._execute_request(qs))
self.wms_request_compare(qs, reference_file='wms_getcapabilities_1_3_0', version='33.33.33')

def test_wms_getcapabilities_url(self):
Expand Down
Binary file added tests/testdata/empty_spatial_layer.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions tests/testdata/empty_spatial_layer.prj
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
1 change: 1 addition & 0 deletions tests/testdata/empty_spatial_layer.qpj
@@ -0,0 +1 @@
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]
Binary file added tests/testdata/empty_spatial_layer.shp
Binary file not shown.
Binary file added tests/testdata/empty_spatial_layer.shx
Binary file not shown.
Binary file not shown.
132 changes: 132 additions & 0 deletions tests/testdata/qgis_server/wms_getcapabilities_empty_spatial_layer.txt
@@ -0,0 +1,132 @@
*****
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8"?>
<WMS_Capabilities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:qgs="http://www.qgis.org/wms" xmlns="http://www.opengis.net/wms" 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://www.qgis.org/wms https://www.qgis.org/?*****" version="1.3.0" xmlns:sld="http://www.opengis.net/sld">
<Service>
<Name>WMS</Name>
<KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</KeywordList>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?*****" xmlns:xlink="http://www.w3.org/1999/xlink"/>
<Fees>None</Fees>
<AccessConstraints>None</AccessConstraints>
</Service>
<Capability>
<Request>
<GetCapabilities>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?*****" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</Get>
</HTTP>
</DCPType>
</GetCapabilities>
<GetMap>
<Format>image/jpeg</Format>
<Format>image/png</Format>
<Format>image/png; mode=16bit</Format>
<Format>image/png; mode=8bit</Format>
<Format>image/png; mode=1bit</Format>
<Format>application/dxf</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?*****" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</Get>
</HTTP>
</DCPType>
</GetMap>
<GetFeatureInfo>
<Format>text/plain</Format>
<Format>text/html</Format>
<Format>text/xml</Format>
<Format>application/vnd.ogc.gml</Format>
<Format>application/vnd.ogc.gml/3.1.1</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?*****" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</Get>
</HTTP>
</DCPType>
</GetFeatureInfo>
<sld:GetLegendGraphic>
<Format>image/jpeg</Format>
<Format>image/png</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?*****" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</Get>
</HTTP>
</DCPType>
</sld:GetLegendGraphic>
<sld:DescribeLayer>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?*****" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</Get>
</HTTP>
</DCPType>
</sld:DescribeLayer>
<qgs:GetStyles>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?*****" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</Get>
</HTTP>
</DCPType>
</qgs:GetStyles>
</Request>
<Exception>
<Format>XML</Format>
</Exception>
<sld:UserDefinedSymbolization SupportSLD="1" RemoteWCS="0" UserLayer="0" InlineFeature="0" RemoteWFS="0" UserStyle="1"/>
<Layer>
<KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</KeywordList>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:3857</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-180</westBoundLongitude>
<eastBoundLongitude>180</eastBoundLongitude>
<southBoundLatitude>-81.8182</southBoundLatitude>
<northBoundLatitude>81.8182</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox maxy="1.6824e+7" maxx="2.00375e+7" miny="-1.6824e+7" CRS="EPSG:3857" minx="-2.00375e+7"/>
<BoundingBox maxy="180" maxx="81.8182" miny="-180" CRS="EPSG:4326" minx="-81.8182"/>
<Layer queryable="1">
<Name>empty_spatial_layer</Name>
<Title>empty_spatial_layer</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:3857</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-180</westBoundLongitude>
<eastBoundLongitude>180</eastBoundLongitude>
<southBoundLatitude>-90</southBoundLatitude>
<northBoundLatitude>90</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox maxy="1.6824e+7" maxx="2.00375e+7" miny="-1.6824e+7" CRS="EPSG:3857" minx="-2.00375e+7"/>
<BoundingBox maxy="180" maxx="90" miny="-180" CRS="EPSG:4326" minx="-90"/>
<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>
</Capability>
</WMS_Capabilities>

0 comments on commit c41a5d0

Please sign in to comment.