diff --git a/src/providers/wms/qgswmsprovider.cpp b/src/providers/wms/qgswmsprovider.cpp index d084c01b977e..43a1c4810650 100644 --- a/src/providers/wms/qgswmsprovider.cpp +++ b/src/providers/wms/qgswmsprovider.cpp @@ -376,6 +376,12 @@ void QgsWmsProvider::setImageCrs( QString const & crs ) } } +void QgsWmsProvider::setQueryItem( QUrl &url, QString item, QString value ) +{ + url.removeQueryItem( item ); + url.addQueryItem( item, value ); +} + QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, int pixelHeight ) { QgsDebugMsg( "Entering." ); @@ -426,8 +432,6 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i crsKey = "CRS"; } - QString url = mIgnoreGetMapUrl ? mBaseUrl : getMapUrl(); - cachedImage = new QImage( pixelWidth, pixelHeight, QImage::Format_ARGB32 ); cachedImage->fill( 0 ); cachedViewExtent = viewExtent; @@ -474,59 +478,52 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i .arg( viewExtent.xMaximum(), 0, 'f' ) .arg( viewExtent.yMaximum(), 0, 'f' ); - // Width in WMS format - QString width; - width = width.setNum( pixelWidth ); - - // Height in WMS format - QString height; - height = height.setNum( pixelHeight ); - - url += "SERVICE=WMS"; - url += "&VERSION=" + mCapabilities.version; - url += "&REQUEST=GetMap"; - url += "&BBOX=" + bbox; - url += "&" + crsKey + "=" + imageCrs; - url += "&WIDTH=" + width; - url += "&HEIGHT=" + height; - url += "&LAYERS=" + layers; - url += "&STYLES=" + styles; - url += "&FORMAT=" + imageMimeType; + QUrl url( mIgnoreGetMapUrl ? mBaseUrl : getMapUrl() ); + setQueryItem( url, "SERVICE", "WMS" ); + setQueryItem( url, "VERSION", mCapabilities.version ); + setQueryItem( url, "REQUEST", "GetMap" ); + setQueryItem( url, "BBOX", bbox ); + setQueryItem( url, crsKey, imageCrs ); + setQueryItem( url, "WIDTH", QString::number( pixelWidth ) ); + setQueryItem( url, "HEIGHT", QString::number( pixelHeight ) ); + setQueryItem( url, "LAYERS", layers ); + setQueryItem( url, "STYLES", styles ); + setQueryItem( url, "FORMAT", imageMimeType ); //DPI parameter is accepted by QGIS mapserver (and ignored by the other WMS servers) if ( mDpi != -1 ) { - url += "&DPI=" + QString::number( mDpi ); + setQueryItem( url, "DPI", QString::number( mDpi ) ); } //MH: jpeg does not support transparency and some servers complain if jpg and transparent=true if ( !imageMimeType.contains( "jpeg", Qt::CaseInsensitive ) && !imageMimeType.contains( "jpg", Qt::CaseInsensitive ) ) { - // some servers giving error for 'true' (lowercase) - //url += "&TRANSPARENT=true"; - url += "&TRANSPARENT=TRUE"; + setQueryItem( url, "TRANSPARENT", "TRUE" ); // some servers giving error for 'true' (lowercase) } - mGetFeatureInfoUrlBase = mIgnoreGetFeatureInfoUrl ? mBaseUrl : getFeatureInfoUrl(); + QgsDebugMsg( QString( "getmap: %1" ).arg( url.toString() ) ); // cache some details for if the user wants to do an identifyAsHtml() later - mGetFeatureInfoUrlBase += "SERVICE=WMS"; - mGetFeatureInfoUrlBase += "&VERSION=" + mCapabilities.version; - mGetFeatureInfoUrlBase += "&REQUEST=GetFeatureInfo"; - mGetFeatureInfoUrlBase += "&BBOX=" + bbox; - mGetFeatureInfoUrlBase += "&" + crsKey + "=" + imageCrs; - mGetFeatureInfoUrlBase += "&WIDTH=" + width; - mGetFeatureInfoUrlBase += "&HEIGHT=" + height; - mGetFeatureInfoUrlBase += "&LAYERS=" + layers; - mGetFeatureInfoUrlBase += "&STYLES=" + styles; - mGetFeatureInfoUrlBase += "&FORMAT=" + imageMimeType; + QUrl fiUrl( mIgnoreGetFeatureInfoUrl ? mBaseUrl : getFeatureInfoUrl() ); + setQueryItem( fiUrl, "SERVICE", "WMS" ); + setQueryItem( fiUrl, "VERSION", mCapabilities.version ); + setQueryItem( fiUrl, "REQUEST", "GetFeatureInfo" ); + setQueryItem( fiUrl, "BBOX", bbox ); + setQueryItem( fiUrl, crsKey, imageCrs ); + setQueryItem( fiUrl, "WIDTH", QString::number( pixelWidth ) ); + setQueryItem( fiUrl, "HEIGHT", QString::number( pixelHeight ) ); + setQueryItem( fiUrl, "LAYERS", layers ); + setQueryItem( fiUrl, "STYLES", styles ); + setQueryItem( fiUrl, "FORMAT", imageMimeType ); if ( !imageMimeType.contains( "jpeg", Qt::CaseInsensitive ) && !imageMimeType.contains( "jpg", Qt::CaseInsensitive ) ) { - mGetFeatureInfoUrlBase += "&TRANSPARENT=true"; + setQueryItem( fiUrl, "TRANSPARENT", "true" ); } - QgsDebugMsg( QString( "getmap: %1" ).arg( url ) ); + mGetFeatureInfoUrlBase = fiUrl.toString(); + QNetworkRequest request( url ); setAuthorization( request ); request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true ); @@ -622,7 +619,19 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i #endif // add WMS request - url += QString( "SERVICE=WMS&VERSION=%1&REQUEST=GetMap" ).arg( mCapabilities.version ); + QUrl url( mIgnoreGetMapUrl ? mBaseUrl : getMapUrl() ); + setQueryItem( url, "SERVICE", "WMS" ); + setQueryItem( url, "VERSION", mCapabilities.version ); + setQueryItem( url, "REQUEST", "GetMap" ); + + url.removeQueryItem( crsKey ); + url.removeQueryItem( "WIDTH" ); + url.removeQueryItem( "HEIGHT" ); + url.removeQueryItem( "LAYERS" ); + url.removeQueryItem( "STYLES" ); + url.removeQueryItem( "FORMAT" ); + url.removeQueryItem( "TILED" ); + // compose static request arguments. QString urlargs; @@ -644,7 +653,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i while ( x < xmax ) { QString turl; - turl += url; + turl += url.toString(); turl += QString( changeXY ? "&BBOX=%2,%1,%4,%3" : "&BBOX=%1,%2,%3,%4" ) .arg( x, 0, 'f' ) .arg( y, 0, 'f' ) @@ -1191,44 +1200,47 @@ void QgsWmsProvider::parseService( QDomElement const & e, QgsWmsServiceProperty& if ( !e1.isNull() ) { // QgsDebugMsg( " " + e1.tagName() ); // the node really is an element. + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); - if ( e1.tagName() == "Title" ) + if ( tagName == "Title" ) { serviceProperty.title = e1.text(); } - else if ( e1.tagName() == "Abstract" ) + else if ( tagName == "Abstract" ) { serviceProperty.abstract = e1.text(); } - else if ( e1.tagName() == "KeywordList" ) + else if ( tagName == "KeywordList" ) { parseKeywordList( e1, serviceProperty.keywordList ); } - else if ( e1.tagName() == "OnlineResource" ) + else if ( tagName == "OnlineResource" ) { parseOnlineResource( e1, serviceProperty.onlineResource ); } - else if ( e1.tagName() == "ContactInformation" ) + else if ( tagName == "ContactInformation" ) { parseContactInformation( e1, serviceProperty.contactInformation ); } - else if ( e1.tagName() == "Fees" ) + else if ( tagName == "Fees" ) { serviceProperty.fees = e1.text(); } - else if ( e1.tagName() == "AccessConstraints" ) + else if ( tagName == "AccessConstraints" ) { serviceProperty.accessConstraints = e1.text(); } - else if ( e1.tagName() == "LayerLimit" ) + else if ( tagName == "LayerLimit" ) { serviceProperty.layerLimit = e1.text().toUInt(); } - else if ( e1.tagName() == "MaxWidth" ) + else if ( tagName == "MaxWidth" ) { serviceProperty.maxWidth = e1.text().toUInt(); } - else if ( e1.tagName() == "MaxHeight" ) + else if ( tagName == "MaxHeight" ) { serviceProperty.maxHeight = e1.text().toUInt(); } @@ -1250,23 +1262,32 @@ void QgsWmsProvider::parseCapability( QDomElement const & e, QgsWmsCapabilityPro QDomElement e1 = n1.toElement(); // try to convert the node to an element. if ( !e1.isNull() ) { + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + QgsDebugMsg( " " + e1.tagName() ); // the node really is an element. - if ( e1.tagName() == "Request" ) + if ( tagName == "Request" ) { parseRequest( e1, capabilityProperty.request ); } - else if ( e1.tagName() == "Layer" ) + else if ( tagName == "Layer" ) { parseLayer( e1, capabilityProperty.layer ); } - else if ( e1.tagName() == "VendorSpecificCapabilities" ) + else if ( tagName == "VendorSpecificCapabilities" ) { for ( int i = 0; i < e1.childNodes().size(); i++ ) { QDomNode n2 = e1.childNodes().item( i ); QDomElement e2 = n2.toElement(); - if ( e2.tagName() == "TileSet" ) + + QString tagName = e2.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + + if ( tagName == "TileSet" ) { parseTileSetProfile( e2, capabilityProperty.tileSetProfiles ); } @@ -1290,11 +1311,15 @@ void QgsWmsProvider::parseContactPersonPrimary( QDomElement const & e, QgsWmsCon QDomElement e1 = n1.toElement(); // try to convert the node to an element. if ( !e1.isNull() ) { - if ( e1.tagName() == "ContactPerson" ) + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + + if ( tagName == "ContactPerson" ) { contactPersonPrimaryProperty.contactPerson = e1.text(); } - else if ( e1.tagName() == "ContactOrganization" ) + else if ( tagName == "ContactOrganization" ) { contactPersonPrimaryProperty.contactOrganization = e1.text(); } @@ -1316,27 +1341,31 @@ void QgsWmsProvider::parseContactAddress( QDomElement const & e, QgsWmsContactAd QDomElement e1 = n1.toElement(); // try to convert the node to an element. if ( !e1.isNull() ) { - if ( e1.tagName() == "AddressType" ) + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + + if ( tagName == "AddressType" ) { contactAddressProperty.addressType = e1.text(); } - else if ( e1.tagName() == "Address" ) + else if ( tagName == "Address" ) { contactAddressProperty.address = e1.text(); } - else if ( e1.tagName() == "City" ) + else if ( tagName == "City" ) { contactAddressProperty.city = e1.text(); } - else if ( e1.tagName() == "StateOrProvince" ) + else if ( tagName == "StateOrProvince" ) { contactAddressProperty.stateOrProvince = e1.text(); } - else if ( e1.tagName() == "PostCode" ) + else if ( tagName == "PostCode" ) { contactAddressProperty.postCode = e1.text(); } - else if ( e1.tagName() == "Country" ) + else if ( tagName == "Country" ) { contactAddressProperty.country = e1.text(); } @@ -1358,27 +1387,31 @@ void QgsWmsProvider::parseContactInformation( QDomElement const & e, QgsWmsConta QDomElement e1 = n1.toElement(); // try to convert the node to an element. if ( !e1.isNull() ) { - if ( e1.tagName() == "ContactPersonPrimary" ) + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + + if ( tagName == "ContactPersonPrimary" ) { parseContactPersonPrimary( e1, contactInformationProperty.contactPersonPrimary ); } - else if ( e1.tagName() == "ContactPosition" ) + else if ( tagName == "ContactPosition" ) { contactInformationProperty.contactPosition = e1.text(); } - else if ( e1.tagName() == "ContactAddress" ) + else if ( tagName == "ContactAddress" ) { parseContactAddress( e1, contactInformationProperty.contactAddress ); } - else if ( e1.tagName() == "ContactVoiceTelephone" ) + else if ( tagName == "ContactVoiceTelephone" ) { contactInformationProperty.contactVoiceTelephone = e1.text(); } - else if ( e1.tagName() == "ContactFacsimileTelephone" ) + else if ( tagName == "ContactFacsimileTelephone" ) { contactInformationProperty.contactFacsimileTelephone = e1.text(); } - else if ( e1.tagName() == "ContactElectronicMailAddress" ) + else if ( tagName == "ContactElectronicMailAddress" ) { contactInformationProperty.contactElectronicMailAddress = e1.text(); } @@ -1410,7 +1443,11 @@ void QgsWmsProvider::parseKeywordList( QDomElement const & e, QStringList& keyw QDomElement e1 = n1.toElement(); // try to convert the node to an element. if ( !e1.isNull() ) { - if ( e1.tagName() == "Keyword" ) + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + + if ( tagName == "Keyword" ) { QgsDebugMsg( " Keyword." ); keywordListProperty += e1.text(); @@ -1433,7 +1470,11 @@ void QgsWmsProvider::parseGet( QDomElement const & e, QgsWmsGetProperty& getProp QDomElement e1 = n1.toElement(); // try to convert the node to an element. if ( !e1.isNull() ) { - if ( e1.tagName() == "OnlineResource" ) + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + + if ( tagName == "OnlineResource" ) { QgsDebugMsg( " OnlineResource." ); parseOnlineResource( e1, getProperty.onlineResource ); @@ -1456,7 +1497,11 @@ void QgsWmsProvider::parsePost( QDomElement const & e, QgsWmsPostProperty& postP QDomElement e1 = n1.toElement(); // try to convert the node to an element. if ( !e1.isNull() ) { - if ( e1.tagName() == "OnlineResource" ) + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + + if ( tagName == "OnlineResource" ) { QgsDebugMsg( " OnlineResource." ); parseOnlineResource( e1, postProperty.onlineResource ); @@ -1530,12 +1575,16 @@ void QgsWmsProvider::parseOperationType( QDomElement const & e, QgsWmsOperationT QDomElement e1 = n1.toElement(); // try to convert the node to an element. if ( !e1.isNull() ) { - if ( e1.tagName() == "Format" ) + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + + if ( tagName == "Format" ) { QgsDebugMsg( " Format." ); operationType.format += e1.text(); } - else if ( e1.tagName() == "DCPType" ) + else if ( tagName == "DCPType" ) { QgsDebugMsg( " DCPType." ); QgsWmsDcpTypeProperty dcp; @@ -1591,11 +1640,15 @@ void QgsWmsProvider::parseLegendUrl( QDomElement const & e, QgsWmsLegendUrlPrope QDomElement e1 = n1.toElement(); // try to convert the node to an element. if ( !e1.isNull() ) { - if ( e1.tagName() == "Format" ) + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + + if ( tagName == "Format" ) { legendUrlProperty.format = e1.text(); } - else if ( e1.tagName() == "OnlineResource" ) + else if ( tagName == "OnlineResource" ) { parseOnlineResource( e1, legendUrlProperty.onlineResource ); } @@ -1617,27 +1670,31 @@ void QgsWmsProvider::parseStyle( QDomElement const & e, QgsWmsStyleProperty& sty QDomElement e1 = n1.toElement(); // try to convert the node to an element. if ( !e1.isNull() ) { - if ( e1.tagName() == "Name" ) + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + + if ( tagName == "Name" ) { styleProperty.name = e1.text(); } - else if ( e1.tagName() == "Title" ) + else if ( tagName == "Title" ) { styleProperty.title = e1.text(); } - else if ( e1.tagName() == "Abstract" ) + else if ( tagName == "Abstract" ) { styleProperty.abstract = e1.text(); } - else if ( e1.tagName() == "LegendURL" ) + else if ( tagName == "LegendURL" ) { // TODO } - else if ( e1.tagName() == "StyleSheetURL" ) + else if ( tagName == "StyleSheetURL" ) { // TODO } - else if ( e1.tagName() == "StyleURL" ) + else if ( tagName == "StyleURL" ) { // TODO } @@ -1676,7 +1733,11 @@ void QgsWmsProvider::parseLayer( QDomElement const & e, QgsWmsLayerProperty& lay { //QgsDebugMsg( " " + e1.tagName() ); // the node really is an element. - if ( e1.tagName() == "Layer" ) + QString tagName = e1.tagName(); + if ( tagName.startsWith( "wms:" ) ) + tagName = tagName.mid( 4 ); + + if ( tagName == "Layer" ) { QgsDebugMsg( " Nested layer." ); @@ -1694,23 +1755,23 @@ void QgsWmsProvider::parseLayer( QDomElement const & e, QgsWmsLayerProperty& lay layerProperty.layer.push_back( subLayerProperty ); } - else if ( e1.tagName() == "Name" ) + else if ( tagName == "Name" ) { layerProperty.name = e1.text(); } - else if ( e1.tagName() == "Title" ) + else if ( tagName == "Title" ) { layerProperty.title = e1.text(); } - else if ( e1.tagName() == "Abstract" ) + else if ( tagName == "Abstract" ) { layerProperty.abstract = e1.text(); } - else if ( e1.tagName() == "KeywordList" ) + else if ( tagName == "KeywordList" ) { parseKeywordList( e1, layerProperty.keywordList ); } - else if ( e1.tagName() == "SRS" || e1.tagName() == "CRS" ) + else if ( tagName == "SRS" || tagName == "CRS" ) { // CRS can contain several definitions separated by whitespace // though this was deprecated in WMS 1.1.1 @@ -1719,7 +1780,7 @@ void QgsWmsProvider::parseLayer( QDomElement const & e, QgsWmsLayerProperty& lay layerProperty.crs.push_back( srs ); } } - else if ( e1.tagName() == "LatLonBoundingBox" ) // legacy from earlier versions of WMS + else if ( tagName == "LatLonBoundingBox" ) // legacy from earlier versions of WMS { layerProperty.ex_GeographicBoundingBox = QgsRectangle( e1.attribute( "minx" ).toDouble(), @@ -1747,12 +1808,25 @@ void QgsWmsProvider::parseLayer( QDomElement const & e, QgsWmsLayerProperty& lay } } } - else if ( e1.tagName() == "EX_GeographicBoundingBox" ) //for WMS 1.3 + else if ( tagName == "EX_GeographicBoundingBox" ) //for WMS 1.3 { - QDomElement wBoundLongitudeElem = n1.namedItem( "westBoundLongitude" ).toElement(); - QDomElement eBoundLongitudeElem = n1.namedItem( "eastBoundLongitude" ).toElement(); - QDomElement sBoundLatitudeElem = n1.namedItem( "southBoundLatitude" ).toElement(); - QDomElement nBoundLatitudeElem = n1.namedItem( "northBoundLatitude" ).toElement(); + QDomElement wBoundLongitudeElem, eBoundLongitudeElem, sBoundLatitudeElem, nBoundLatitudeElem; + + if ( e1.tagName() == "wms:EX_GeographicBoundingBox" ) + { + wBoundLongitudeElem = n1.namedItem( "wms:westBoundLongitude" ).toElement(); + eBoundLongitudeElem = n1.namedItem( "wms:eastBoundLongitude" ).toElement(); + sBoundLatitudeElem = n1.namedItem( "wms:southBoundLatitude" ).toElement(); + nBoundLatitudeElem = n1.namedItem( "wms:northBoundLatitude" ).toElement(); + } + else + { + wBoundLongitudeElem = n1.namedItem( "westBoundLongitude" ).toElement(); + eBoundLongitudeElem = n1.namedItem( "eastBoundLongitude" ).toElement(); + sBoundLatitudeElem = n1.namedItem( "southBoundLatitude" ).toElement(); + nBoundLatitudeElem = n1.namedItem( "northBoundLatitude" ).toElement(); + } + double wBLong, eBLong, sBLat, nBLat; bool wBOk, eBOk, sBOk, nBOk; wBLong = wBoundLongitudeElem.text().toDouble( &wBOk ); @@ -1764,7 +1838,7 @@ void QgsWmsProvider::parseLayer( QDomElement const & e, QgsWmsLayerProperty& lay layerProperty.ex_GeographicBoundingBox = QgsRectangle( wBLong, sBLat, eBLong, nBLat ); } } - else if ( e1.tagName() == "BoundingBox" ) + else if ( tagName == "BoundingBox" ) { // TODO: overwrite inherited QgsWmsBoundingBoxProperty bbox; @@ -1787,35 +1861,35 @@ void QgsWmsProvider::parseLayer( QDomElement const & e, QgsWmsLayerProperty& lay QgsDebugMsg( "CRS/SRS attribute note found in BoundingBox" ); } } - else if ( e1.tagName() == "Dimension" ) + else if ( tagName == "Dimension" ) { // TODO } - else if ( e1.tagName() == "Attribution" ) + else if ( tagName == "Attribution" ) { // TODO } - else if ( e1.tagName() == "AuthorityURL" ) + else if ( tagName == "AuthorityURL" ) { // TODO } - else if ( e1.tagName() == "Identifier" ) + else if ( tagName == "Identifier" ) { // TODO } - else if ( e1.tagName() == "MetadataURL" ) + else if ( tagName == "MetadataURL" ) { // TODO } - else if ( e1.tagName() == "DataURL" ) + else if ( tagName == "DataURL" ) { // TODO } - else if ( e1.tagName() == "FeatureListURL" ) + else if ( tagName == "FeatureListURL" ) { // TODO } - else if ( e1.tagName() == "Style" ) + else if ( tagName == "Style" ) { QgsWmsStyleProperty styleProperty; @@ -1823,11 +1897,11 @@ void QgsWmsProvider::parseLayer( QDomElement const & e, QgsWmsLayerProperty& lay layerProperty.style.push_back( styleProperty ); } - else if ( e1.tagName() == "MinScaleDenominator" ) + else if ( tagName == "MinScaleDenominator" ) { // TODO } - else if ( e1.tagName() == "MaxScaleDenominator" ) + else if ( tagName == "MaxScaleDenominator" ) { // TODO } @@ -1914,31 +1988,35 @@ void QgsWmsProvider::parseTileSetProfile( QDomElement const &e, QVector