QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsmemoryprovider.h
Go to the documentation of this file.
1 /***************************************************************************
2  memoryprovider.h - provider with storage in memory
3  ------------------
4  begin : June 2008
5  copyright : (C) 2008 by Martin Dobias
6  email : wonder dot sk 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 
16 #define SIP_NO_FILE
17 
18 #include "qgsvectordataprovider.h"
20 #include "qgsfields.h"
21 #include "qgsprovidermetadata.h"
22 
24 typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
25 
26 class QgsSpatialIndex;
27 
28 class QgsMemoryFeatureIterator;
29 
30 class QgsMemoryProvider final: public QgsVectorDataProvider
31 {
32  Q_OBJECT
33 
34  public:
35  explicit QgsMemoryProvider( const QString &uri, const QgsVectorDataProvider::ProviderOptions &coordinateTransformContext,
36  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
37 
38  ~QgsMemoryProvider() override;
39 
41  static QString providerKey();
43  static QString providerDescription();
44 
45  /* Implementation of functions from QgsVectorDataProvider */
46 
47  QgsAbstractFeatureSource *featureSource() const override;
48 
49  QString dataSourceUri( bool expandAuthConfig = true ) const override;
50  QString storageType() const override;
51  QgsFeatureIterator getFeatures( const QgsFeatureRequest &request ) const override;
52  QgsWkbTypes::Type wkbType() const override;
53  long long featureCount() const override;
54  QgsFields fields() const override;
55  bool addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
56  bool deleteFeatures( const QgsFeatureIds &id ) override;
57  bool addAttributes( const QList<QgsField> &attributes ) override;
58  bool renameAttributes( const QgsFieldNameMap &renamedAttributes ) override;
59  bool deleteAttributes( const QgsAttributeIds &attributes ) override;
60  bool changeAttributeValues( const QgsChangedAttributesMap &attr_map ) override;
61  bool changeGeometryValues( const QgsGeometryMap &geometry_map ) override;
62  QString subsetString() const override;
63  bool setSubsetString( const QString &theSQL, bool updateFeatureCount = true ) override;
64  bool supportsSubsetString() const override { return true; }
65  bool createSpatialIndex() override;
67  QgsVectorDataProvider::Capabilities capabilities() const override;
68  bool truncate() override;
69 
70  /* Implementation of functions from QgsDataProvider */
71 
72  QString name() const override;
73  QString description() const override;
74  QgsRectangle extent() const override;
75  void updateExtents() override;
76  bool isValid() const override;
77  QgsCoordinateReferenceSystem crs() const override;
78  void handlePostCloneOperations( QgsVectorDataProvider *source ) override;
79 
80  private:
81  // Coordinate reference system
83 
84  // fields
85  QgsFields mFields;
86  QgsWkbTypes::Type mWkbType;
87  mutable QgsRectangle mExtent;
88 
89  // features
90  QgsFeatureMap mFeatures;
91  QgsFeatureId mNextFeatureId;
92 
93  // indexing
94  QgsSpatialIndex *mSpatialIndex = nullptr;
95 
96  QString mSubsetString;
97 
98  friend class QgsMemoryFeatureSource;
99 };
100 
101 
102 class QgsMemoryProviderMetadata final: public QgsProviderMetadata
103 {
104  public:
105  QgsMemoryProviderMetadata();
106  QIcon icon() const override;
107  QgsDataProvider *createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) override;
108  QList< QgsMapLayerType > supportedLayerTypes() const override;
109 };
110 
qgsfields.h
QgsAttributeIds
QSet< int > QgsAttributeIds
Definition: qgsvectordataprovider.h:39
QgsFeatureSource::hasSpatialIndex
virtual SpatialIndexPresence hasSpatialIndex() const
Returns an enum value representing the presence of a valid spatial index on the source,...
Definition: qgsfeaturesource.cpp:190
QgsVectorDataProvider::deleteFeatures
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features from the provider.
Definition: qgsvectordataprovider.cpp:109
QgsVectorDataProvider::createSpatialIndex
virtual bool createSpatialIndex()
Creates a spatial index on the datasource (if supported by the provider type).
Definition: qgsvectordataprovider.cpp:197
QgsDataProvider::supportsSubsetString
virtual bool supportsSubsetString() const
Returns true if the provider supports setting of subset strings.
Definition: qgsdataprovider.h:274
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:107
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:40
QgsVectorDataProvider::handlePostCloneOperations
virtual void handlePostCloneOperations(QgsVectorDataProvider *source)
Handles any post-clone operations required after this vector data provider was cloned from the source...
Definition: qgsvectordataprovider.cpp:916
QgsVectorDataProvider::fields
QgsFields fields() const override=0
Returns the fields associated with this data provider.
QgsDataProvider::setSubsetString
virtual bool setSubsetString(const QString &subset, bool updateFeatureCount=true)
Set the subset string used to create a subset of features in the layer.
Definition: qgsdataprovider.h:262
QgsVectorDataProvider::changeAttributeValues
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
Definition: qgsvectordataprovider.cpp:147
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsVectorDataProvider::featureCount
long long featureCount() const override=0
Number of features in the layer.
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsChangedAttributesMap
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:868
QgsProviderMetadata::icon
virtual QIcon icon() const
Returns an icon representing the provider.
Definition: qgsprovidermetadata.cpp:55
QgsDataProvider::dataSourceUri
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
Definition: qgsdataprovider.h:166
QgsProviderMetadata::supportedLayerTypes
virtual QList< QgsMapLayerType > supportedLayerTypes() const
Returns a list of the map layer types supported by the provider.
Definition: qgsprovidermetadata.cpp:70
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsDataProvider::description
virtual QString description() const =0
Returns description.
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:83
QgsVectorDataProvider::capabilities
virtual Q_INVOKABLE QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
Definition: qgsvectordataprovider.cpp:208
qgsprovidermetadata.h
QgsVectorDataProvider::changeGeometryValues
virtual bool changeGeometryValues(const QgsGeometryMap &geometry_map)
Changes geometries of existing features.
Definition: qgsvectordataprovider.cpp:179
QgsVectorDataProvider::truncate
virtual bool truncate()
Removes all features from the layer.
Definition: qgsvectordataprovider.cpp:115
QgsVectorDataProvider::featureSource
virtual QgsAbstractFeatureSource * featureSource() const =0
Returns feature source object that can be used for querying provider's data.
QgsProviderMetadata::createProvider
virtual QgsDataProvider * createProvider(const QString &uri, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags=QgsDataProvider::ReadFlags())
Class factory to return a pointer to a newly created QgsDataProvider object.
Definition: qgsprovidermetadata.cpp:130
QgsFeatureSource::SpatialIndexPresence
SpatialIndexPresence
Enumeration of spatial index presence states.
Definition: qgsfeaturesource.h:187
QgsAbstractFeatureSource
Base class that can be used for any class that is capable of returning features.
Definition: qgsfeaturerequest.h:1009
QgsVectorDataProvider::renameAttributes
virtual bool renameAttributes(const QgsFieldNameMap &renamedAttributes)
Renames existing attributes.
Definition: qgsvectordataprovider.cpp:141
qgsvectordataprovider.h
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:882
QgsVectorDataProvider::storageType
virtual QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
Definition: qgsvectordataprovider.cpp:46
QgsSpatialIndex
A spatial index for QgsFeature objects.
Definition: qgsspatialindex.h:67
QgsFeatureMap
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
Definition: qgsvectorlayereditbuffer.h:31
QgsVectorDataProvider::getFeatures
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const override=0
Query the provider for features specified in request.
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsProviderMetadata
Holds data provider key, description, and associated shared library file or function pointer informat...
Definition: qgsprovidermetadata.h:177
QgsVectorDataProvider::deleteAttributes
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes from the provider.
Definition: qgsvectordataprovider.cpp:135
QgsVectorDataProvider::addFeatures
bool addFeatures(QgsFeatureList &flist, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a list of features to the sink.
Definition: qgsvectordataprovider.cpp:97
QgsDataProvider::extent
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
QgsFieldNameMap
QMap< int, QString > QgsFieldNameMap
Definition: qgsattributes.h:44
QgsVectorDataProvider::addAttributes
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes to the provider.
Definition: qgsvectordataprovider.cpp:129
QgsGeometryMap
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:877
QgsVectorDataProvider
This is the base class for vector data providers.
Definition: qgsvectordataprovider.h:58
QgsDataProvider::subsetString
virtual QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
Definition: qgsdataprovider.h:282
QgsDataProvider::name
virtual QString name() const =0
Returns a provider name.
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:289
qgscoordinatereferencesystem.h
QgsVectorDataProvider::wkbType
QgsWkbTypes::Type wkbType() const override=0
Returns the geometry type which is returned by this layer.
QgsDataProvider::isValid
virtual bool isValid() const =0
Returns true if this is a valid layer.
QgsDataProvider::updateExtents
virtual void updateExtents()
Update the extents of the layer.
Definition: qgsdataprovider.h:250
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
QgsDataProvider::crs
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.