QGIS API Documentation  2.15.0-Master (af20121)
qgsvectordataprovider.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectordataprovider.cpp - DataProvider Interface for vector layers
3  --------------------------------------
4  Date : 26-Oct-2004
5  Copyright : (C) 2004 by Marco Hugentobler
6  email : [email protected]
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 #include <QSettings>
17 #include <QTextCodec>
18 
19 #include <cfloat> // for DBL_MAX
20 #include <climits>
21 #include <limits>
22 
23 #include "qgsvectordataprovider.h"
24 #include "qgscircularstringv2.h"
25 #include "qgscompoundcurvev2.h"
26 #include "qgsfeature.h"
27 #include "qgsfeatureiterator.h"
28 #include "qgsfeaturerequest.h"
29 #include "qgsfield.h"
30 #include "qgsgeometry.h"
32 #include "qgsgeometryfactory.h"
33 #include "qgslogger.h"
34 #include "qgsmessagelog.h"
35 
37  : QgsDataProvider( uri )
38  , mCacheMinMaxDirty( true )
39  , mAttrPalIndexName( QgsAttrPalIndexNameHash() )
40 {
41  QSettings settings;
42  setEncoding( settings.value( "/UI/encoding", "System" ).toString() );
43 }
44 
45 
47 {
48 }
49 
51 {
52  return "Generic vector file";
53 }
54 
56 {
57  return QString();
58 }
59 
61 {
62  Q_UNUSED( flist );
63  return false;
64 }
65 
67 {
68  Q_UNUSED( ids );
69  return false;
70 }
71 
73 {
74  Q_UNUSED( attributes );
75  return false;
76 }
77 
79 {
80  Q_UNUSED( attributes );
81  return false;
82 }
83 
85 {
86  Q_UNUSED( attr_map );
87  return false;
88 }
89 
91 {
92  Q_UNUSED( fieldId );
93  return QVariant();
94 }
95 
97 {
98  Q_UNUSED( geometry_map );
99  return false;
100 }
101 
103  const QgsGeometryMap &geometry_map )
104 {
105  Q_UNUSED( attr_map );
106  Q_UNUSED( geometry_map );
107  return false;
108 }
109 
111 {
112  return false;
113 }
114 
116 {
117  Q_UNUSED( field );
118  return true;
119 }
120 
122 {
124 }
125 
126 
128 {
130  if ( ncodec )
131  {
132  mEncoding = ncodec;
133  }
134  else
135  {
136  QgsMessageLog::logMessage( tr( "Codec %1 not found. Falling back to system locale" ).arg( e ) );
137  mEncoding = QTextCodec::codecForName( "System" );
138 
139  if ( !mEncoding )
141 
142  Q_ASSERT( mEncoding );
143  }
144 }
145 
147 {
148  if ( mEncoding )
149  {
150  return mEncoding->name();
151  }
152 
153  return "";
154 }
155 
157 {
158  QStringList abilitiesList;
159 
160  int abilities = capabilities();
161 
162  if ( abilities & QgsVectorDataProvider::AddFeatures )
163  {
164  abilitiesList += tr( "Add Features" );
165  QgsDebugMsg( "Capability: Add Features" );
166  }
167 
168  if ( abilities & QgsVectorDataProvider::DeleteFeatures )
169  {
170  abilitiesList += tr( "Delete Features" );
171  QgsDebugMsg( "Capability: Delete Features" );
172  }
173 
175  {
176  abilitiesList += tr( "Change Attribute Values" );
177  QgsDebugMsg( "Capability: Change Attribute Values" );
178  }
179 
180  if ( abilities & QgsVectorDataProvider::AddAttributes )
181  {
182  abilitiesList += tr( "Add Attributes" );
183  QgsDebugMsg( "Capability: Add Attributes" );
184  }
185 
186  if ( abilities & QgsVectorDataProvider::DeleteAttributes )
187  {
188  abilitiesList += tr( "Delete Attributes" );
189  QgsDebugMsg( "Capability: Delete Attributes" );
190  }
191 
193  {
194  // TODO: Tighten up this test. See QgsOgrProvider for details.
195  abilitiesList += tr( "Create Spatial Index" );
196  QgsDebugMsg( "Capability: Create Spatial Index" );
197  }
198 
199  if ( abilities & QgsVectorDataProvider::SelectAtId )
200  {
201  abilitiesList += tr( "Fast Access to Features at ID" );
202  QgsDebugMsg( "Capability: Select at ID" );
203  }
204 
205  if ( abilities & QgsVectorDataProvider::ChangeGeometries )
206  {
207  abilitiesList += tr( "Change Geometries" );
208  QgsDebugMsg( "Capability: Change Geometries" );
209  }
210 
212  {
213  abilitiesList += tr( "Presimplify Geometries" );
214  QgsDebugMsg( "Capability: Simplify Geometries before fetching the feature" );
215  }
216 
218  {
219  abilitiesList += tr( "Presimplify Geometries with Validity Check" );
220  QgsDebugMsg( "Capability: Simplify Geometries before fetch the feature ensuring that the result is a valid geometry" );
221  }
222 
223  if ( abilities & QgsVectorDataProvider::ChangeFeatures )
224  {
225  abilitiesList += tr( "Simultaneous Geometry and Attribute Updates" );
226  QgsDebugMsg( "Capability: change both feature attributes and geometry at once" );
227  }
228 
229  return abilitiesList.join( ", " );
230 }
231 
232 
233 int QgsVectorDataProvider::fieldNameIndex( const QString& fieldName ) const
234 {
235  return fields().fieldNameIndex( fieldName );
236 }
237 
239 {
240  QMap<QString, int> resultMap;
241 
242  const QgsFields& theFields = fields();
243  for ( int i = 0; i < theFields.count(); ++i )
244  {
245  resultMap.insert( theFields[i].name(), i );
246  }
247 
248  return resultMap;
249 }
250 
252 {
253  return fields().allAttributesList();
254 }
255 
257 {
258  return mNativeTypes;
259 }
260 
262 {
263  int i;
264  QgsDebugMsgLevel( QString( "field name = %1 type = %2 length = %3 precision = %4" )
265  .arg( field.name(),
266  QVariant::typeToName( field.type() ) )
267  .arg( field.length() )
268  .arg( field.precision() ), 2 );
269  for ( i = 0; i < mNativeTypes.size(); i++ )
270  {
271  QgsDebugMsgLevel( QString( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
272  .arg( QVariant::typeToName( mNativeTypes[i].mType ) )
273  .arg( mNativeTypes[i].mMinLen )
274  .arg( mNativeTypes[i].mMaxLen )
275  .arg( mNativeTypes[i].mMinPrec )
276  .arg( mNativeTypes[i].mMaxPrec ), 2 );
277 
278  if ( field.type() != mNativeTypes[i].mType )
279  continue;
280 
281  if ( field.length() == -1 )
282  {
283  // source length unlimited
284  if ( mNativeTypes[i].mMinLen > -1 || mNativeTypes[i].mMaxLen > -1 )
285  {
286  // destination limited
287  continue;
288  }
289  }
290  else
291  {
292  // source length limited
293  if ( mNativeTypes[i].mMinLen > -1 && mNativeTypes[i].mMaxLen > -1 &&
294  ( field.length() < mNativeTypes[i].mMinLen || field.length() > mNativeTypes[i].mMaxLen ) )
295  {
296  // source length exceeds destination limits
297  continue;
298  }
299  }
300 
301  if ( field.precision() == -1 )
302  {
303  // source precision unlimited / n/a
304  if ( mNativeTypes[i].mMinPrec > -1 || mNativeTypes[i].mMaxPrec > -1 )
305  {
306  // destination limited
307  continue;
308  }
309  }
310  else
311  {
312  // source precision unlimited / n/a
313  if ( mNativeTypes[i].mMinPrec > -1 && mNativeTypes[i].mMaxPrec > -1 &&
314  ( field.precision() < mNativeTypes[i].mMinPrec || field.precision() > mNativeTypes[i].mMaxPrec ) )
315  {
316  // source precision exceeds destination limits
317  continue;
318  }
319  }
320 
321  QgsDebugMsg( "native type matches" );
322  return true;
323  }
324 
325  QgsDebugMsg( "no sufficient native type found" );
326  return false;
327 }
328 
330 {
331  if ( index < 0 || index >= fields().count() )
332  {
333  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
334  return QVariant();
335  }
336 
337  fillMinMaxCache();
338 
339  if ( !mCacheMinValues.contains( index ) )
340  return QVariant();
341 
342  return mCacheMinValues[index];
343 }
344 
346 {
347  if ( index < 0 || index >= fields().count() )
348  {
349  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
350  return QVariant();
351  }
352 
353  fillMinMaxCache();
354 
355  if ( !mCacheMaxValues.contains( index ) )
356  return QVariant();
357 
358  return mCacheMaxValues[index];
359 }
360 
362 {
363  QgsFeature f;
364  QgsAttributeList keys;
365  keys.append( index );
366  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys ) );
367 
368  QSet<QString> set;
369  values.clear();
370 
371  while ( fi.nextFeature( f ) )
372  {
373  if ( !set.contains( f.attribute( index ).toString() ) )
374  {
375  values.append( f.attribute( index ) );
376  set.insert( f.attribute( index ).toString() );
377  }
378 
379  if ( limit >= 0 && values.size() >= limit )
380  break;
381  }
382 }
383 
385  const QgsAggregateCalculator::AggregateParameters& parameters, QgsExpressionContext* context, bool& ok )
386 {
387  //base implementation does nothing
388  Q_UNUSED( aggregate );
389  Q_UNUSED( index );
390  Q_UNUSED( parameters );
391  Q_UNUSED( context );
392 
393  ok = false;
394  return QVariant();
395 }
396 
398 {
399  mCacheMinMaxDirty = true;
400 }
401 
403 {
404  if ( !mCacheMinMaxDirty )
405  return;
406 
407  const QgsFields& flds = fields();
408  for ( int i = 0; i < flds.count(); ++i )
409  {
410  if ( flds[i].type() == QVariant::Int )
411  {
412  mCacheMinValues[i] = QVariant( INT_MAX );
413  mCacheMaxValues[i] = QVariant( INT_MIN );
414  }
415  else if ( flds[i].type() == QVariant::LongLong )
416  {
419  }
420  else if ( flds[i].type() == QVariant::Double )
421  {
422  mCacheMinValues[i] = QVariant( DBL_MAX );
423  mCacheMaxValues[i] = QVariant( -DBL_MAX );
424  }
425  else
426  {
427  mCacheMinValues[i] = QVariant();
428  mCacheMaxValues[i] = QVariant();
429  }
430  }
431 
432  QgsFeature f;
434  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys ) );
435 
436  while ( fi.nextFeature( f ) )
437  {
438  QgsAttributes attrs = f.attributes();
439  for ( QgsAttributeList::const_iterator it = keys.begin(); it != keys.end(); ++it )
440  {
441  const QVariant& varValue = attrs.at( *it );
442 
443  if ( varValue.isNull() )
444  continue;
445 
446  if ( flds[*it].type() == QVariant::Int )
447  {
448  int value = varValue.toInt();
449  if ( value < mCacheMinValues[*it].toInt() )
450  mCacheMinValues[*it] = value;
451  if ( value > mCacheMaxValues[*it].toInt() )
452  mCacheMaxValues[*it] = value;
453  }
454  else if ( flds[*it].type() == QVariant::LongLong )
455  {
456  qlonglong value = varValue.toLongLong();
457  if ( value < mCacheMinValues[*it].toLongLong() )
458  mCacheMinValues[*it] = value;
459  if ( value > mCacheMaxValues[*it].toLongLong() )
460  mCacheMaxValues[*it] = value;
461  }
462  else if ( flds[*it].type() == QVariant::Double )
463  {
464  double value = varValue.toDouble();
465  if ( value < mCacheMinValues[*it].toDouble() )
466  mCacheMinValues[*it] = value;
467  if ( value > mCacheMaxValues[*it].toDouble() )
468  mCacheMaxValues[*it] = value;
469  }
470  else
471  {
472  QString value = varValue.toString();
473  if ( mCacheMinValues[*it].isNull() || value < mCacheMinValues[*it].toString() )
474  {
475  mCacheMinValues[*it] = value;
476  }
477  if ( mCacheMaxValues[*it].isNull() || value > mCacheMaxValues[*it].toString() )
478  {
479  mCacheMaxValues[*it] = value;
480  }
481  }
482  }
483  }
484 
485  mCacheMinMaxDirty = false;
486 }
487 
488 QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString& value )
489 {
490  QVariant v( value );
491 
492  if ( !v.convert( type ) || value.isNull() )
493  v = QVariant( type );
494 
495  return v;
496 }
497 
498 static bool _compareEncodings( const QString& s1, const QString& s2 )
499 {
500  return s1.toLower() < s2.toLower();
501 }
502 
504 {
505  if ( smEncodings.isEmpty() )
506  {
507  Q_FOREACH ( const QString& codec, QTextCodec::availableCodecs() )
508  {
509  smEncodings << codec;
510  }
511 #if 0
512  smEncodings << "BIG5";
513  smEncodings << "BIG5-HKSCS";
514  smEncodings << "EUCJP";
515  smEncodings << "EUCKR";
516  smEncodings << "GB2312";
517  smEncodings << "GBK";
518  smEncodings << "GB18030";
519  smEncodings << "JIS7";
520  smEncodings << "SHIFT-JIS";
521  smEncodings << "TSCII";
522  smEncodings << "UTF-8";
523  smEncodings << "UTF-16";
524  smEncodings << "KOI8-R";
525  smEncodings << "KOI8-U";
526  smEncodings << "ISO8859-1";
527  smEncodings << "ISO8859-2";
528  smEncodings << "ISO8859-3";
529  smEncodings << "ISO8859-4";
530  smEncodings << "ISO8859-5";
531  smEncodings << "ISO8859-6";
532  smEncodings << "ISO8859-7";
533  smEncodings << "ISO8859-8";
534  smEncodings << "ISO8859-8-I";
535  smEncodings << "ISO8859-9";
536  smEncodings << "ISO8859-10";
537  smEncodings << "ISO8859-11";
538  smEncodings << "ISO8859-12";
539  smEncodings << "ISO8859-13";
540  smEncodings << "ISO8859-14";
541  smEncodings << "ISO8859-15";
542  smEncodings << "IBM 850";
543  smEncodings << "IBM 866";
544  smEncodings << "CP874";
545  smEncodings << "CP1250";
546  smEncodings << "CP1251";
547  smEncodings << "CP1252";
548  smEncodings << "CP1253";
549  smEncodings << "CP1254";
550  smEncodings << "CP1255";
551  smEncodings << "CP1256";
552  smEncodings << "CP1257";
553  smEncodings << "CP1258";
554  smEncodings << "Apple Roman";
555  smEncodings << "TIS-620";
556  smEncodings << "System";
557 #endif
558  }
559 
560  // Do case-insensitive sorting of encodings
561  qSort( smEncodings.begin(), smEncodings.end(), _compareEncodings );
562 
563  return smEncodings;
564 }
565 
567 {
568  mErrors.clear();
569 }
570 
572 {
573  return !mErrors.isEmpty();
574 }
575 
577 {
578  return mErrors;
579 }
580 
582 {
583  QgsDebugMsg( msg );
584  mErrors << msg;
585  emit raiseError( msg );
586 }
587 
589 {
590  return QSet<QString>();
591 }
592 
594 {
595  if ( !geom )
596  {
597  return nullptr;
598  }
599 
600  QgsAbstractGeometryV2* geometry = geom->geometry();
601  if ( !geometry )
602  {
603  return nullptr;
604  }
605 
606  QgsWKBTypes::Type providerGeomType = QGis::fromOldWkbType( geometryType() );
607 
608  //geom is already in the provider geometry type
609  if ( geometry->wkbType() == providerGeomType )
610  {
611  return nullptr;
612  }
613 
614  QgsAbstractGeometryV2* outputGeom = nullptr;
615 
616  //convert compoundcurve to circularstring (possible if compoundcurve consists of one circular string)
618  {
619  QgsCompoundCurveV2* compoundCurve = static_cast<QgsCompoundCurveV2*>( geometry );
620  if ( compoundCurve )
621  {
622  if ( compoundCurve->nCurves() == 1 )
623  {
624  const QgsCircularStringV2* circularString = dynamic_cast<const QgsCircularStringV2*>( compoundCurve->curveAt( 0 ) );
625  if ( circularString )
626  {
627  outputGeom = circularString->clone();
628  }
629  }
630  }
631  }
632 
633  //convert to multitype if necessary
634  if ( QgsWKBTypes::isMultiType( providerGeomType ) && !QgsWKBTypes::isMultiType( geometry->wkbType() ) )
635  {
636  outputGeom = QgsGeometryFactory::geomFromWkbType( providerGeomType );
637  QgsGeometryCollectionV2* geomCollection = dynamic_cast<QgsGeometryCollectionV2*>( outputGeom );
638  if ( geomCollection )
639  {
640  geomCollection->addGeometry( geometry->clone() );
641  }
642  }
643 
644  //convert to curved type if necessary
645  if ( !QgsWKBTypes::isCurvedType( geometry->wkbType() ) && QgsWKBTypes::isCurvedType( providerGeomType ) )
646  {
647  QgsAbstractGeometryV2* curveGeom = outputGeom ? outputGeom->toCurveType() : geometry->toCurveType();
648  if ( curveGeom )
649  {
650  delete outputGeom;
651  outputGeom = curveGeom;
652  }
653  }
654 
655  //convert to linear type from curved type
656  if ( QgsWKBTypes::isCurvedType( geometry->wkbType() ) && !QgsWKBTypes::isCurvedType( providerGeomType ) )
657  {
658  QgsAbstractGeometryV2* segmentizedGeom = nullptr;
659  segmentizedGeom = outputGeom ? outputGeom->segmentize() : geometry->segmentize();
660  if ( segmentizedGeom )
661  {
662  delete outputGeom;
663  outputGeom = segmentizedGeom;
664  }
665  }
666 
667  //set z/m types
668  if ( QgsWKBTypes::hasZ( providerGeomType ) )
669  {
670  if ( !outputGeom )
671  {
672  outputGeom = geometry->clone();
673  }
674  outputGeom->addZValue();
675  }
676  if ( QgsWKBTypes::hasM( providerGeomType ) )
677  {
678  if ( !outputGeom )
679  {
680  outputGeom = geometry->clone();
681  }
682  outputGeom->addMValue();
683  }
684 
685  if ( outputGeom )
686  {
687  return new QgsGeometry( outputGeom );
688  }
689  return nullptr;
690 }
691 
692 QStringList QgsVectorDataProvider::smEncodings;
virtual QSet< QString > layerDependencies() const
Get the list of layer ids on which this layer depends.
qlonglong toLongLong(bool *ok) const
void clear()
Wrapper for iterator of features from vector data provider or vector layer.
static unsigned index
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
static QVariant convertValue(QVariant::Type type, const QString &value)
bool contains(const Key &key) const
virtual QByteArray name() const =0
static bool _compareEncodings(const QString &s1, const QString &s2)
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes.
QString capabilitiesString() const
Returns the above in friendly format.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
Definition: qgswkbtypes.h:703
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
QgsGeometry * convertToProviderType(const QgsGeometry *geom) const
Converts the geometry to the provider type if possible / necessary.
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
Circular string geometry type.
Supports simplification of geometries on provider side according to a distance tolerance.
int fieldNameIndex(const QString &fieldName) const
Look up field&#39;s index from name also looks up case-insensitive if there is no match otherwise...
Definition: qgsfield.cpp:534
virtual QgsAttributeList attributeIndexes()
Return list of indexes to fetch all attributes in nextFeature()
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features.
virtual void setEncoding(const QString &e)
Set encoding used for accessing data from layer.
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
Definition: qgswkbtypes.h:476
int precision() const
Gets the precision of the field.
Definition: qgsfield.cpp:104
Abstract base class for all geometries.
virtual void uniqueValues(int index, QList< QVariant > &uniqueValues, int limit=-1)
Return unique values of an attribute.
Container of fields for a vector layer.
Definition: qgsfield.h:193
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
QStringList errors()
Get recorded errors.
QMap< int, QVariant > mCacheMaxValues
Abstract base class for spatial data provider implementations.
Allows deletion of attributes (fields)
QString join(const QString &separator) const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
Definition: qgswkbtypes.h:656
virtual bool addFeatures(QgsFeatureList &flist)
Adds a list of features.
QString tr(const char *sourceText, const char *disambiguation, int n)
QTextCodec * codecForLocale()
virtual QString name() const =0
Return a provider name.
virtual bool createAttributeIndex(int field)
Create an attribute index on the datasource.
int size() const
bool isNull() const
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
static const QStringList & availableEncodings()
Returns a list of available encodings.
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
QList< Key > keys() const
Allows creation of spatial index.
static QgsWKBTypes::Type fromOldWkbType(QGis::WkbType type)
Converts from old (pre 2.10) WKB type (OGR) to new WKB type.
Definition: qgis.cpp:106
QString encoding() const
Get encoding which is used for accessing data.
virtual QVariant maximumValue(int index)
Returns the maximum value of an attribute.
virtual bool createSpatialIndex()
Creates a spatial index on the datasource (if supported by the provider type).
QString number(int n, int base)
void append(const T &value)
QTextCodec * mEncoding
Encoding.
bool supportedType(const QgsField &field) const
check if provider supports type of field
int toInt(bool *ok) const
bool isNull() const
Allows addition of new attributes (fields)
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:34
virtual QString dataComment() const
Return a short comment for the data that this provider is providing access to (e.g.
static bool isCurvedType(Type type)
Returns true if the WKB type is a curved type or can contain curved geometries.
Definition: qgswkbtypes.h:520
QgsAttributes attributes() const
Returns the feature&#39;s attributes.
Definition: qgsfeature.cpp:110
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
bool hasErrors()
Provider has errors to report.
QString name() const
Gets the name of the field.
Definition: qgsfield.cpp:84
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
bool isEmpty() const
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual bool changeFeatures(const QgsChangedAttributesMap &attr_map, const QgsGeometryMap &geometry_map)
Changes attribute values and geometries of existing features.
const char * constData() const
const QList< NativeType > & nativeTypes() const
Returns the names of the supported types.
virtual QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
This class wraps a request for features to a vector layer (or directly its vector data provider)...
virtual QVariant aggregate(QgsAggregateCalculator::Aggregate aggregate, int index, const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok)
Calculates an aggregated value from the layer&#39;s features.
QList< NativeType > mNativeTypes
The names of the providers native types.
Allows modifications of geometries.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Query the provider for features specified in request.
const QgsCurveV2 * curveAt(int i) const
Returns the curve at the specified index.
void clearErrors()
Clear recorded errors.
int count() const
Return number of items.
Definition: qgsfield.cpp:365
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
virtual QGis::WkbType geometryType() const =0
Get feature type.
Fast access to features using their ID.
virtual bool changeGeometryValues(const QgsGeometryMap &geometry_map)
Changes geometries of existing features.
QMap< QString, int > fieldNameMap() const
Return a map where the key is the name of the field and the value is its index.
static QgsAbstractGeometryV2 * geomFromWkbType(QgsWKBTypes::Type t)
Return empty geometry from wkb type.
Compound curve geometry type.
QgsVectorDataProvider(const QString &uri=QString())
Constructor of the vector provider.
iterator end()
QString toLower() const
QByteArray toLocal8Bit() const
void raiseError(const QString &msg)
Signals an error in this provider.
virtual QgsCircularStringV2 * clone() const override
Clones the geometry by performing a deep copy.
Supports joint updates for attributes and geometry Providers supporting this should still define Chan...
Supports topological simplification of geometries on provider side according to a distance tolerance...
const char * typeToName(Type typ)
const T & at(int i) const
QVariant value(const QString &key, const QVariant &defaultValue) const
QList< QByteArray > availableCodecs()
virtual const QgsFields & fields() const =0
Return a map of indexes with field names for this layer.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:271
virtual QVariant defaultValue(int fieldId)
Returns the default value for field specified by fieldId.
virtual QVariant minimumValue(int index)
Returns the minimum value of an attribute.
QTextCodec * codecForName(const QByteArray &name)
virtual bool addGeometry(QgsAbstractGeometryV2 *g)
Adds a geometry and takes ownership.
int length() const
Gets the length of the field.
Definition: qgsfield.cpp:99
virtual ~QgsVectorDataProvider()
Destructor.
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:366
double toDouble(bool *ok) const
iterator insert(const Key &key, const T &value)
void pushError(const QString &msg)
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
bool nextFeature(QgsFeature &f)
Provider has no capabilities.
virtual QgsAbstractGeometryV2 * clone() const =0
Clones the geometry by performing a deep copy.
A vector of attributes.
Definition: qgsfeature.h:115
bool convert(Type t)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString toString() const
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
Definition: qgsfield.cpp:551
int nCurves() const
Returns the number of curves in the geometry.
iterator begin()
Allows modification of attribute values.
bool isNull(const QVariant &v)
virtual QgsAbstractGeometryV2 * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
Aggregate
Available aggregates to calculate.
QMap< int, QVariant > mCacheMinValues
virtual QgsAbstractGeometryV2 * toCurveType() const
Returns the geometry converted to the more generic curve type.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
Definition: qgsfield.cpp:89
A bundle of parameters controlling aggregate calculation.