QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
qgsarcgisrestquery.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsarcgisrestquery.h
3  --------------------
4  begin : December 2020
5  copyright : (C) 2020 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSARCGISRESTQUERY_H
16 #define QGSARCGISRESTQUERY_H
17 
18 #define SIP_NO_FILE
19 
20 #include "qgis_core.h"
21 #include "qgsrectangle.h"
22 #include "qgswkbtypes.h"
23 
24 #include <QString>
25 #include <QVariantMap>
26 
27 class QgsFeedback;
28 class QNetworkReply;
29 
36 class CORE_EXPORT QgsArcGisRestQueryUtils
37 {
38  public:
39 
44  {
47  Raster
48  };
49 
53  static QVariantMap getServiceInfo( const QString &baseurl, const QString &authcfg, QString &errorTitle, QString &errorText, const QMap< QString, QString > &requestHeaders = QMap< QString, QString >() );
54 
58  static QVariantMap getLayerInfo( const QString &layerurl, const QString &authcfg, QString &errorTitle, QString &errorText, const QMap< QString, QString > &requestHeaders = QMap< QString, QString >() );
59 
63  static QVariantMap getObjectIds( const QString &layerurl, const QString &authcfg, QString &errorTitle, QString &errorText, const QMap< QString, QString > &requestHeaders = QMap< QString, QString >(),
64  const QgsRectangle &bbox = QgsRectangle() );
65 
69  static QVariantMap getObjects( const QString &layerurl, const QString &authcfg, const QList<quint32> &objectIds, const QString &crs,
70  bool fetchGeometry, const QStringList &fetchAttributes, bool fetchM, bool fetchZ,
71  const QgsRectangle &filterRect, QString &errorTitle, QString &errorText, const QgsStringMap &requestHeaders = QgsStringMap(), QgsFeedback *feedback = nullptr );
72 
76  static QList<quint32> getObjectIdsByExtent( const QString &layerurl, const QgsRectangle &filterRect, QString &errorTitle, QString &errorText, const QString &authcfg, const QgsStringMap &requestHeaders = QgsStringMap(), QgsFeedback *feedback = nullptr );
77 
81  static QByteArray queryService( const QUrl &url, const QString &authcfg, QString &errorTitle, QString &errorText, const QgsStringMap &requestHeaders = QgsStringMap(), QgsFeedback *feedback = nullptr, QString *contentType = nullptr );
82 
86  static QVariantMap queryServiceJSON( const QUrl &url, const QString &authcfg, QString &errorTitle, QString &errorText, const QgsStringMap &requestHeaders = QgsStringMap(), QgsFeedback *feedback = nullptr );
87 
91  static void visitFolderItems( const std::function<void ( const QString &folderName, const QString &url )> &visitor, const QVariantMap &serviceData, const QString &baseUrl );
92 
96  static void visitServiceItems( const std::function<void ( const QString &serviceName, const QString &url, const QString &service, ServiceTypeFilter serviceType )> &visitor, const QVariantMap &serviceData, const QString &baseUrl );
97 
101  static void addLayerItems( const std::function<void ( const QString &parentLayerId, ServiceTypeFilter serviceType, QgsWkbTypes::GeometryType geometryType, const QString &layerId, const QString &name, const QString &description, const QString &url, bool isParentLayer, const QString &authid, const QString &format )> &visitor, const QVariantMap &serviceData, const QString &parentUrl, const QString &parentSupportedFormats, const ServiceTypeFilter filter = AllTypes );
102 
103  private:
104 
105  static QUrl parseUrl( const QUrl &url );
106  static void adjustBaseUrl( QString &baseUrl, const QString &name );
107 
108  friend class TestQgsArcGisRestUtils;
109 };
110 
112 class CORE_EXPORT QgsArcGisAsyncQuery : public QObject
113 {
114  Q_OBJECT
115  public:
116  QgsArcGisAsyncQuery( QObject *parent = nullptr );
117  ~QgsArcGisAsyncQuery() override;
118 
119  void start( const QUrl &url, const QString &authCfg, QByteArray *result, bool allowCache = false, const QgsStringMap &headers = QgsStringMap() );
120  signals:
121  void finished();
122  void failed( QString errorTitle, QString errorName );
123  private slots:
124  void handleReply();
125 
126  private:
127  QNetworkReply *mReply = nullptr;
128  QByteArray *mResult = nullptr;
129 };
130 
131 class CORE_EXPORT QgsArcGisAsyncParallelQuery : public QObject
132 {
133  Q_OBJECT
134  public:
135  QgsArcGisAsyncParallelQuery( const QString &authcfg, const QgsStringMap &requestHeaders, QObject *parent = nullptr );
136  void start( const QVector<QUrl> &urls, QVector<QByteArray> *results, bool allowCache = false );
137 
138  signals:
139  void finished( QStringList errors );
140  private slots:
141  void handleReply();
142 
143  private:
144  QVector<QByteArray> *mResults = nullptr;
145  int mPendingRequests = 0;
146  QStringList mErrors;
147  QString mAuthCfg;
148  QgsStringMap mRequestHeaders;
149 };
150 
152 
153 #endif // QGSARCGISRESTQUERY_H
Utility functions for querying ArcGIS REST services.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
A rectangle specified with double values.
Definition: qgsrectangle.h:42
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
QMap< QString, QString > QgsStringMap
Definition: qgis.h:1703
const QgsCoordinateReferenceSystem & crs