QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsfeaturestore.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfeaturestore.h
3 --------------------------------------
4 Date : February 2013
5 Copyright : (C) 2013 by Radim Blazek
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 QGSFEATURESTORE_H
16#define QGSFEATURESTORE_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
20#include "qgsfeature.h"
21#include "qgsfields.h"
22#include "qgsfeaturesink.h"
24#include <QList>
25#include <QMetaType>
26#include <QVariant>
27
32class CORE_EXPORT QgsFeatureStore : public QgsFeatureSink
33{
34 public:
35 QgsFeatureStore() = default;
36
39
44 QgsFields fields() const { return mFields; }
45
50 void setFields( const QgsFields &fields );
51
56 QgsCoordinateReferenceSystem crs() const { return mCrs; }
57
62 void setCrs( const QgsCoordinateReferenceSystem &crs ) { mCrs = crs; }
63
64 bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
65 bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
66
70 int count() const { return mFeatures.size(); }
71
72#ifdef SIP_RUN
73
77 int __len__() const;
78 % MethodCode
79 sipRes = sipCpp->count();
80 % End
81
83 int __bool__() const;
84 % MethodCode
85 sipRes = true;
86 % End
87#endif
88
92 QgsFeatureList features() const { return mFeatures; }
93
98 void setParams( const QMap<QString, QVariant> &parameters ) { mParams = parameters; }
99
104 QMap<QString, QVariant> params() const { return mParams; }
105
106 private:
107 QgsFields mFields;
108
110
111 QgsFeatureList mFeatures;
112
113 // Optional parameters
114 QMap<QString, QVariant> mParams;
115};
116
117#ifndef SIP_RUN
118typedef QVector<QgsFeatureStore> QgsFeatureStoreList;
119#else
120typedef QVector<QgsFeatureStore> QgsFeatureStoreList;
121
122% MappedType QgsFeatureStoreList
123{
124 % TypeHeaderCode
125#include "qgsfeaturestore.h"
126 % End
127
128 % ConvertFromTypeCode
129 // Create the list.
130 PyObject *l;
131
132 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
133 return NULL;
134
135 // Set the list elements.
136 for ( int i = 0; i < sipCpp->size(); ++i )
137 {
138 QgsFeatureStore *v = new QgsFeatureStore( sipCpp->at( i ) );
139 PyObject *tobj;
140
141 if ( ( tobj = sipConvertFromNewType( v, sipType_QgsFeatureStore, Py_None ) ) == NULL )
142 {
143 Py_DECREF( l );
144 delete v;
145
146 return NULL;
147 }
148
149 PyList_SET_ITEM( l, i, tobj );
150 }
151
152 return l;
153 % End
154
155 % ConvertToTypeCode
156 // Check the type if that is all that is required.
157 if ( sipIsErr == NULL )
158 {
159 if ( !PyList_Check( sipPy ) )
160 return 0;
161
162 for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
163 if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QgsFeatureStore, SIP_NOT_NONE ) )
164 return 0;
165
166 return 1;
167 }
168
170 SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
171 qv->reserve( listSize );
172
173 for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
174 {
175 PyObject *obj = PyList_GET_ITEM( sipPy, i );
176 int state;
177 QgsFeatureStore *t = reinterpret_cast<QgsFeatureStore *>( sipConvertToType( obj, sipType_QgsFeatureStore, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );
178
179 if ( *sipIsErr )
180 {
181 sipReleaseType( t, sipType_QgsFeatureStore, state );
182
183 delete qv;
184 return 0;
185 }
186
187 qv->append( *t );
188 sipReleaseType( t, sipType_QgsFeatureStore, state );
189 }
190
191 *sipCppPtr = qv;
192
193 return sipGetState( sipTransferObj );
194 % End
195};
196#endif
197
199
201
202#endif
This class represents a coordinate reference system (CRS).
An interface for objects which accept features via addFeature(s) methods.
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
Adds a single feature to the sink.
virtual bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())=0
Adds a list of features to the sink.
QFlags< Flag > Flags
A container for features with the same fields and crs.
QgsFeatureList features() const
Returns the list of features contained in the store.
QgsFields fields() const
Returns the store's field list.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the store's crs.
QMap< QString, QVariant > params() const
Returns the map of optional parameters.
int count() const
Returns the number of features contained in the store.
QgsCoordinateReferenceSystem crs() const
Returns the store's coordinate reference system.
void setParams(const QMap< QString, QVariant > &parameters)
Sets a map of optional parameters for the store.
QgsFeatureStore()=default
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Container of fields for a vector layer.
Definition qgsfields.h:46
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QList< QgsFeature > QgsFeatureList
QVector< QgsFeatureStore > QgsFeatureStoreList
const QgsCoordinateReferenceSystem & crs