QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsserverapiutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsserverapiutils.h
3
4 Class defining utilities for QGIS server APIs.
5 -------------------
6 begin : 2019-04-16
7 copyright : (C) 2019 by Alessandro Pasotti
8 email : elpaso at itopen dot it
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20
21#ifndef QGSSERVERAPIUTILS_H
22#define QGSSERVERAPIUTILS_H
23
24#include "qgis_server.h"
25#include "qgsjsonutils.h"
27#include "qgsproject.h"
28#include "qgsrange.h"
29#include "qgsserverapicontext.h"
30#include "qgsserverexception.h"
32
33#include <QString>
34
35#ifdef HAVE_SERVER_PYTHON_PLUGINS
36#include "qgsaccesscontrol.h"
37#include "qgsserverinterface.h"
38#endif
39
40class QgsRectangle;
42class QgsVectorLayer;
43
44#ifndef SIP_RUN
45#include <nlohmann/json_fwd.hpp>
46using namespace nlohmann;
47#endif
48
54class SERVER_EXPORT QgsServerApiUtils
55{
56 public:
57
63 static QgsRectangle parseBbox( const QString &bbox );
64
69 static QList<QgsServerWmsDimensionProperties::WmsDimensionInfo> temporalDimensions( const QgsVectorLayer *layer );
70
78
86
87
93 static QString fieldName( const QString &name, const QgsVectorLayer *layer ) SIP_THROW( QgsServerApiBadRequestException );
94
96 // T is TemporalDateInterval|TemporalDateTimeInterval, T2 is QDate|QdateTime
97 template<typename T, class T2> static T parseTemporalInterval( const QString &interval ) SIP_SKIP;
99
100
113 static QgsExpression temporalFilterExpression( const QgsVectorLayer *layer, const QString &interval );
114
118 static json layerExtent( const QgsVectorLayer *layer ) SIP_SKIP;
119
137 static json temporalExtent( const QgsVectorLayer *layer ) SIP_SKIP;
138
155 static QVariantList temporalExtentList( const QgsVectorLayer *layer ) SIP_PYNAME( temporalExtent );
156
160 static QgsCoordinateReferenceSystem parseCrs( const QString &bboxCrs );
161
167 static const QVector<QgsVectorLayer *> publishedWfsLayers( const QgsServerApiContext &context );
168
169#ifndef SIP_RUN
170
180 template<typename T>
181 static const QVector<T> publishedWfsLayers( const QgsServerApiContext &context )
182 {
183#ifdef HAVE_SERVER_PYTHON_PLUGINS
184 QgsAccessControl *accessControl = context.serverInterface()->accessControls();
185#endif
186 const QgsProject *project = context.project();
187 QVector<T> result;
188 if ( project )
189 {
190 const QStringList wfsLayerIds = QgsServerProjectUtils::wfsLayerIds( *project );
191 const auto constLayers { project->layers<T>() };
192 for ( const auto &layer : constLayers )
193 {
194 if ( !wfsLayerIds.contains( layer->id() ) )
195 {
196 continue;
197 }
198#ifdef HAVE_SERVER_PYTHON_PLUGINS
199 if ( accessControl && !accessControl->layerReadPermission( layer ) )
200 {
201 continue;
202 }
203#endif
204 result.push_back( layer );
205 }
206 }
207 return result;
208 }
209
210#endif
211
212
217 static QString sanitizedFieldValue( const QString &value );
218
223 static QStringList publishedCrsList( const QgsProject *project );
224
231 Q_DECL_DEPRECATED static QString crsToOgcUri( const QgsCoordinateReferenceSystem &crs ) SIP_DEPRECATED;
232
236 static QString appendMapParameter( const QString &path, const QUrl &requestUrl );
237};
238#endif // QGSSERVERAPIUTILS_H
A helper class that centralizes restrictions given by all the access control filter plugins.
bool layerReadPermission(const QgsMapLayer *layer) const
Returns the layer read right.
Represents a coordinate reference system (CRS).
Handles parsing and evaluation of expressions (formerly called "search strings").
QString id
Definition qgsmaplayer.h:83
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
A rectangle specified with double values.
Bad request error API exception.
Encapsulates the resources for a particular client request.
const QgsProject * project() const
Returns the (possibly NULL) project.
QgsServerInterface * serverInterface() const
Returns the server interface.
Contains helper functions to handle common API operations.
static const QVector< T > publishedWfsLayers(const QgsServerApiContext &context)
Returns the list of layers of type T accessible to the WFS service for a given project.
static QgsExpression temporalFilterExpression(const QgsVectorLayer *layer, const QString &interval)
Parses the interval and constructs a (possibly invalid) temporal filter expression for the given laye...
static QVariantList temporalExtentList(const QgsVectorLayer *layer)
temporalExtent returns a json array with an array of [min, max] temporal extent for the given layer.
static QString fieldName(const QString &name, const QgsVectorLayer *layer)
Given a field name (or display name) and a layer returns the actual name of the field.
static QgsCoordinateReferenceSystem parseCrs(const QString &bboxCrs)
Parses the CRS URI bboxCrs (example: "http://www.opengis.net/def/crs/OGC/1.3/CRS84") into a QGIS CRS ...
static json temporalExtent(const QgsVectorLayer *layer)
temporalExtent returns a json array with an array of [min, max] temporal extent for the given layer.
static const QVector< QgsVectorLayer * > publishedWfsLayers(const QgsServerApiContext &context)
Returns the list of layers accessible to the service for a given context.
static json layerExtent(const QgsVectorLayer *layer)
layerExtent returns json array with [xMin,yMin,xMax,yMax] CRS84 extent for the given layer
static QgsDateTimeRange parseTemporalDateTimeInterval(const QString &interval)
Parses a datetime interval and returns a QgsDateTimeRange.
static QgsDateRange parseTemporalDateInterval(const QString &interval)
Parses a date interval and returns a QgsDateRange.
static QList< QgsServerWmsDimensionProperties::WmsDimensionInfo > temporalDimensions(const QgsVectorLayer *layer)
Returns a list of temporal dimensions information for the given layer (either configured in wmsDimens...
static QgsRectangle parseBbox(const QString &bbox)
Parses a comma separated bbox into a (possibly empty) QgsRectangle.
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
static QStringList wfsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WFS.
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_PYNAME(name)
Definition qgis_sip.h:89
#define SIP_THROW(name,...)
Definition qgis_sip.h:211
QgsTemporalRange< QDate > QgsDateRange
QgsRange which stores a range of dates.
Definition qgsrange.h:747
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:761