QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
150 static QList< Qgis::GeometryType > availableGeometryTypes( const QString &uri, Qgis::SensorThingsEntity type, QgsFeedback *feedback = nullptr, const QString &authCfg = QString() );
151
157 static QList< Qgis::SensorThingsEntity > expandableTargets( Qgis::SensorThingsEntity type );
158
171
179 static QString asQueryString( Qgis::SensorThingsEntity baseType, const QList< QgsSensorThingsExpansionDefinition > &expansions );
180};
181
182
190{
191 public:
197 const QString &orderBy = QString(),
198 Qt::SortOrder sortOrder = Qt::SortOrder::AscendingOrder,
200 const QString &filter = QString()
201 );
202
208
212 bool isValid() const;
213
220
227
234 QString orderBy() const;
235
242 void setOrderBy( const QString &field );
243
250 Qt::SortOrder sortOrder() const;
251
258 void setSortOrder( Qt::SortOrder order );
259
267 int limit() const;
268
276 void setLimit( int limit );
277
283 QString filter() const;
284
290 void setFilter( const QString &filter );
291
297 QString toString() const;
298
304 static QgsSensorThingsExpansionDefinition fromString( const QString &string );
305
313 QString asQueryString( Qgis::SensorThingsEntity parentEntityType, const QStringList &additionalOptions = QStringList() ) const;
314
315 bool operator==( const QgsSensorThingsExpansionDefinition &other ) const;
316 bool operator!=( const QgsSensorThingsExpansionDefinition &other ) const;
317
318#ifdef SIP_RUN
319 // clang-format off
320 SIP_PYOBJECT __repr__();
321 % MethodCode
322 if ( !sipCpp->isValid() )
323 {
324 sipRes = PyUnicode_FromString( "<QgsSensorThingsExpansionDefinition: invalid>" );
325 }
326 else
327 {
328 QString innerDefinition;
329 if ( !sipCpp->orderBy().isEmpty() )
330 {
331 innerDefinition = u"by %1 (%2)"_s.arg( sipCpp->orderBy(), sipCpp->sortOrder() == Qt::SortOrder::AscendingOrder ? u"asc"_s : u"desc"_s );
332 }
333 if ( sipCpp->limit() >= 0 )
334 {
335 if ( !innerDefinition.isEmpty() )
336 innerDefinition = u"%1, limit %2"_s.arg( innerDefinition ).arg( sipCpp->limit() );
337 else
338 innerDefinition = u"limit %1"_s.arg( sipCpp->limit() );
339 }
340 if ( !sipCpp->filter().isEmpty() )
341 {
342 if ( !innerDefinition.isEmpty() )
343 innerDefinition = u"%1, filter '%2'"_s.arg( innerDefinition ).arg( sipCpp->filter() );
344 else
345 innerDefinition = u"filter '%1'"_s.arg( sipCpp->filter() );
346 }
347
348 QString str = u"<QgsSensorThingsExpansionDefinition: %1%2>"_s.arg( qgsEnumValueToKey( sipCpp->childEntity() ), innerDefinition.isEmpty() ? QString() : ( u" "_s + innerDefinition ) );
349 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
350 }
351 % End
352// clang-format on
353#endif
354
355 // clang-format off
356 private:
357 // clang-format on
358
359 Qgis::SensorThingsEntity mChildEntity
361 QString mOrderBy;
362 Qt::SortOrder mSortOrder = Qt::SortOrder::AscendingOrder;
364 QString mFilter;
365};
367
368#endif // QGSSENSORTHINGSUTILS_H
SensorThingsEntity
OGC SensorThings API entity types.
Definition qgis.h:6324
@ Invalid
An invalid/unknown entity.
Definition qgis.h:6325
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:379
RelationshipCardinality
Relationship cardinality.
Definition qgis.h:4561
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 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:7157
#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)