?? qgswmsprovider.cpp
字號(hào):
}/* QgsHttpTransaction http(url, httpproxyhost, httpproxyport); // Do a passthrough for the status bar text connect( &http, SIGNAL(setStatus (QString)), this, SLOT(showStatusMessage(QString)) ); bool httpOk; httpOk = http.getSynchronously(imagesource); if (!httpOk) { // We had an HTTP exception mErrorCaption = tr("HTTP Exception"); mError = http.errorString(); mError += "\n" + tr("Tried URL: ") + url; return 0; } if (http.responseContentType() == "application/vnd.ogc.se_xml") { // We had a Service Exception from the WMS QgsDebugMsg("got Service Exception as:\n" + QString(imagesource) ); mErrorCaption = tr("WMS Service Exception"); // set mError with the following: parseServiceExceptionReportDOM(imagesource); mError += "\n" + tr("Tried URL: ") + url; QgsDebugMsg("composed error message '" + mError + "'.");#endif return 0; }*/ QgsDebugMsg("Response received.");#ifdef QGISDEBUG //QFile file( "/tmp/qgis-wmsprovider-draw-raw.png" ); //if ( file.open( QIODevice::WriteOnly ) ) //{ // file.writeBlock(imagesource); // file.close(); //}#endif // Load into the final QImage. //bool success = i.loadFromData(imagesource); if (cachedImage) { delete cachedImage; } cachedImage = new QImage(imagesource); // Remember settings for useful caching next time. cachedViewExtent = viewExtent; cachedPixelWidth = pixelWidth; cachedPixelHeight = pixelHeight;#ifdef QGISDEBUG // Get what we can support// Commented out for now, causes segfaults.// supportedFormats();#endif QgsDebugMsg("Exiting."); // TODO: bit depth conversion to the client's expectation// return *(i.convertDepth(32)); return cachedImage;}/*void QgsWmsProvider::getServerCapabilities(){ QgsDebugMsg("entering."); retrieveServerCapabilities(); // TODO: Return generic server capabilities here QgsDebugMsg("exiting.");}*/bool QgsWmsProvider::retrieveServerCapabilities(bool forceRefresh){ QgsDebugMsg("entering."); if ( httpcapabilitiesresponse.isNull() || forceRefresh ) { QString url = baseUrl + "SERVICE=WMS&REQUEST=GetCapabilities"; httpcapabilitiesresponse = retrieveUrl(url); if (httpcapabilitiesresponse.isEmpty()) { return FALSE; }/* QgsHttpTransaction http(url, httpproxyhost, httpproxyport); // Do a passthrough for the status bar text connect( &http, SIGNAL(setStatus (QString)), this, SLOT(showStatusMessage(QString)) ); bool httpOk; httpOk = http.getSynchronously(httpcapabilitiesresponse); if (!httpOk) { // We had an HTTP exception mErrorCaption = tr("HTTP Exception"); mError = http.errorString(); mError += "\n" + tr("Tried URL: ") + url; QgsDebugMsg("!httpOK: " + mError ); return FALSE; }*/ QgsDebugMsg("Converting to DOM."); bool domOK; domOK = parseCapabilitiesDOM(httpcapabilitiesresponse, mCapabilities); if (!domOK) { // We had an DOM exception - // mErrorCaption and mError are pre-filled by parseCapabilitiesDOM mError += "\n" + tr("Tried URL: ") + url; QgsDebugMsg("!domOK: " + mError); return FALSE; } } QgsDebugMsg("exiting."); return TRUE;}QByteArray QgsWmsProvider::retrieveUrl(QString url){ QgsDebugMsg("WMS request Url: " + url); QgsHttpTransaction http( url, mHttpProxyHost, mHttpProxyPort, mHttpProxyUser, mHttpProxyPass); // Do a passthrough for the status bar text connect( &http, SIGNAL(setStatus (QString)), this, SLOT(showStatusMessage(QString)) ); QByteArray httpResponse; bool httpOk; httpOk = http.getSynchronously(httpResponse); if (!httpOk) { // We had an HTTP exception mErrorCaption = tr("HTTP Exception"); mError = http.errorString(); mError += "\n" + tr("Tried URL: ") + url; return QByteArray(""); } if (http.responseContentType() == "application/vnd.ogc.se_xml") { // We had a Service Exception from the WMS QgsDebugMsg("got Service Exception as:\n" + httpResponse ); mErrorCaption = tr("WMS Service Exception"); // set mError with the following: parseServiceExceptionReportDOM(httpResponse); mError += "\n" + tr("Tried URL: ") + url; QgsDebugMsg("composed error message '" + mError + "'."); return QByteArray(""); } return httpResponse;}#if 0// deprecatedbool QgsWmsProvider::downloadCapabilitiesURI(QString const & uri){ QgsDebugMsg("Entered with '" + uri + "'"); QgsHttpTransaction http(uri, httpproxyhost, httpproxyport); // Do a passthrough for the status bar text connect( &http, SIGNAL(setStatus (QString)), this, SLOT(showStatusMessage(QString)) ); bool httpOk; httpOk = http.getSynchronously(httpcapabilitiesresponse); if (!httpOk) { // We had an HTTP exception mErrorCaption = tr("HTTP Exception"); mError = http.errorString(); mError += "\n" + tr("Tried URL: ") + uri; QgsDebugMsg("!httpOK: " + mError ); return FALSE; } QgsDebugMsg("Converting to DOM."); bool domOK; domOK = parseCapabilitiesDOM(httpcapabilitiesresponse, capabilities); if (!domOK) { // We had an DOM exception - // mErrorCaption and mError are pre-filled by parseCapabilitiesDOM mError += "\n" + tr("Tried URL: ") + uri; QgsDebugMsg("!domOK: " + mError ); return FALSE; } QgsDebugMsg("exiting."); return TRUE;}#endifbool QgsWmsProvider::parseCapabilitiesDOM(QByteArray const & xml, QgsWmsCapabilitiesProperty& capabilitiesProperty){ QgsDebugMsg("entering.");#ifdef QGISDEBUG //test the content of the QByteArray. // There is a bug in Qt4.1.2, due for fixing in 4.2.0, where // QString(QByteArray) uses strlen to find the length of the // QByteArray. However, there are no guarantees that the QByteArray // has a terminating \0, and hence this can cause a crash, so we supply // the qbytearray to qstring in a way that ensures that there is a // terminating \0, and just to be safe, we also give it the actual // size. // Also, the Qt qWarning() function has a limit of 8192 bytes per // message, which can easily be exceeded by wms capability // documents, so we use the qgs logger stuff instead which doesn't // have that limitation. QString responsestring(QString::fromAscii(xml.constData(), xml.size())); QgsLogger::debug("QgsWmsProvider::parseCapabilitiesDOM, received the following data: "+responsestring); //QFile file( "/tmp/qgis-wmsprovider-capabilities.xml" ); //if ( file.open( QIODevice::WriteOnly ) ) //{ // file.writeBlock(xml); // file.close(); //}#endif // Convert completed document into a DOM QString errorMsg; int errorLine; int errorColumn; bool contentSuccess = capabilitiesDOM.setContent(xml, false, &errorMsg, &errorLine, &errorColumn); if (!contentSuccess) { mErrorCaption = tr("DOM Exception"); mError = QString(tr("Could not get WMS capabilities: %1 at line %2 column %3") .arg(errorMsg) .arg(errorLine) .arg(errorColumn) ); mError += "\n" + tr("This is probably due to an incorrect WMS Server URL."); QgsLogger::debug("DOM Exception: "+mError); return FALSE; } QDomElement docElem = capabilitiesDOM.documentElement(); // Assert that the DTD is what we expected (i.e. a WMS Capabilities document) QgsDebugMsg("testing tagName " + docElem.tagName() ); if (! ( (docElem.tagName() == "WMS_Capabilities") // (1.3 vintage) || (docElem.tagName() == "WMT_MS_Capabilities") // (1.1.1 vintage) ) ) { mErrorCaption = tr("DOM Exception"); mError = QString(tr("Could not get WMS capabilities in the " "expected format (DTD): no %1 or %2 found") .arg("WMS_Capabilities") .arg("WMT_MS_Capabilities") ); mError += "\n" + tr("This is probably due to an incorrect WMS Server URL."); QgsLogger::debug("DOM Exception: "+mError); return FALSE; } capabilitiesProperty.version = docElem.attribute("version"); // Start walking through XML. QDomNode n = docElem.firstChild(); while( !n.isNull() ) { QDomElement e = n.toElement(); // try to convert the node to an element. if( !e.isNull() ) { //QgsDebugMsg(e.tagName() ); // the node really is an element. if (e.tagName() == "Service") { QgsDebugMsg(" Service."); parseService(e, capabilitiesProperty.service); } else if (e.tagName() == "Capability") { QgsDebugMsg(" Capability."); parseCapability(e, capabilitiesProperty.capability); } } n = n.nextSibling(); } QgsDebugMsg("exiting."); return TRUE;}void QgsWmsProvider::parseService(QDomElement const & e, QgsWmsServiceProperty& serviceProperty){ QgsDebugMsg("entering."); QDomNode n1 = e.firstChild(); while( !n1.isNull() ) { QDomElement e1 = n1.toElement(); // try to convert the node to an element. if( !e1.isNull() ) { //QgsDebugMsg(" " + e1.tagName() ); // the node really is an element. if (e1.tagName() == "Title") { serviceProperty.title = e1.text(); } else if (e1.tagName() == "Abstract") { serviceProperty.abstract = e1.text(); } else if (e1.tagName() == "KeywordList") { parseKeywordList(e1, serviceProperty.keywordList); } else if (e1.tagName() == "OnlineResource") { parseOnlineResource(e1, serviceProperty.onlineResource); } else if (e1.tagName() == "ContactInformation") { parseContactInformation(e1, serviceProperty.contactInformation); } else if (e1.tagName() == "Fees") { serviceProperty.fees = e1.text(); } else if (e1.tagName() == "AccessConstraints") { serviceProperty.accessConstraints = e1.text(); } else if (e1.tagName() == "LayerLimit") { serviceProperty.layerLimit = e1.text().toUInt(); } else if (e1.tagName() == "MaxWidth") { serviceProperty.maxWidth = e1.text().toUInt(); } else if (e1.tagName() == "MaxHeight") { serviceProperty.maxHeight = e1.text().toUInt(); } } n1 = n1.nextSibling(); }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -