Skip to content

Commit 811a434

Browse files
authored
Merge pull request #3856 from rldhont/backport-218-wms-130-compliance
Backport 218 wms 130 compliance
2 parents febc819 + f6cd843 commit 811a434

8 files changed

+148
-28
lines changed

src/server/qgsconfigparserutils.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ void QgsConfigParserUtils::appendCRSElementsToLayer( QDomElement& layerElement,
6565
appendCRSElementToLayer( layerElement, CRSPrecedingElement, crs, doc );
6666
}
6767
}
68+
69+
//Support for CRS:84 is mandatory (equals EPSG:4326 with reversed axis)
70+
appendCRSElementToLayer( layerElement, CRSPrecedingElement, QString( "CRS:84" ), doc );
6871
}
6972

7073
void QgsConfigParserUtils::appendCRSElementToLayer( QDomElement& layerElement, const QDomElement& precedingElement,
@@ -77,14 +80,21 @@ void QgsConfigParserUtils::appendCRSElementToLayer( QDomElement& layerElement, c
7780
layerElement.insertAfter( crsElement, precedingElement );
7881
}
7982

80-
void QgsConfigParserUtils::appendLayerBoundingBoxes( QDomElement& layerElem, QDomDocument& doc, const QgsRectangle& layerExtent,
83+
void QgsConfigParserUtils::appendLayerBoundingBoxes( QDomElement& layerElem, QDomDocument& doc, const QgsRectangle& lExtent,
8184
const QgsCoordinateReferenceSystem& layerCRS, const QStringList &crsList, const QStringList& constrainedCrsList )
8285
{
8386
if ( layerElem.isNull() )
8487
{
8588
return;
8689
}
8790

91+
QgsRectangle layerExtent = lExtent;
92+
if ( qgsDoubleNear( layerExtent.xMinimum(), layerExtent.xMaximum() ) || qgsDoubleNear( layerExtent.yMinimum(), layerExtent.yMaximum() ) )
93+
{
94+
//layer bbox cannot be empty
95+
layerExtent.grow( 0.000001 );
96+
}
97+
8898
QgsCoordinateReferenceSystem wgs84 = QgsCRSCache::instance()->crsByOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
8999

90100
QString version = doc.documentElement().attribute( "version" );

src/server/qgsserverprojectparser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ void QgsServerProjectParser::serviceCapabilities( QDomElement& parentElement, QD
584584
//Fees
585585
QDomElement feesElem = propertiesElement.firstChildElement( "WMSFees" );
586586
QDomElement wmsFeesElem = doc.createElement( "Fees" );
587-
QDomText wmsFeesText = doc.createTextNode( "conditions unknown" ); // default value if access conditions are unknown
587+
QDomText wmsFeesText = doc.createTextNode( "None" ); // default value if access conditions are unknown
588588
if ( !feesElem.isNull() && !feesElem.text().isEmpty() )
589589
{
590590
wmsFeesText = doc.createTextNode( feesElem.text() );

src/server/qgswmsserver.cpp

+110-6
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,30 @@ void QgsWMSServer::executeRequest()
147147
}
148148

149149
//version
150-
QString version = mParameters.value( "VERSION", "1.3.0" );
150+
QString version = "1.3.0";
151+
if ( mParameters.contains( "VERSION" ) )
152+
{
153+
version = mParameters.value( "VERSION" );
154+
}
155+
else if ( mParameters.contains( "WMTVER" ) ) //WMTVER needs to be supported by WMS 1.1.1 for backwards compatibility with WMS 1.0.0
156+
{
157+
version = mParameters.value( "WMTVER" );
158+
}
159+
151160
bool getProjectSettings = ( request.compare( "GetProjectSettings", Qt::CaseInsensitive ) == 0 );
152161
if ( getProjectSettings )
153162
{
154163
version = "1.3.0"; //getProjectSettings extends WMS 1.3.0 capabilities
155164
}
156165

166+
if ( version == "1.1.1" )
167+
{
168+
if ( request.compare( "capabilities", Qt::CaseInsensitive ) == 0 )
169+
{
170+
request = QString( "GetCapabilities" );
171+
}
172+
}
173+
157174
//GetCapabilities
158175
if ( request.compare( "GetCapabilities", Qt::CaseInsensitive ) == 0 || getProjectSettings )
159176
{
@@ -423,6 +440,12 @@ QDomDocument QgsWMSServer::getCapabilities( QString version, bool fullProjectInf
423440
hrefString = serviceUrl();
424441
}
425442

443+
//href needs to be a prefix
444+
if ( !hrefString.endsWith( "?" ) && !hrefString.endsWith( "&" ) )
445+
{
446+
hrefString.append( hrefString.contains( "?" ) ? "&" : "?" );
447+
}
448+
426449
if ( version == "1.1.1" )
427450
{
428451
doc = QDomDocument( "WMT_MS_Capabilities SYSTEM 'http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd'" ); //WMS 1.1.1 needs DOCTYPE "SYSTEM http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd"
@@ -556,7 +579,7 @@ QDomDocument QgsWMSServer::getCapabilities( QString version, bool fullProjectInf
556579

557580
//Exception element is mandatory
558581
elem = doc.createElement( "Exception" );
559-
appendFormats( doc, elem, QStringList() << ( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "text/xml" ) );
582+
appendFormats( doc, elem, QStringList() << ( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "XML" ) );
560583
capabilityElement.appendChild( elem );
561584

562585
//UserDefinedSymbolization element
@@ -690,6 +713,10 @@ static QgsRectangle _parseBBOX( const QString &bboxStr, bool &ok )
690713
}
691714

692715
ok = true;
716+
if ( d[2] <= d[0] || d[3] <= d[1] )
717+
{
718+
throw QgsMapServiceException( "InvalidParameterValue", "BBOX is empty" );
719+
}
693720
return QgsRectangle( d[0], d[1], d[2], d[3] );
694721
}
695722

@@ -1456,6 +1483,17 @@ QImage* QgsWMSServer::getMap( HitTest* hitTest )
14561483
// theImage->save( QDir::tempPath() + QDir::separator() + "lastrender.png" );
14571484
//#endif
14581485

1486+
thePainter.end();
1487+
1488+
//test if width / height ratio of image is the same as the ratio of WIDTH / HEIGHT parameters. If not, the image has to be scaled (required by WMS spec)
1489+
int widthParam = mParameters.value( "WIDTH", "0" ).toInt();
1490+
int heightParam = mParameters.value( "HEIGHT", "0" ).toInt();
1491+
if ( widthParam != theImage->width() || heightParam != theImage->height() )
1492+
{
1493+
//scale image
1494+
*theImage = theImage->scaled( widthParam, heightParam, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
1495+
}
1496+
14591497
return theImage;
14601498
}
14611499

@@ -1577,7 +1615,6 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, const QString& version )
15771615
QgsRectangle mapExtent = mMapRenderer->extent();
15781616
double scaleDenominator = scaleCalc.calculate( mapExtent, outputImage->width() );
15791617
mConfigParser->setScaleDenominator( scaleDenominator );
1580-
delete outputImage; //no longer needed for feature info
15811618

15821619
//read FEATURE_COUNT
15831620
int featureCount = 1;
@@ -1617,6 +1654,16 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, const QString& version )
16171654
j = -1;
16181655
}
16191656

1657+
//In case the output image is distorted (WIDTH/HEIGHT ratio not equal to BBOX width/height), I and J need to be adapted as well
1658+
int widthParam = mParameters.value( "WIDTH", "-1" ).toInt();
1659+
int heightParam = mParameters.value( "HEIGHT", "-1" ).toInt();
1660+
if (( i != -1 && j != -1 && widthParam != -1 && heightParam != -1 ) && ( widthParam != outputImage->width() || heightParam != outputImage->height() ) )
1661+
{
1662+
i *= ( outputImage->width() / ( double )widthParam );
1663+
j *= ( outputImage->height() / ( double )heightParam );
1664+
}
1665+
delete outputImage; //no longer needed for feature info
1666+
16201667
//Normally, I/J or X/Y are mandatory parameters.
16211668
//However, in order to make attribute only queries via the FILTER parameter, it is allowed to skip them if the FILTER parameter is there
16221669

@@ -1953,6 +2000,29 @@ QImage* QgsWMSServer::createImage( int width, int height ) const
19532000
}
19542001
}
19552002

