3 #include <QNetworkAccessManager> 4 #include <QNetworkRequest> 5 #include <QNetworkReply> 13 return "http://overpass-api.de/api/interpreter";
19 return QString(
"(node(%1,%2,%3,%4);<;);out;" ).arg( rect.
yMinimum() ).arg( rect.
xMinimum() )
34 mReply->deleteLater();
44 if ( mQuery.isEmpty() )
46 mError =
tr(
"No query has been specified." );
52 mError =
tr(
"There is already a pending request for data." );
56 if ( !mFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
58 mError =
tr(
"Cannot open output file: %1" ).arg( mFile.fileName() );
64 QUrl url( mServiceUrl );
65 url.addQueryItem(
"data", mQuery );
67 QNetworkRequest request( url );
68 request.setRawHeader(
"User-Agent",
"QGIS" );
70 mReply = nwam->get( request );
72 connect( mReply, SIGNAL( readyRead() ),
this, SLOT( onReadyRead() ) );
73 connect( mReply, SIGNAL( error( QNetworkReply::NetworkError ) ),
this, SLOT( onError( QNetworkReply::NetworkError ) ) );
74 connect( mReply, SIGNAL(
finished() ),
this, SLOT( onFinished() ) );
91 void QgsOSMDownload::onReadyRead()
95 QByteArray data = mReply->read( 1024 * 1024 );
100 void QgsOSMDownload::onFinished()
102 qDebug(
"finished" );
105 mReply->deleteLater();
114 void QgsOSMDownload::onError( QNetworkReply::NetworkError err )
116 qDebug(
"error: %d", err );
119 mError = mReply->errorString();
128 return mReply->isFinished();
A rectangle specified with double values.
void downloadProgress(qint64, qint64)
normally the total length is not known (until we reach end)
double yMaximum() const
Get the y maximum value (top side of rectangle)
static QgsNetworkAccessManager * instance()
bool abort()
Aborts current pending request.
bool isFinished() const
Returns true if the request has already finished.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
void finished()
emitted when the network reply has finished (with success or with an error)
bool start()
Starts network request for data.
static QString queryFromRect(const QgsRectangle &rect)
Create query (in Overpass Query Language) that fetches everything in given rectangle.
static QString defaultServiceUrl()
Return URL of the service that is used by default.
double xMinimum() const
Get the x minimum value (left side of rectangle)