QGIS API Documentation 3.99.0-Master (26c88405ac0)
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.h"
19#include "qgis_core.h"
20#include "qgis_sip.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
88 static QgsFields fieldsForEntityType( Qgis::SensorThingsEntity type, bool includeRangeFieldProxies = true );
89
96 static QgsFields fieldsForExpandedEntityType( Qgis::SensorThingsEntity baseType, const QList< Qgis::SensorThingsEntity > &expandedTypes );
97
102
107
116
121 static QString filterForWkbType( Qgis::SensorThingsEntity entityType, Qgis::WkbType wkbType );
122
131 static QString filterForExtent( const QString &geometryField, const QgsRectangle &extent );
132
140 static QString combineFilters( const QStringList &filters );
141
148 static QList< Qgis::GeometryType > availableGeometryTypes( const QString &uri, Qgis::SensorThingsEntity type, QgsFeedback *feedback = nullptr, const QString &authCfg = QString() );
149
155 static QList< Qgis::SensorThingsEntity > expandableTargets( Qgis::SensorThingsEntity type );
156
169
177 static QString asQueryString( Qgis::SensorThingsEntity baseType, const QList< QgsSensorThingsExpansionDefinition > &expansions );
178
179};
180
181
189{
190 public:
191
196 const QString &orderBy = QString(),
197 Qt::SortOrder sortOrder = Qt::SortOrder::AscendingOrder,
199 const QString &filter = QString() );
200
206
210 bool isValid() const;
211
218
225
232 QString orderBy() const;
233
240 void setOrderBy( const QString &field );
241
248 Qt::SortOrder sortOrder() const;
249
256 void setSortOrder( Qt::SortOrder order );
257
265 int limit() const;
266
274 void setLimit( int limit );
275
281 QString filter() const;
282
288 void setFilter( const QString &filter );
289
295 QString toString() const;
296
302 static QgsSensorThingsExpansionDefinition fromString( const QString &string );
303
311 QString asQueryString( Qgis::SensorThingsEntity parentEntityType, const QStringList &additionalOptions = QStringList() ) const;
312
313 bool operator==( const QgsSensorThingsExpansionDefinition &other ) const;
314 bool operator!=( const QgsSensorThingsExpansionDefinition &other ) const;
315
316#ifdef SIP_RUN
317 SIP_PYOBJECT __repr__();
318 % MethodCode
319 if ( !sipCpp->isValid() )
320 {
321 sipRes = PyUnicode_FromString( "<QgsSensorThingsExpansionDefinition: invalid>" );
322 }
323 else
324 {
325 QString innerDefinition;
326 if ( !sipCpp->orderBy().isEmpty() )
327 {
328 innerDefinition = QStringLiteral( "by %1 (%2)" ).arg( sipCpp->orderBy(), sipCpp->sortOrder() == Qt::SortOrder::AscendingOrder ? QStringLiteral( "asc" ) : QStringLiteral( "desc" ) );
329 }
330 if ( sipCpp->limit() >= 0 )
331 {
332 if ( !innerDefinition.isEmpty() )
333 innerDefinition = QStringLiteral( "%1, limit %2" ).arg( innerDefinition ).arg( sipCpp->limit() );
334 else
335 innerDefinition = QStringLiteral( "limit %1" ).arg( sipCpp->limit() );
336 }
337 if ( !sipCpp->filter().isEmpty() )
338 {
339 if ( !innerDefinition.isEmpty() )
340 innerDefinition = QStringLiteral( "%1, filter '%2'" ).arg( innerDefinition ).arg( sipCpp->filter() );
341 else
342 innerDefinition = QStringLiteral( "filter '%1'" ).arg( sipCpp->filter() );
343 }
344
345 QString str = QStringLiteral( "<QgsSensorThingsExpansionDefinition: %1%2>" ).arg( qgsEnumValueToKey( sipCpp->childEntity() ), innerDefinition.isEmpty() ? QString() : ( QStringLiteral( " " ) + innerDefinition ) );
346 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
347 }
348 % End
349#endif
350
351 private:
352
354 QString mOrderBy;
355 Qt::SortOrder mSortOrder = Qt::SortOrder::AscendingOrder;
357 QString mFilter;
358
359};
361
362#endif // QGSSENSORTHINGSUTILS_H
SensorThingsEntity
OGC SensorThings API entity types.
Definition qgis.h:5966
@ Invalid
An invalid/unknown entity.
Definition qgis.h:5967
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
RelationshipCardinality
Relationship cardinality.
Definition qgis.h:4417
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
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.
Qgis::SensorThingsEntity childEntity() const
Returns the target child entity which should be expanded.
void setLimit(int limit)
Sets the limit on the number of child features to fetch.
void setChildEntity(Qgis::SensorThingsEntity entity)
Sets the target child entity which should be expanded.
void setSortOrder(Qt::SortOrder order)
Sets the sort order for the expanded child entities.
static QgsSensorThingsExpansionDefinition defaultDefinitionForEntity(Qgis::SensorThingsEntity entity)
Returns an expansion definition for the specified entity type, populated with reasonable defaults whi...
static QgsSensorThingsExpansionDefinition fromString(const QString &string)
Returns a QgsSensorThingsExpansionDefinition from a string representation.
void setFilter(const QString &filter)
Returns the the string filter to filter expanded child entities by.
QString asQueryString(Qgis::SensorThingsEntity parentEntityType, const QStringList &additionalOptions=QStringList()) const
Returns the expansion as a valid SensorThings API query string, eg "$expand=Observations($orderby=phe...
int limit() const
Returns the limit on the number of child features to fetch.
void setOrderBy(const QString &field)
Sets the field name to order the expanded child entities by.
Qt::SortOrder sortOrder() const
Returns the sort order for the expanded child entities.
QString toString() const
Returns a string encapsulation of the expansion definition.
QString orderBy() const
Returns the field name to order the expanded child entities by.
QString filter() const
Returns the the string filter to filter expanded child entities by.
QgsSensorThingsExpansionDefinition(Qgis::SensorThingsEntity childEntity=Qgis::SensorThingsEntity::Invalid, const QString &orderBy=QString(), Qt::SortOrder sortOrder=Qt::SortOrder::AscendingOrder, int limit=QgsSensorThingsUtils::DEFAULT_EXPANSION_LIMIT, const QString &filter=QString())
Constructor for QgsSensorThingsExpansionDefinition, targeting the specified child entity type.
bool isValid() const
Returns true if the definition is valid.
Utility functions for working with OGC SensorThings API services.
static constexpr int DEFAULT_EXPANSION_LIMIT
Default limit on number of expanded features fetched.
static QStringList propertiesForEntityType(Qgis::SensorThingsEntity type)
Returns the SensorThings properties which correspond to a specified entity type.
static constexpr int DEFAULT_PAGE_SIZE
Default page size.
static QList< Qgis::GeometryType > availableGeometryTypes(const QString &uri, Qgis::SensorThingsEntity type, QgsFeedback *feedback=nullptr, const QString &authCfg=QString())
Returns a list of available geometry types for the server at the specified uri and entity type.
static Qgis::SensorThingsEntity stringToEntity(const QString &type)
Converts a string value to a Qgis::SensorThingsEntity type.
static constexpr int DEFAULT_FEATURE_LIMIT
Default limit on number of features fetched.
static QString entityToSetString(Qgis::SensorThingsEntity type)
Converts a SensorThings entity set to a SensorThings entity set string.
static QString asQueryString(Qgis::SensorThingsEntity baseType, const QList< QgsSensorThingsExpansionDefinition > &expansions)
Returns a list of expansions as a valid SensorThings API query string, eg "$expand=Locations($orderby...
static Qgis::SensorThingsEntity entitySetStringToEntity(const QString &type)
Converts a string value corresponding to a SensorThings entity set to a Qgis::SensorThingsEntity type...
static QString combineFilters(const QStringList &filters)
Combines a set of SensorThings API filter operators.
static QString filterForWkbType(Qgis::SensorThingsEntity entityType, Qgis::WkbType wkbType)
Returns a filter string which restricts results to those matching the specified entityType and wkbTyp...
static Qgis::RelationshipCardinality relationshipCardinality(Qgis::SensorThingsEntity baseType, Qgis::SensorThingsEntity relatedType, bool &valid)
Returns the cardinality of the relationship between a base entity type and a related entity type.
static Qgis::GeometryType geometryTypeForEntity(Qgis::SensorThingsEntity type)
Returns the geometry type for if the specified entity type.
static QgsFields fieldsForEntityType(Qgis::SensorThingsEntity type, bool includeRangeFieldProxies=true)
Returns the fields which correspond to a specified entity type.
static QString displayString(Qgis::SensorThingsEntity type, bool plural=false)
Converts a Qgis::SensorThingsEntity type to a user-friendly translated string.
static bool entityTypeHasGeometry(Qgis::SensorThingsEntity type)
Returns true if the specified entity type can have geometry attached.
static QgsFields fieldsForExpandedEntityType(Qgis::SensorThingsEntity baseType, const QList< Qgis::SensorThingsEntity > &expandedTypes)
Returns the fields which correspond to a specified entity baseType, expanded using the specified list...
static QString geometryFieldForEntityType(Qgis::SensorThingsEntity type)
Returns the geometry field for a specified entity type.
static QList< Qgis::SensorThingsEntity > expandableTargets(Qgis::SensorThingsEntity type)
Returns a list of permissible expand targets for a given base entity type.
static QString filterForExtent(const QString &geometryField, const QgsRectangle &extent)
Returns a filter string which restricts results to those within the specified extent.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:6798
#define SIP_SKIP
Definition qgis_sip.h:134
#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)