QGIS API Documentation 3.99.0-Master (d270888f95f)
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
40 public:
41
43 static constexpr int DEFAULT_PAGE_SIZE = 200; SIP_SKIP
44
46 static constexpr int DEFAULT_FEATURE_LIMIT = 10000; SIP_SKIP
47
49 static constexpr int DEFAULT_EXPANSION_LIMIT = 100; SIP_SKIP
50
56 static Qgis::SensorThingsEntity stringToEntity( const QString &type );
57
63 static QString displayString( Qgis::SensorThingsEntity type, bool plural = false );
64
70 static Qgis::SensorThingsEntity entitySetStringToEntity( const QString &type );
71
77 static QString entityToSetString( Qgis::SensorThingsEntity type );
78
84 static QStringList propertiesForEntityType( Qgis::SensorThingsEntity type );
85
92 static QgsFields fieldsForEntityType( Qgis::SensorThingsEntity type, bool includeRangeFieldProxies = true );
93
100 static QgsFields fieldsForExpandedEntityType( Qgis::SensorThingsEntity baseType, const QList< Qgis::SensorThingsEntity > &expandedTypes );
101
106
111
120
125 static QString filterForWkbType( Qgis::SensorThingsEntity entityType, Qgis::WkbType wkbType );
126
135 static QString filterForExtent( const QString &geometryField, const QgsRectangle &extent );
136
144 static QString combineFilters( const QStringList &filters );
145
152 static QList< Qgis::GeometryType > availableGeometryTypes( const QString &uri, Qgis::SensorThingsEntity type, QgsFeedback *feedback = nullptr, const QString &authCfg = QString() );
153
159 static QList< Qgis::SensorThingsEntity > expandableTargets( Qgis::SensorThingsEntity type );
160
173
181 static QString asQueryString( Qgis::SensorThingsEntity baseType, const QList< QgsSensorThingsExpansionDefinition > &expansions );
182
183};
184
185
193{
194 public:
195
200 const QString &orderBy = QString(),
201 Qt::SortOrder sortOrder = Qt::SortOrder::AscendingOrder,
203 const QString &filter = QString() );
204
210
214 bool isValid() const;
215
222
229
236 QString orderBy() const;
237
244 void setOrderBy( const QString &field );
245
252 Qt::SortOrder sortOrder() const;
253
260 void setSortOrder( Qt::SortOrder order );
261
269 int limit() const;
270
278 void setLimit( int limit );
279
285 QString filter() const;
286
292 void setFilter( const QString &filter );
293
299 QString toString() const;
300
306 static QgsSensorThingsExpansionDefinition fromString( const QString &string );
307
315 QString asQueryString( Qgis::SensorThingsEntity parentEntityType, const QStringList &additionalOptions = QStringList() ) const;
316
317 bool operator==( const QgsSensorThingsExpansionDefinition &other ) const;
318 bool operator!=( const QgsSensorThingsExpansionDefinition &other ) const;
319
320#ifdef SIP_RUN
321 SIP_PYOBJECT __repr__();
322 % MethodCode
323 if ( !sipCpp->isValid() )
324 {
325 sipRes = PyUnicode_FromString( "<QgsSensorThingsExpansionDefinition: invalid>" );
326 }
327 else
328 {
329 QString innerDefinition;
330 if ( !sipCpp->orderBy().isEmpty() )
331 {
332 innerDefinition = u"by %1 (%2)"_s.arg( sipCpp->orderBy(), sipCpp->sortOrder() == Qt::SortOrder::AscendingOrder ? u"asc"_s : u"desc"_s );
333 }
334 if ( sipCpp->limit() >= 0 )
335 {
336 if ( !innerDefinition.isEmpty() )
337 innerDefinition = u"%1, limit %2"_s.arg( innerDefinition ).arg( sipCpp->limit() );
338 else
339 innerDefinition = u"limit %1"_s.arg( sipCpp->limit() );
340 }
341 if ( !sipCpp->filter().isEmpty() )
342 {
343 if ( !innerDefinition.isEmpty() )
344 innerDefinition = u"%1, filter '%2'"_s.arg( innerDefinition ).arg( sipCpp->filter() );
345 else
346 innerDefinition = u"filter '%1'"_s.arg( sipCpp->filter() );
347 }
348
349 QString str = u"<QgsSensorThingsExpansionDefinition: %1%2>"_s.arg( qgsEnumValueToKey( sipCpp->childEntity() ), innerDefinition.isEmpty() ? QString() : ( u" "_s + innerDefinition ) );
350 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
351 }
352 % End
353#endif
354
355 private:
356
358 QString mOrderBy;
359 Qt::SortOrder mSortOrder = Qt::SortOrder::AscendingOrder;
361 QString mFilter;
362
363};
365
366#endif // QGSSENSORTHINGSUTILS_H
SensorThingsEntity
OGC SensorThings API entity types.
Definition qgis.h:6232
@ Invalid
An invalid/unknown entity.
Definition qgis.h:6233
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:365
RelationshipCardinality
Relationship cardinality.
Definition qgis.h:4476
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
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 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:7091
#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)