2003+
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
2004+
//Required by WMS spec. 1.3.
2005+
bool bboxOk;
2006+
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
2007+
if ( bboxOk )
2008+
{
2009+
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
2010+
double imageWidthHeightRatio = ( double )width / ( double )height;
2011+
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
2012+
{
2013+
if ( mapWidthHeightRatio >= imageWidthHeightRatio )
2014+
{
2015+
//decrease image height
2016+
height = width / mapWidthHeightRatio;
2017+
}
2018+
else
2019+
{
2020+
//decrease image width
2021+
width = height * mapWidthHeightRatio;
2022+
}
2023+
}
2024+
}
2025+
19562026
if ( width < 0 || height < 0 )
19572027
{
19582028
return nullptr;
@@ -1969,6 +2039,19 @@ QImage* QgsWMSServer::createImage( int width, int height ) const
19692039
//transparent parameter
19702040
bool transparent = mParameters.value( "TRANSPARENT" ).compare( "true", Qt::CaseInsensitive ) == 0;
19712041

2042+
//background color
2043+
QString bgColorString = mParameters.value( "BGCOLOR" );
2044+
if ( bgColorString.startsWith( "0x", Qt::CaseInsensitive ) )
2045+
{
2046+
bgColorString.replace( 0, 2, "#" );
2047+
}
2048+
QColor backgroundColor;
2049+
backgroundColor.setNamedColor( bgColorString );
2050+
if ( !backgroundColor.isValid() )
2051+
{
2052+
backgroundColor = QColor( Qt::white );
2053+
}
2054+
19722055
//use alpha channel only if necessary because it slows down performance
19732056
if ( transparent && !jpeg )
19742057
{
@@ -1978,7 +2061,7 @@ QImage* QgsWMSServer::createImage( int width, int height ) const
19782061
else
19792062
{
19802063
theImage = new QImage( width, height, QImage::Format_RGB32 );
1981-
theImage->fill( qRgb( 255, 255, 255 ) );
2064+
theImage->fill( backgroundColor );
19822065
}
19832066

19842067
if ( !theImage )
@@ -2014,17 +2097,32 @@ int QgsWMSServer::configureMapRender( const QPaintDevice* paintDevice ) const
20142097
mMapRenderer->setOutputSize( QSize( paintDevice->width(), paintDevice->height() ), paintDevice->logicalDpiX() );
20152098

20162099
//map extent
2017-
bool bboxOk;
2018-
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX", "0,0,0,0" ), bboxOk );
2100+
bool bboxOk = true;
2101+
QgsRectangle mapExtent;
2102+
if ( mParameters.contains( "BBOX" ) )
2103+
{
2104+
mapExtent = _parseBBOX( mParameters.value( "BBOX", "0,0,0,0" ), bboxOk );
2105+
}
2106+
20192107
if ( !bboxOk )
20202108
{
20212109
//throw a service exception
20222110
throw QgsMapServiceException( "InvalidParameterValue", "Invalid BBOX parameter" );
20232111
}
20242112

2113+
if ( mParameters.contains( "BBOX" ) && mapExtent.isEmpty() )
2114+
{
2115+
throw QgsMapServiceException( "InvalidParameterValue", "BBOX is empty" );
2116+
}
2117+
20252118
QGis::UnitType mapUnits = QGis::Degrees;
20262119

20272120
QString crs = mParameters.value( "CRS", mParameters.value( "SRS" ) );
2121+
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
2122+
{
2123+
crs = QString( "EPSG:4326" );
2124+
mapExtent.invert();
2125+
}
20282126

20292127
QgsCoordinateReferenceSystem outputCRS;
20302128

@@ -2151,6 +2249,12 @@ bool QgsWMSServer::infoPointToMapCoordinates( int i, int j, QgsPoint* infoPoint,
21512249
return false;
21522250
}
21532251

2252+
//check if i, j are in the pixel range of the image
2253+
if ( i < 0 || i > mapRenderer->width() || j < 0 || j > mapRenderer->height() )
2254+
{
2255+
throw QgsMapServiceException( "InvalidPoint", "I/J parameters not within the pixel range" );
2256+
}
2257+
21542258
double xRes = mapRenderer->extent().width() / mapRenderer->width();
21552259
double yRes = mapRenderer->extent().height() / mapRenderer->height();
21562260
infoPoint->setX( mapRenderer->extent().xMinimum() + i * xRes + xRes / 2.0 );

0 commit comments

Comments
 (0)