QGIS API Documentation 4.1.0-Master (3fcefe620d1)
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
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
26class QgsFields;
27class QgsFeedback;
28class QgsRectangle;
30
37class CORE_EXPORT QgsSensorThingsUtils
38{
39 public:
41 static constexpr int DEFAULT_PAGE_SIZE = 200 SIP_SKIP;
42
44 static constexpr int DEFAULT_FEATURE_LIMIT = 10000 SIP_SKIP;
45
47 static constexpr int DEFAULT_EXPANSION_LIMIT = 100 SIP_SKIP;
48
54 static Qgis::SensorThingsEntity stringToEntity( const QString &type );
55
61 static QString displayString( Qgis::SensorThingsEntity type, bool plural = false );
62
68 static Qgis::SensorThingsEntity entitySetStringToEntity( const QString &type );
69
75 static QString entityToSetString( Qgis::SensorThingsEntity type );
76
82 static QStringList propertiesForEntityType( Qgis::SensorThingsEntity type );
83
90 static QgsFields fieldsForEntityType( Qgis::SensorThingsEntity type, bool includeRangeFieldProxies = true );
91
98 static QgsFields fieldsForExpandedEntityType( Qgis::SensorThingsEntity baseType, const QList< Qgis::SensorThingsEntity > &expandedTypes );
99
104
109
118
123 static QString filterForWkbType( Qgis::SensorThingsEntity entityType, Qgis::WkbType wkbType );
124
133 static QString filterForExtent( const QString &geometryField, const QgsRectangle &extent );
134
142 static QString combineFilters( const QStringList &filters );
143
156
162 static ServiceCapabilities determineServiceCapabilities( const QString &uri, QgsFeedback *feedback = nullptr, const QString &authCfg = QString() );
163
170 static QList< Qgis::GeometryType > availableGeometryTypes( const QString &uri, Qgis::SensorThingsEntity type, QgsFeedback *feedback = nullptr, const QString &authCfg = QString() );
171
177 static QList< Qgis::SensorThingsEntity > expandableTargets( Qgis::SensorThingsEntity type );
178
191
199 static QString asQueryString( Qgis::SensorThingsEntity baseType, const QList< QgsSensorThingsExpansionDefinition > &expansions );
200};
201
202
210{
211 public:
217 const QString &orderBy = QString(),
218 Qt::SortOrder sortOrder = Qt::SortOrder::AscendingOrder,
220 const QString &filter = QString()
221 );
222
228
232 bool isValid() const;
233
240
247
254 QString orderBy() const;
255
262 void setOrderBy( const QString &field );
263
270 Qt::SortOrder sortOrder() const;
271
278 void setSortOrder( Qt::SortOrder order );
279
287 int limit() const;
288
296 void setLimit( int limit );
297
303 QString filter() const;
304
310 void setFilter( const QString &filter );
311
317 QString toString() const;
318
324 static QgsSensorThingsExpansionDefinition fromString( const QString &string );
325
333 QString asQueryString( Qgis::SensorThingsEntity parentEntityType, const QStringList &additionalOptions = QStringList() ) const;
334
335 bool operator==( const QgsSensorThingsExpansionDefinition &other ) const;
336 bool operator!=( const QgsSensorThingsExpansionDefinition &other ) const;
337
338#ifdef SIP_RUN
339 // clang-format off
340 SIP_PYOBJECT __repr__();
341 % MethodCode
342 if ( !sipCpp->isValid() )
343 {
344 sipRes = PyUnicode_FromString( "<QgsSensorThingsExpansionDefinition: invalid>" );
345 }
346 else
347 {
348 QString innerDefinition;
349 if ( !sipCpp->orderBy().isEmpty() )
350 {
351 innerDefinition = u"by %1 (%2)"_s.arg( sipCpp->orderBy(), sipCpp->sortOrder() == Qt::SortOrder::AscendingOrder ? u"asc"_s : u"desc"_s );
352 }
353 if ( sipCpp->limit() >= 0 )
354 {
355 if ( !innerDefinition.isEmpty() )
356 innerDefinition = u"%1, limit %2"_s.arg( innerDefinition ).arg( sipCpp->limit() );
357 else
358 innerDefinition = u"limit %1"_s.arg( sipCpp->limit() );
359 }
360 if ( !sipCpp->filter().isEmpty() )
361 {
362 if ( !innerDefinition.isEmpty() )
363 innerDefinition = u"%1, filter '%2'"_s.arg( innerDefinition ).arg( sipCpp->filter() );
364 else
365 innerDefinition = u"filter '%1'"_s.arg( sipCpp->filter() );
366 }
367
368 QString str = u"<QgsSensorThingsExpansionDefinition: %1%2>"_s.arg( qgsEnumValueToKey( sipCpp->childEntity() ), innerDefinition.isEmpty() ? QString() : ( u" "_s + innerDefinition ) );
369 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
370 }
371 % End
372// clang-format on
373#endif
374
375 // clang-format off
376 private:
377 // clang-format on
378
379 Qgis::SensorThingsEntity mChildEntity
381 QString mOrderBy;
382 Qt::SortOrder mSortOrder = Qt::SortOrder::AscendingOrder;
384 QString mFilter;
385};
387
388#endif // QGSSENSORTHINGSUTILS_H
QFlags< SensorThingsExtension > SensorThingsExtensions
OGC SensorThings extensions.
Definition qgis.h:6616
SensorThingsEntity
OGC SensorThings API entity types.
Definition qgis.h:6625
@ Invalid
An invalid/unknown entity.
Definition qgis.h:6626
SensorThingsVersion
OGC SensorThings API versions.
Definition qgis.h:6591
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:379
RelationshipCardinality
Relationship cardinality.
Definition qgis.h:4815
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
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 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 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 ServiceCapabilities determineServiceCapabilities(const QString &uri, QgsFeedback *feedback=nullptr, const QString &authCfg=QString())
Retrieves general service capabilities for a SensorThings server.
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:7576
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_OUT
Definition qgis_sip.h:57
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
SensorThings service capabilities.
QSet< Qgis::SensorThingsEntity > availableEntities
Available SensorThings entities.
Qgis::SensorThingsExtensions availableExtensions
Available SensorThings extensions.
Qgis::SensorThingsVersion version
SensorThings API version.