QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
qgssensorthingsutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssensorthingsutils.h
3 --------------------
4 begin : November 2023
5 copyright : (C) 2023 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 QGSSENSORTHINGSUTILS_H
16#define QGSSENSORTHINGSUTILS_H
17
18#include "qgis_sip.h"
19#include "qgis_core.h"
20#include "qgis.h"
21
22class QgsFields;
23class QgsFeedback;
24class QgsRectangle;
26
33class CORE_EXPORT QgsSensorThingsUtils
34{
35
36 public:
37
39 static constexpr int DEFAULT_PAGE_SIZE = 200; SIP_SKIP
40
42 static constexpr int DEFAULT_FEATURE_LIMIT = 10000; SIP_SKIP
43
45 static constexpr int DEFAULT_EXPANSION_LIMIT = 100; SIP_SKIP
46
52 static Qgis::SensorThingsEntity stringToEntity( const QString &type );
53
59 static QString displayString( Qgis::SensorThingsEntity type, bool plural = false );
60
66 static Qgis::SensorThingsEntity entitySetStringToEntity( const QString &type );
67
73 static QString entityToSetString( Qgis::SensorThingsEntity type );
74
80 static QStringList propertiesForEntityType( Qgis::SensorThingsEntity type );
81
85 static QgsFields fieldsForEntityType( Qgis::SensorThingsEntity type );
86
93 static QgsFields fieldsForExpandedEntityType( Qgis::SensorThingsEntity baseType, const QList< Qgis::SensorThingsEntity > &expandedTypes );
94
98 static QString geometryFieldForEntityType( Qgis::SensorThingsEntity type );
99
103 static bool entityTypeHasGeometry( Qgis::SensorThingsEntity type );
104
112 static Qgis::GeometryType geometryTypeForEntity( Qgis::SensorThingsEntity type );
113
118 static QString filterForWkbType( Qgis::SensorThingsEntity entityType, Qgis::WkbType wkbType );
119
128 static QString filterForExtent( const QString &geometryField, const QgsRectangle &extent );
129
137 static QString combineFilters( const QStringList &filters );
138
145 static QList< Qgis::GeometryType > availableGeometryTypes( const QString &uri, Qgis::SensorThingsEntity type, QgsFeedback *feedback = nullptr, const QString &authCfg = QString() );
146
152 static QList< Qgis::SensorThingsEntity > expandableTargets( Qgis::SensorThingsEntity type );
153
165 static Qgis::RelationshipCardinality relationshipCardinality( Qgis::SensorThingsEntity baseType, Qgis::SensorThingsEntity relatedType, bool &valid SIP_OUT );
166
174 static QString asQueryString( Qgis::SensorThingsEntity baseType, const QList< QgsSensorThingsExpansionDefinition > &expansions );
175
176};
177
178
186{
187 public:
188
193 const QString &orderBy = QString(),
194 Qt::SortOrder sortOrder = Qt::SortOrder::AscendingOrder,
196 const QString &filter = QString() );
197
202 static QgsSensorThingsExpansionDefinition defaultDefinitionForEntity( Qgis::SensorThingsEntity entity );
203
207 bool isValid() const;
208
214 Qgis::SensorThingsEntity childEntity() const;
215
221 void setChildEntity( Qgis::SensorThingsEntity entity );
222
229 QString orderBy() const;
230
237 void setOrderBy( const QString &field );
238
245 Qt::SortOrder sortOrder() const;
246
253 void setSortOrder( Qt::SortOrder order );
254
262 int limit() const;
263
271 void setLimit( int limit );
272
278 QString filter() const;
279
285 void setFilter( const QString &filter );
286
292 QString toString() const;
293
299 static QgsSensorThingsExpansionDefinition fromString( const QString &string );
300
308 QString asQueryString( Qgis::SensorThingsEntity parentEntityType, const QStringList &additionalOptions = QStringList() ) const;
309
310 bool operator==( const QgsSensorThingsExpansionDefinition &other ) const;
311 bool operator!=( const QgsSensorThingsExpansionDefinition &other ) const;
312
313#ifdef SIP_RUN
314 SIP_PYOBJECT __repr__();
315 % MethodCode
316 if ( !sipCpp->isValid() )
317 {
318 sipRes = PyUnicode_FromString( "<QgsSensorThingsExpansionDefinition: invalid>" );
319 }
320 else
321 {
322 QString innerDefinition;
323 if ( !sipCpp->orderBy().isEmpty() )
324 {
325 innerDefinition = QStringLiteral( "by %1 (%2)" ).arg( sipCpp->orderBy(), sipCpp->sortOrder() == Qt::SortOrder::AscendingOrder ? QStringLiteral( "asc" ) : QStringLiteral( "desc" ) );
326 }
327 if ( sipCpp->limit() >= 0 )
328 {
329 if ( !innerDefinition.isEmpty() )
330 innerDefinition = QStringLiteral( "%1, limit %2" ).arg( innerDefinition ).arg( sipCpp->limit() );
331 else
332 innerDefinition = QStringLiteral( "limit %1" ).arg( sipCpp->limit() );
333 }
334 if ( !sipCpp->filter().isEmpty() )
335 {
336 if ( !innerDefinition.isEmpty() )
337 innerDefinition = QStringLiteral( "%1, filter '%2'" ).arg( innerDefinition ).arg( sipCpp->filter() );
338 else
339 innerDefinition = QStringLiteral( "filter '%1'" ).arg( sipCpp->filter() );
340 }
341
342 QString str = QStringLiteral( "<QgsSensorThingsExpansionDefinition: %1%2>" ).arg( qgsEnumValueToKey( sipCpp->childEntity() ), innerDefinition.isEmpty() ? QString() : ( QStringLiteral( " " ) + innerDefinition ) );
343 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
344 }
345 % End
346#endif
347
348 private:
349
351 QString mOrderBy;
352 Qt::SortOrder mSortOrder = Qt::SortOrder::AscendingOrder;
354 QString mFilter;
355
356};
358
359#endif // QGSSENSORTHINGSUTILS_H
SensorThingsEntity
OGC SensorThings API entity types.
Definition qgis.h:5099
@ Invalid
An invalid/unknown entity.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:274
RelationshipCardinality
Relationship cardinality.
Definition qgis.h:3823
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:201
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Container of fields for a vector layer.
Definition qgsfields.h:46
A rectangle specified with double values.
Encapsulates information about how relationships in a SensorThings API service should be expanded.
Utility functions for working with OGC SensorThings API services.
static constexpr int DEFAULT_EXPANSION_LIMIT
Default limit on number of expanded features fetched.
#define str(x)
Definition qgis.cpp:38
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:5636
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_OUT
Definition qgis_sip.h:58
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)