QGIS API Documentation 3.99.0-Master (752b475928d)
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"
21#include "qgsfeature.h"
22#include "qgsfeaturesink.h"
23#include "qgsfields.h"
24
25#include <QList>
26#include <QMetaType>
27#include <QVariant>
28
33class CORE_EXPORT QgsFeatureStore : public QgsFeatureSink
34{
35 public:
36 QgsFeatureStore() = default;
37
40
45 QgsFields fields() const { return mFields; }
46
51 void setFields( const QgsFields &fields );
52
57 QgsCoordinateReferenceSystem crs() const { return mCrs; }
58
63 void setCrs( const QgsCoordinateReferenceSystem &crs ) { mCrs = crs; }
64
65 bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
66
68 bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
69
73 int count() const { return mFeatures.size(); }
74
75#ifdef SIP_RUN
76
80 int __len__() const;
81 % MethodCode
82 sipRes = sipCpp->count();
83 % End
84
86 int __bool__() const;
87 % MethodCode
88 sipRes = true;
89 % End
90#endif
91
95 QgsFeatureList features() const { return mFeatures; }
96
101 void setParams( const QMap<QString, QVariant> &parameters ) { mParams = parameters; }
102
107 QMap<QString, QVariant> params() const { return mParams; }
108
109 private:
110 QgsFields mFields;
111
113
114 QgsFeatureList mFeatures;
115
116 // Optional parameters
117 QMap<QString, QVariant> mParams;
118};
119
120#ifndef SIP_RUN
121typedef QVector<QgsFeatureStore> QgsFeatureStoreList;
122#else
123typedef QVector<QgsFeatureStore> QgsFeatureStoreList;
124
125% MappedType QgsFeatureStoreList
126{
127 % TypeHeaderCode
128#include "qgsfeaturestore.h"
129 % End
130
131 % ConvertFromTypeCode
132 // Create the list.
133 PyObject *l;
134
135 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
136 return NULL;
137
138 // Set the list elements.
139 for ( int i = 0; i < sipCpp->size(); ++i )
140 {
141 QgsFeatureStore *v = new QgsFeatureStore( sipCpp->at( i ) );
142 PyObject *tobj;
143
144 if ( ( tobj = sipConvertFromNewType( v, sipType_QgsFeatureStore, Py_None ) ) == NULL )
145 {
146 Py_DECREF( l );
147 delete v;
148
149 return NULL;
150 }
151
152 PyList_SET_ITEM( l, i, tobj );
153 }
154
155 return l;
156 % End
157
158 % ConvertToTypeCode
159 // Check the type if that is all that is required.
160 if ( sipIsErr == NULL )
161 {
162 if ( !PyList_Check( sipPy ) )
163 return 0;
164
165 for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
166 if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QgsFeatureStore, SIP_NOT_NONE ) )
167 return 0;
168
169 return 1;
170 }
171
173 SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
174 qv->reserve( listSize );
175
176 for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
177 {
178 PyObject *obj = PyList_GET_ITEM( sipPy, i );
179 int state;
180 QgsFeatureStore *t = reinterpret_cast<QgsFeatureStore *>( sipConvertToType( obj, sipType_QgsFeatureStore, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );
181
182 if ( *sipIsErr )
183 {
184 sipReleaseType( t, sipType_QgsFeatureStore, state );
185
186 delete qv;
187 return 0;
188 }
189
190 qv->append( *t );
191 sipReleaseType( t, sipType_QgsFeatureStore, state );
192 }
193
194 *sipCppPtr = qv;
195
196 return sipGetState( sipTransferObj );
197 % End
198};
199#endif
200
202
204
205#endif
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