QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 // clang-format off
77
81 int __len__() const;
82 % MethodCode
83 sipRes = sipCpp->count();
84 % End
85
87 int __bool__() const;
88 % MethodCode
89 sipRes = true;
90 % End
91// clang-format on
92#endif
93
98 {
99 return mFeatures;
100 }
101
106 void setParams( const QMap<QString, QVariant> &parameters ) { mParams = parameters; }
107
112 QMap<QString, QVariant> params() const { return mParams; }
113
114 private:
115 QgsFields mFields;
116
118
119 QgsFeatureList mFeatures;
120
121 // Optional parameters
122 QMap<QString, QVariant> mParams;
123};
124
125#ifndef SIP_RUN
126typedef QVector<QgsFeatureStore> QgsFeatureStoreList;
127#else
128// clang-format off
129typedef QVector<QgsFeatureStore> QgsFeatureStoreList;
130
131% MappedType QgsFeatureStoreList
132{
133 % TypeHeaderCode
134#include "qgsfeaturestore.h"
135 % End
136
137 % ConvertFromTypeCode
138 // Create the list.
139 PyObject *l;
140
141 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
142 return NULL;
143
144 // Set the list elements.
145 for ( int i = 0; i < sipCpp->size(); ++i )
146 {
147 QgsFeatureStore *v = new QgsFeatureStore( sipCpp->at( i ) );
148 PyObject *tobj;
149
150 if ( ( tobj = sipConvertFromNewType( v, sipType_QgsFeatureStore, Py_None ) ) == NULL )
151 {
152 Py_DECREF( l );
153 delete v;
154
155 return NULL;
156 }
157
158 PyList_SET_ITEM( l, i, tobj );
159 }
160
161 return l;
162 % End
163
164 % ConvertToTypeCode
165 // Check the type if that is all that is required.
166 if ( sipIsErr == NULL )
167 {
168 if ( !PyList_Check( sipPy ) )
169 return 0;
170
171 for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
172 if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QgsFeatureStore, SIP_NOT_NONE ) )
173 return 0;
174
175 return 1;
176 }
177
179 SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
180 qv->reserve( listSize );
181
182 for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
183 {
184 PyObject *obj = PyList_GET_ITEM( sipPy, i );
185 int state;
186 QgsFeatureStore *t = reinterpret_cast<QgsFeatureStore *>( sipConvertToType( obj, sipType_QgsFeatureStore, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );
187
188 if ( *sipIsErr )
189 {
190 sipReleaseType( t, sipType_QgsFeatureStore, state );
191
192 delete qv;
193 return 0;
194 }
195
196 qv->append( *t );
197 sipReleaseType( t, sipType_QgsFeatureStore, state );
198 }
199
200 *sipCppPtr = qv;
201
202 return sipGetState( sipTransferObj );
203 % End
204};
205// clang-format on
206#endif
207
209
211
212#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:60
Container of fields for a vector layer.
Definition qgsfields.h:46
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QList< QgsFeature > QgsFeatureList
QVector< QgsFeatureStore > QgsFeatureStoreList