QGIS API Documentation  2.17.0-Master (0497e4a)
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( renamedAttributes );
87  return false;
88 }
89 
91 {
92  Q_UNUSED( attr_map );
93  return false;
94 }
95 
97 {
98  Q_UNUSED( fieldId );
99  return QVariant();
100 }
101 
103 {
104  Q_UNUSED( geometry_map );
105  return false;
106 }
107 
109  const QgsGeometryMap &geometry_map )
110 {
111  Q_UNUSED( attr_map );
112  Q_UNUSED( geometry_map );
113  return false;
114 }
115 
117 {
118  return false;
119 }
120 
122 {
123  Q_UNUSED( field );
124  return true;
125 }
126 
128 {
130 }
131 
132 
134 {
136  if ( ncodec )
137  {
138  mEncoding = ncodec;
139  }
140  else
141  {
142  QgsMessageLog::logMessage( tr( "Codec %1 not found. Falling back to system locale" ).arg( e ) );
143  mEncoding = QTextCodec::codecForName( "System" );
144 
145  if ( !mEncoding )
147 
148  Q_ASSERT( mEncoding );
149  }
150 }
151 
153 {
154  if ( mEncoding )
155  {
156  return mEncoding->name();
157  }
158 
159  return "";
160 }
161 
163 {
164  QStringList abilitiesList;
165 
166  int abilities = capabilities();
167 
168  if ( abilities & QgsVectorDataProvider::AddFeatures )
169  {
170  abilitiesList += tr( "Add Features" );
171  QgsDebugMsg( "Capability: Add Features" );
172  }
173 
174  if ( abilities & QgsVectorDataProvider::DeleteFeatures )
175  {
176  abilitiesList += tr( "Delete Features" );
177  QgsDebugMsg( "Capability: Delete Features" );
178  }
179 
181  {
182  abilitiesList += tr( "Change Attribute Values" );
183  QgsDebugMsg( "Capability: Change Attribute Values" );
184  }
185 
186  if ( abilities & QgsVectorDataProvider::AddAttributes )
187  {
188  abilitiesList += tr( "Add Attributes" );
189  QgsDebugMsg( "Capability: Add Attributes" );
190  }
191 
192  if ( abilities & QgsVectorDataProvider::DeleteAttributes )
193  {
194  abilitiesList += tr( "Delete Attributes" );
195  QgsDebugMsg( "Capability: Delete Attributes" );
196  }
197 
198  if ( abilities & QgsVectorDataProvider::RenameAttributes )
199  {
200  abilitiesList += tr( "Rename Attributes" );
201  QgsDebugMsg( "Capability: Rename Attributes" );
202  }
203 
205  {
206  // TODO: Tighten up this test. See QgsOgrProvider for details.
207  abilitiesList += tr( "Create Spatial Index" );
208  QgsDebugMsg( "Capability: Create Spatial Index" );
209  }
210 
212  {
213  abilitiesList += tr( "Create Attribute Indexes" );
214  QgsDebugMsg( "Capability: Create Attribute Index" );
215  }
216 
217  if ( abilities & QgsVectorDataProvider::SelectAtId )
218  {
219  abilitiesList += tr( "Fast Access to Features at ID" );
220  QgsDebugMsg( "Capability: Select at ID" );
221  }
222 
223  if ( abilities & QgsVectorDataProvider::ChangeGeometries )
224  {
225  abilitiesList += tr( "Change Geometries" );
226  QgsDebugMsg( "Capability: Change Geometries" );
227  }
228 
230  {
231  abilitiesList += tr( "Presimplify Geometries" );
232  QgsDebugMsg( "Capability: Simplify Geometries before fetching the feature" );
233  }
234 
236  {
237  abilitiesList += tr( "Presimplify Geometries with Validity Check" );
238  QgsDebugMsg( "Capability: Simplify Geometries before fetch the feature ensuring that the result is a valid geometry" );
239  }
240 
241  if ( abilities & QgsVectorDataProvider::ChangeFeatures )
242  {
243  abilitiesList += tr( "Simultaneous Geometry and Attribute Updates" );
244  QgsDebugMsg( "Capability: change both feature attributes and geometry at once" );
245  }
246 
248  {
249  abilitiesList += tr( "Transactions" );
250  QgsDebugMsg( "Capability: transactions" );
251  }
252 
254  {
255  abilitiesList += tr( "Curved Geometries" );
256  QgsDebugMsg( "Supports circular geometry types (circularstring, compoundcurve, curvepolygon)" );
257  }
258 
259  return abilitiesList.join( ", " );
260 }
261 
262 
263 int QgsVectorDataProvider::fieldNameIndex( const QString& fieldName ) const
264 {
265  return fields().fieldNameIndex( fieldName );
266 }
267 
269 {
270  QMap<QString, int> resultMap;
271 
272  const QgsFields& theFields = fields();
273  for ( int i = 0; i < theFields.count(); ++i )
274  {
275  resultMap.insert( theFields[i].name(), i );
276  }
277 
278  return resultMap;
279 }
280 
282 {
283  return fields().allAttributesList();
284 }
285 
287 {
288  return mNativeTypes;
289 }
290 
292 {
293  int i;
294  QgsDebugMsgLevel( QString( "field name = %1 type = %2 length = %3 precision = %4" )
295  .arg( field.name(),
296  QVariant::typeToName( field.type() ) )
297  .arg( field.length() )
298  .arg( field.precision() ), 2 );
299  for ( i = 0; i < mNativeTypes.size(); i++ )
300  {
301  QgsDebugMsgLevel( QString( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
302  .arg( QVariant::typeToName( mNativeTypes[i].mType ) )
303  .arg( mNativeTypes[i].mMinLen )
304  .arg( mNativeTypes[i].mMaxLen )
305  .arg( mNativeTypes[i].mMinPrec )
306  .arg( mNativeTypes[i].mMaxPrec ), 2 );
307 
308  if ( field.type() != mNativeTypes[i].mType )
309  continue;
310 
311  if ( field.length() == -1 )
312  {
313  // source length unlimited
314  if ( mNativeTypes[i].mMinLen > -1 || mNativeTypes[i].mMaxLen > -1 )
315  {
316  // destination limited
317  continue;
318  }
319  }
320  else
321  {
322  // source length limited
323  if ( mNativeTypes[i].mMinLen > -1 && mNativeTypes[i].mMaxLen > -1 &&
324  ( field.length() < mNativeTypes[i].mMinLen || field.length() > mNativeTypes[i].mMaxLen ) )
325  {
326  // source length exceeds destination limits
327  continue;
328  }
329  }
330 
331  if ( field.precision() == -1 )
332  {
333  // source precision unlimited / n/a
334  if ( mNativeTypes[i].mMinPrec > -1 || mNativeTypes[i].mMaxPrec > -1 )
335  {
336  // destination limited
337  continue;
338  }
339  }
340  else
341  {
342  // source precision unlimited / n/a
343  if ( mNativeTypes[i].mMinPrec > -1 && mNativeTypes[i].mMaxPrec > -1 &&
344  ( field.precision() < mNativeTypes[i].mMinPrec || field.precision() > mNativeTypes[i].mMaxPrec ) )
345  {
346  // source precision exceeds destination limits
347  continue;
348  }
349  }
350 
351  QgsDebugMsg( "native type matches" );
352  return true;
353  }
354 
355  QgsDebugMsg( "no sufficient native type found" );
356  return false;
357 }
358 
360 {
361  if ( index < 0 || index >= fields().count() )
362  {
363  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
364  return QVariant();
365  }
366 
367  fillMinMaxCache();
368 
369  if ( !mCacheMinValues.contains( index ) )
370  return QVariant();
371 
372  return mCacheMinValues[index];
373 }
374 
376 {
377  if ( index < 0 || index >= fields().count() )
378  {
379  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
380  return QVariant();
381  }
382 
383  fillMinMaxCache();
384 
385  if ( !mCacheMaxValues.contains( index ) )
386  return QVariant();
387 
388  return mCacheMaxValues[index];
389 }
390 
392 {
393  QgsFeature f;
394  QgsAttributeList keys;
395  keys.append( index );
396  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys ).setFlags( QgsFeatureRequest::NoGeometry ) );
397 
398  QSet<QString> set;
399  values.clear();
400 
401  while ( fi.nextFeature( f ) )
402  {
403  if ( !set.contains( f.attribute( index ).toString() ) )
404  {
405  values.append( f.attribute( index ) );
406  set.insert( f.attribute( index ).toString() );
407  }
408 
409  if ( limit >= 0 && values.size() >= limit )
410  break;
411  }
412 }
413 
415  const QgsAggregateCalculator::AggregateParameters& parameters, QgsExpressionContext* context, bool& ok )
416 {
417  //base implementation does nothing
418  Q_UNUSED( aggregate );
419  Q_UNUSED( index );
420  Q_UNUSED( parameters );
421  Q_UNUSED( context );
422 
423  ok = false;
424  return QVariant();
425 }
426 
428 {
429  mCacheMinMaxDirty = true;
430 }
431 
433 {
434  if ( !mCacheMinMaxDirty )
435  return;
436 
437  const QgsFields& flds = fields();
438  for ( int i = 0; i < flds.count(); ++i )
439  {
440  if ( flds[i].type() == QVariant::Int )
441  {
442  mCacheMinValues[i] = QVariant( INT_MAX );
443  mCacheMaxValues[i] = QVariant( INT_MIN );
444  }
445  else if ( flds[i].type() == QVariant::LongLong )
446  {
449  }
450  else if ( flds[i].type() == QVariant::Double )
451  {
452  mCacheMinValues[i] = QVariant( DBL_MAX );
453  mCacheMaxValues[i] = QVariant( -DBL_MAX );
454  }
455  else
456  {
457  mCacheMinValues[i] = QVariant();
458  mCacheMaxValues[i] = QVariant();
459  }
460  }
461 
462  QgsFeature f;
464  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys )
465  .setFlags( QgsFeatureRequest::NoGeometry ) );
466 
467  while ( fi.nextFeature( f ) )
468  {
469  QgsAttributes attrs = f.attributes();
470  for ( QgsAttributeList::const_iterator it = keys.begin(); it != keys.end(); ++it )
471  {
472  const QVariant& varValue = attrs.at( *it );
473 
474  if ( varValue.isNull() )
475  continue;
476 
477  if ( flds[*it].type() == QVariant::Int )
478  {
479  int value = varValue.toInt();
480  if ( value < mCacheMinValues[*it].toInt() )
481  mCacheMinValues[*it] = value;
482  if ( value > mCacheMaxValues[*it].toInt() )
483  mCacheMaxValues[*it] = value;
484  }
485  else if ( flds[*it].type() == QVariant::LongLong )
486  {
487  qlonglong value = varValue.toLongLong();
488  if ( value < mCacheMinValues[*it].toLongLong() )
489  mCacheMinValues[*it] = value;
490  if ( value > mCacheMaxValues[*it].toLongLong() )
491  mCacheMaxValues[*it] = value;
492  }
493  else if ( flds[*it].type() == QVariant::Double )
494  {
495  double value = varValue.toDouble();
496  if ( value < mCacheMinValues[*it].toDouble() )
497  mCacheMinValues[*it] = value;
498  if ( value > mCacheMaxValues[*it].toDouble() )
499  mCacheMaxValues[*it] = value;
500  }
501  else
502  {
503  QString value = varValue.toString();
504  if ( mCacheMinValues[*it].isNull() || value < mCacheMinValues[*it].toString() )
505  {
506  mCacheMinValues[*it] = value;
507  }
508  if ( mCacheMaxValues[*it].isNull() || value > mCacheMaxValues[*it].toString() )
509  {
510  mCacheMaxValues[*it] = value;
511  }
512  }
513  }
514  }
515 
516  mCacheMinMaxDirty = false;
517 }
518 
519 QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString& value )
520 {
521  QVariant v( value );
522 
523  if ( !v.convert( type ) || value.isNull() )
524  v = QVariant( type );
525 
526  return v;
527 }
528 
529 static bool _compareEncodings( const QString& s1, const QString& s2 )
530 {
531  return s1.toLower() < s2.toLower();
532 }
533 
535 {
536  if ( smEncodings.isEmpty() )
537  {
538  Q_FOREACH ( const QString& codec, QTextCodec::availableCodecs() )
539  {
540  smEncodings << codec;
541  }
542 #if 0
543  smEncodings << "BIG5";
544  smEncodings << "BIG5-HKSCS";
545  smEncodings << "EUCJP";
546  smEncodings << "EUCKR";
547  smEncodings << "GB2312";
548  smEncodings << "GBK";
549  smEncodings << "GB18030";
550  smEncodings << "JIS7";
551  smEncodings << "SHIFT-JIS";
552  smEncodings << "TSCII";
553  smEncodings << "UTF-8";
554  smEncodings << "UTF-16";
555  smEncodings << "KOI8-R";
556  smEncodings << "KOI8-U";
557  smEncodings << "ISO8859-1";
558  smEncodings << "ISO8859-2";
559  smEncodings << "ISO8859-3";
560  smEncodings << "ISO8859-4";
561  smEncodings << "ISO8859-5";
562  smEncodings << "ISO8859-6";
563  smEncodings << "ISO8859-7";
564  smEncodings << "ISO8859-8";
565  smEncodings << "ISO8859-8-I";
566  smEncodings << "ISO8859-9";
567  smEncodings << "ISO8859-10";
568  smEncodings << "ISO8859-11";
569  smEncodings << "ISO8859-12";
570  smEncodings << "ISO8859-13";
571  smEncodings << "ISO8859-14";
572  smEncodings << "ISO8859-15";
573  smEncodings << "IBM 850";
574  smEncodings << "IBM 866";
575  smEncodings << "CP874";
576  smEncodings << "CP1250";
577  smEncodings << "CP1251";
578  smEncodings << "CP1252";
579  smEncodings << "CP1253";
580  smEncodings << "CP1254";
581  smEncodings << "CP1255";
582  smEncodings << "CP1256";
583  smEncodings << "CP1257";
584  smEncodings << "CP1258";
585  smEncodings << "Apple Roman";
586  smEncodings << "TIS-620";
587  smEncodings << "System";
588 #endif
589  }
590 
591  // Do case-insensitive sorting of encodings
592  qSort( smEncodings.begin(), smEncodings.end(), _compareEncodings );
593 
594  return smEncodings;
595 }
596 
598 {
599  mErrors.clear();
600 }
601 
603 {
604  return !mErrors.isEmpty();
605 }
606 
608 {
609  return mErrors;
610 }
611 
613 {
614  QgsDebugMsg( msg );
615  mErrors << msg;
616  emit raiseError( msg );
617 }
618 
620 {
621  return QSet<QString>();
622 }
623 
625 {
626  if ( !geom )
627  {
628  return nullptr;
629  }
630 
631  QgsAbstractGeometryV2* geometry = geom->geometry();
632  if ( !geometry )
633  {
634  return nullptr;
635  }
636 
637  QgsWKBTypes::Type providerGeomType = QGis::fromOldWkbType( geometryType() );
638 
639  //geom is already in the provider geometry type
640  if ( geometry->wkbType() == providerGeomType )
641  {
642  return nullptr;
643  }
644 
645  QgsAbstractGeometryV2* outputGeom = nullptr;
646 
647  //convert compoundcurve to circularstring (possible if compoundcurve consists of one circular string)
649  {
650  QgsCompoundCurveV2* compoundCurve = static_cast<QgsCompoundCurveV2*>( geometry );
651  if ( compoundCurve )
652  {
653  if ( compoundCurve->nCurves() == 1 )
654  {
655  const QgsCircularStringV2* circularString = dynamic_cast<const QgsCircularStringV2*>( compoundCurve->curveAt( 0 ) );
656  if ( circularString )
657  {
658  outputGeom = circularString->clone();
659  }
660  }
661  }
662  }
663 
664  //convert to multitype if necessary
665  if ( QgsWKBTypes::isMultiType( providerGeomType ) && !QgsWKBTypes::isMultiType( geometry->wkbType() ) )
666  {
667  outputGeom = QgsGeometryFactory::geomFromWkbType( providerGeomType );
668  QgsGeometryCollectionV2* geomCollection = dynamic_cast<QgsGeometryCollectionV2*>( outputGeom );
669  if ( geomCollection )
670  {
671  geomCollection->addGeometry( geometry->clone() );
672  }
673  }
674 
675  //convert to curved type if necessary
676  if ( !QgsWKBTypes::isCurvedType( geometry->wkbType() ) && QgsWKBTypes::isCurvedType( providerGeomType ) )
677  {
678  QgsAbstractGeometryV2* curveGeom = outputGeom ? outputGeom->toCurveType() : geometry->toCurveType();
679  if ( curveGeom )
680  {
681  delete outputGeom;
682  outputGeom = curveGeom;
683  }
684  }
685 
686  //convert to linear type from curved type
687  if ( QgsWKBTypes::isCurvedType( geometry->wkbType() ) && !QgsWKBTypes::isCurvedType( providerGeomType ) )
688  {
689  QgsAbstractGeometryV2* segmentizedGeom = nullptr;
690  segmentizedGeom = outputGeom ? outputGeom->segmentize() : geometry->segmentize();
691  if ( segmentizedGeom )
692  {
693  delete outputGeom;
694  outputGeom = segmentizedGeom;
695  }
696  }
697 
698  //set z/m types
699  if ( QgsWKBTypes::hasZ( providerGeomType ) )
700  {
701  if ( !outputGeom )
702  {
703  outputGeom = geometry->clone();
704  }
705  outputGeom->addZValue();
706  }
707  if ( QgsWKBTypes::hasM( providerGeomType ) )
708  {
709  if ( !outputGeom )
710  {
711  outputGeom = geometry->clone();
712  }
713  outputGeom->addMValue();
714  }
715 
716  if ( outputGeom )
717  {
718  return new QgsGeometry( outputGeom );
719  }
720  return nullptr;
721 }
722 
723 QStringList QgsVectorDataProvider::smEncodings;
qlonglong toLongLong(bool *ok) const
void clear()
QString encoding() const
Get encoding which is used for accessing data.
Wrapper for iterator of features from vector data provider or vector layer.
static unsigned index
static QVariant convertValue(QVariant::Type type, const QString &value)
QgsAttributes attributes() const
Returns the feature&#39;s attributes.
Definition: qgsfeature.cpp:110
QMap< QString, int > fieldNameMap() const
Return a map where the key is the name of the field and the value is its index.
bool contains(const Key &key) const
QString name
Definition: qgsfield.h:52
virtual QByteArray name() const=0
int precision
Definition: qgsfield.h:50
static bool _compareEncodings(const QString &s1, const QString &s2)
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
Definition: qgswkbtypes.h:714
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
Circular string geometry type.
Supports simplification of geometries on provider side according to a distance tolerance.
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.
virtual bool renameAttributes(const QgsFieldNameMap &renamedAttributes)
Renames existing attributes.
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
Definition: qgswkbtypes.h:487
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:252
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
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
Definition: qgswkbtypes.h:667
virtual bool addFeatures(QgsFeatureList &flist)
Adds a list of features.
int count() const
Return number of items.
Definition: qgsfield.cpp:402
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
virtual QgsAbstractGeometryV2 * toCurveType() const
Returns the geometry converted to the more generic curve type.
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.
bool supportedType(const QgsField &field) const
check if provider supports type of field
int length
Definition: qgsfield.h:49
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
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.
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
Definition: qgsfield.cpp:588
int toInt(bool *ok) const
bool isNull() const
Allows addition of new attributes (fields)
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:34
static bool isCurvedType(Type type)
Returns true if the WKB type is a curved type or can contain curved geometries.
Definition: qgswkbtypes.h:531
bool hasErrors()
Provider has errors to report.
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
virtual QgsAbstractGeometryV2 * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
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)
virtual QSet< QString > layerDependencies() const
Get the list of layer ids on which this layer depends.
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.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
Allows modifications of geometries.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Query the provider for features specified in request.
void clearErrors()
Clear recorded errors.
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
const QList< NativeType > & nativeTypes() const
Returns the names of the supported types.
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.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
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.
Supports circular geometry types (circularstring, compoundcurve, curvepolygon)
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:571
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...
QString capabilitiesString() const
Returns the above in friendly format.
const char * typeToName(Type typ)
const T & at(int i) const
QVariant value(const QString &key, const QVariant &defaultValue) const
QList< QByteArray > availableCodecs()
const QgsCurveV2 * curveAt(int i) const
Returns the curve at the specified index.
virtual const QgsFields & fields() const =0
Return a map of indexes with field names for this layer.
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
virtual QVariant defaultValue(int fieldId)
Returns the default value for field specified by fieldId.
QgsGeometry * convertToProviderType(const QgsGeometry *geom) const
Converts the geometry to the provider type if possible / necessary.
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
virtual QVariant minimumValue(int index)
Returns the minimum value of an attribute.
QTextCodec * codecForName(const QByteArray &name)
virtual QString dataComment() const
Return a short comment for the data that this provider is providing access to (e.g.
virtual bool addGeometry(QgsAbstractGeometryV2 *g)
Adds a geometry and takes ownership.
virtual ~QgsVectorDataProvider()
Destructor.
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes.
int nCurves() const
Returns the number of curves in the geometry.
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)
virtual QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
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.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
A vector of attributes.
Definition: qgsfeature.h:115
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
Definition: qgsfield.cpp:97
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:271
bool convert(Type t)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString toString() const
iterator begin()
Allows modification of attribute values.
bool isNull(const QVariant &v)
Aggregate
Available aggregates to calculate.
QMap< int, QVariant > mCacheMinValues
Supports renaming attributes (fields).
A bundle of parameters controlling aggregate calculation.