-
Notifications
You must be signed in to change notification settings - Fork 1
/
qgssoscapabilities.cpp
108 lines (92 loc) · 3.49 KB
/
qgssoscapabilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/***************************************************************************
qgssoscapabilities.cpp - description
--------------------------------------
begin : June 2013
copyright : (C) 2013 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgssoscapabilities.h"
#include "qgsnetworkaccessmanager.h"
#include <QDomDocument>
#include <QNetworkReply>
QgsSOSCapabilities::QgsSOSCapabilities( const QString& serviceUrl ): QObject( 0 ), mCapabilitiesReply( 0 )
{
mUrl.setEncodedUri( serviceUrl );
mBaseUrl = prepareUri( mUrl.param( "url" ) );
}
QgsSOSCapabilities::~QgsSOSCapabilities()
{
delete mCapabilitiesReply;
}
void QgsSOSCapabilities::requestCapabilities()
{
QString url = uriGetCapabilities();
qWarning( url.toLocal8Bit().data() );
QNetworkRequest request( url );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
QObject::connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
}
void QgsSOSCapabilities::capabilitiesReplyFinished()
{
QNetworkReply* reply = mCapabilitiesReply;
QSet<QString> observedPropertiesSet;
mObservableProperties.clear();
mNetworkError.clear();
mXmlError.clear();
reply->deleteLater();
mCapabilitiesReply = 0;
// handle network errors
if ( reply->error() != QNetworkReply::NoError )
{
mNetworkError = reply->errorString();
emit gotCapabilities();
return;
}
QByteArray buffer = reply->readAll();
QDomDocument doc;
QString xmlErrorMsg;
int errorLine = 0;
int errorColumn = 0;
if ( !doc.setContent( buffer, true, &xmlErrorMsg, &errorLine, &errorColumn ) )
{
mXmlError = QString( "XML error: %1 on line %2, column %3" ).arg( xmlErrorMsg ).arg( errorLine ).arg( errorColumn );
return;
}
//get list of observable properties
QDomNodeList observablePropertyList = doc.elementsByTagNameNS( "http://www.opengis.net/swes/2.0" , "observableProperty" );
for ( int i = 0; i < observablePropertyList.size(); ++i )
{
observedPropertiesSet.insert( observablePropertyList.at( i ).toElement().text() );
}
QSet<QString>::const_iterator propIt = observedPropertiesSet.constBegin();
for ( ; propIt != observedPropertiesSet.constEnd(); ++propIt )
{
mObservableProperties.push_back( *propIt );
}
emit gotCapabilities();
}
QString QgsSOSCapabilities::uriGetCapabilities()
{
return ( mBaseUrl + "SERVICE=SOS&REQUEST=GetCapabilities&VERSION=2.0.0" );
}
QString QgsSOSCapabilities::prepareUri( QString uri )
{
if ( !uri.contains( "?" ) )
{
uri.append( "?" );
}
else if ( uri.right( 1 ) != "?" && uri.right( 1 ) != "&" )
{
uri.append( "&" );
}
return uri;
}