QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
96 QVariant QgsVectorDataProvider::defaultValue( int fieldId, bool forceLazyEval )
97 {
98  Q_UNUSED( forceLazyEval )
99  Q_UNUSED( fieldId );
100  return QVariant();
101 }
102 
104 {
105  Q_UNUSED( geometry_map );
106  return false;
107 }
108 
110  const QgsGeometryMap &geometry_map )
111 {
112  Q_UNUSED( attr_map );
113  Q_UNUSED( geometry_map );
114  return false;
115 }
116 
118 {
119  return false;
120 }
121 
123 {
124  Q_UNUSED( field );
125  return true;
126 }
127 
129 {
131 }
132 
133 
135 {
137  if ( ncodec )
138  {
139  mEncoding = ncodec;
140  }
141  else
142  {
143  QgsMessageLog::logMessage( tr( "Codec %1 not found. Falling back to system locale" ).arg( e ) );
144  mEncoding = QTextCodec::codecForName( "System" );
145 
146  if ( !mEncoding )
148 
149  Q_ASSERT( mEncoding );
150  }
151 }
152 
154 {
155  if ( mEncoding )
156  {
157  return mEncoding->name();
158  }
159 
160  return "";
161 }
162 
164 {
165  QStringList abilitiesList;
166 
167  int abilities = capabilities();
168 
169  if ( abilities & QgsVectorDataProvider::AddFeatures )
170  {
171  abilitiesList += tr( "Add Features" );
172  QgsDebugMsg( "Capability: Add Features" );
173  }
174 
175  if ( abilities & QgsVectorDataProvider::DeleteFeatures )
176  {
177  abilitiesList += tr( "Delete Features" );
178  QgsDebugMsg( "Capability: Delete Features" );
179  }
180 
182  {
183  abilitiesList += tr( "Change Attribute Values" );
184  QgsDebugMsg( "Capability: Change Attribute Values" );
185  }
186 
187  if ( abilities & QgsVectorDataProvider::AddAttributes )
188  {
189  abilitiesList += tr( "Add Attributes" );
190  QgsDebugMsg( "Capability: Add Attributes" );
191  }
192 
193  if ( abilities & QgsVectorDataProvider::DeleteAttributes )
194  {
195  abilitiesList += tr( "Delete Attributes" );
196  QgsDebugMsg( "Capability: Delete Attributes" );
197  }
198 
199  if ( abilities & QgsVectorDataProvider::RenameAttributes )
200  {
201  abilitiesList += tr( "Rename Attributes" );
202  QgsDebugMsg( "Capability: Rename Attributes" );
203  }
204 
206  {
207  // TODO: Tighten up this test. See QgsOgrProvider for details.
208  abilitiesList += tr( "Create Spatial Index" );
209  QgsDebugMsg( "Capability: Create Spatial Index" );
210  }
211 
213  {
214  abilitiesList += tr( "Create Attribute Indexes" );
215  QgsDebugMsg( "Capability: Create Attribute Index" );
216  }
217 
218  if ( abilities & QgsVectorDataProvider::SelectAtId )
219  {
220  abilitiesList += tr( "Fast Access to Features at ID" );
221  QgsDebugMsg( "Capability: Select at ID" );
222  }
223 
224  if ( abilities & QgsVectorDataProvider::ChangeGeometries )
225  {
226  abilitiesList += tr( "Change Geometries" );
227  QgsDebugMsg( "Capability: Change Geometries" );
228  }
229 
231  {
232  abilitiesList += tr( "Presimplify Geometries" );
233  QgsDebugMsg( "Capability: Simplify Geometries before fetching the feature" );
234  }
235 
237  {
238  abilitiesList += tr( "Presimplify Geometries with Validity Check" );
239  QgsDebugMsg( "Capability: Simplify Geometries before fetch the feature ensuring that the result is a valid geometry" );
240  }
241 
242  if ( abilities & QgsVectorDataProvider::ChangeFeatures )
243  {
244  abilitiesList += tr( "Simultaneous Geometry and Attribute Updates" );
245  QgsDebugMsg( "Capability: change both feature attributes and geometry at once" );
246  }
247 
249  {
250  abilitiesList += tr( "Transactions" );
251  QgsDebugMsg( "Capability: transactions" );
252  }
253 
255  {
256  abilitiesList += tr( "Curved Geometries" );
257  QgsDebugMsg( "Supports circular geometry types (circularstring, compoundcurve, curvepolygon)" );
258  }
259 
260  return abilitiesList.join( ", " );
261 }
262 
263 
264 int QgsVectorDataProvider::fieldNameIndex( const QString& fieldName ) const
265 {
266  return fields().fieldNameIndex( fieldName );
267 }
268 
270 {
271  QMap<QString, int> resultMap;
272 
273  const QgsFields& theFields = fields();
274  for ( int i = 0; i < theFields.count(); ++i )
275  {
276  resultMap.insert( theFields[i].name(), i );
277  }
278 
279  return resultMap;
280 }
281 
283 {
284  return fields().allAttributesList();
285 }
286 
288 {
289  return mNativeTypes;
290 }
291 
293 {
294  int i;
295  QgsDebugMsgLevel( QString( "field name = %1 type = %2 length = %3 precision = %4" )
296  .arg( field.name(),
297  QVariant::typeToName( field.type() ) )
298  .arg( field.length() )
299  .arg( field.precision() ), 2 );
300  for ( i = 0; i < mNativeTypes.size(); i++ )
301  {
302  QgsDebugMsgLevel( QString( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
303  .arg( QVariant::typeToName( mNativeTypes[i].mType ) )
304  .arg( mNativeTypes[i].mMinLen )
305  .arg( mNativeTypes[i].mMaxLen )
306  .arg( mNativeTypes[i].mMinPrec )
307  .arg( mNativeTypes[i].mMaxPrec ), 2 );
308 
309  if ( field.type() != mNativeTypes[i].mType )
310  continue;
311 
312  if ( field.length() == -1 )
313  {
314  // source length unlimited
315  if ( mNativeTypes[i].mMinLen > -1 || mNativeTypes[i].mMaxLen > -1 )
316  {
317  // destination limited
318  continue;
319  }
320  }
321  else
322  {
323  // source length limited
324  if ( mNativeTypes[i].mMinLen > -1 && mNativeTypes[i].mMaxLen > -1 &&
325  ( field.length() < mNativeTypes[i].mMinLen || field.length() > mNativeTypes[i].mMaxLen ) )
326  {
327  // source length exceeds destination limits
328  continue;
329  }
330  }
331 
332  if ( field.precision() == -1 )
333  {
334  // source precision unlimited / n/a
335  if ( mNativeTypes[i].mMinPrec > -1 || mNativeTypes[i].mMaxPrec > -1 )
336  {
337  // destination limited
338  continue;
339  }
340  }
341  else
342  {
343  // source precision unlimited / n/a
344  if ( mNativeTypes[i].mMinPrec > -1 && mNativeTypes[i].mMaxPrec > -1 &&
345  ( field.precision() < mNativeTypes[i].mMinPrec || field.precision() > mNativeTypes[i].mMaxPrec ) )
346  {
347  // source precision exceeds destination limits
348  continue;
349  }
350  }
351 
352  QgsDebugMsg( "native type matches" );
353  return true;
354  }
355 
356  QgsDebugMsg( "no sufficient native type found" );
357  return false;
358 }
359 
361 {
362  if ( index < 0 || index >= fields().count() )
363  {
364  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
365  return QVariant();
366  }
367 
368  fillMinMaxCache();
369 
370  if ( !mCacheMinValues.contains( index ) )
371  return QVariant();
372 
373  return mCacheMinValues[index];
374 }
375 
377 {
378  if ( index < 0 || index >= fields().count() )
379  {
380  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
381  return QVariant();
382  }
383 
384  fillMinMaxCache();
385 
386  if ( !mCacheMaxValues.contains( index ) )
387  return QVariant();
388 
389  return mCacheMaxValues[index];
390 }
391 
393 {
394  QgsFeature f;
395  QgsAttributeList keys;
396  keys.append( index );
397  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys ).setFlags( QgsFeatureRequest::NoGeometry ) );
398 
399  QSet<QString> set;
400  values.clear();
401 
402  while ( fi.nextFeature( f ) )
403  {
404  if ( !set.contains( f.attribute( index ).toString() ) )
405  {
406  values.append( f.attribute( index ) );
407  set.insert( f.attribute( index ).toString() );
408  }
409 
410  if ( limit >= 0 && values.size() >= limit )
411  break;
412  }
413 }
414 
416  const QgsAggregateCalculator::AggregateParameters& parameters, QgsExpressionContext* context, bool& ok )
417 {
418  //base implementation does nothing
419  Q_UNUSED( aggregate );
420  Q_UNUSED( index );
421  Q_UNUSED( parameters );
422  Q_UNUSED( context );
423 
424  ok = false;
425  return QVariant();
426 }
427 
429 {
430  mCacheMinMaxDirty = true;
431 }
432 
434 {
435  if ( !mCacheMinMaxDirty )
436  return;
437 
438  const QgsFields& flds = fields();
439  for ( int i = 0; i < flds.count(); ++i )
440  {
441  if ( flds[i].type() == QVariant::Int )
442  {
443  mCacheMinValues[i] = QVariant( INT_MAX );
444  mCacheMaxValues[i] = QVariant( INT_MIN );
445  }
446  else if ( flds[i].type() == QVariant::LongLong )
447  {
450  }
451  else if ( flds[i].type() == QVariant::Double )
452  {
453  mCacheMinValues[i] = QVariant( DBL_MAX );
454  mCacheMaxValues[i] = QVariant( -DBL_MAX );
455  }
456  else
457  {
458  mCacheMinValues[i] = QVariant();
459  mCacheMaxValues[i] = QVariant();
460  }
461  }
462 
463  QgsFeature f;
465  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys )
466  .setFlags( QgsFeatureRequest::NoGeometry ) );
467 
468  while ( fi.nextFeature( f ) )
469  {
470  QgsAttributes attrs = f.attributes();
471  for ( QgsAttributeList::const_iterator it = keys.begin(); it != keys.end(); ++it )
472  {
473  const QVariant& varValue = attrs.at( *it );
474 
475  if ( varValue.isNull() )
476  continue;
477 
478  if ( flds[*it].type() == QVariant::Int )
479  {
480  int value = varValue.toInt();
481  if ( value < mCacheMinValues[*it].toInt() )
482  mCacheMinValues[*it] = value;
483  if ( value > mCacheMaxValues[*it].toInt() )
484  mCacheMaxValues[*it] = value;
485  }
486  else if ( flds[*it].type() == QVariant::LongLong )
487  {
488  qlonglong value = varValue.toLongLong();
489  if ( value < mCacheMinValues[*it].toLongLong() )
490  mCacheMinValues[*it] = value;
491  if ( value > mCacheMaxValues[*it].toLongLong() )
492  mCacheMaxValues[*it] = value;
493  }
494  else if ( flds[*it].type() == QVariant::Double )
495  {
496  double value = varValue.toDouble();
497  if ( value < mCacheMinValues[*it].toDouble() )
498  mCacheMinValues[*it] = value;
499  if ( value > mCacheMaxValues[*it].toDouble() )
500  mCacheMaxValues[*it] = value;
501  }
502  else
503  {
504  QString value = varValue.toString();
505  if ( mCacheMinValues[*it].isNull() || value < mCacheMinValues[*it].toString() )
506  {
507  mCacheMinValues[*it] = value;
508  }
509  if ( mCacheMaxValues[*it].isNull() || value > mCacheMaxValues[*it].toString() )
510  {
511  mCacheMaxValues[*it] = value;
512  }
513  }
514  }
515  }
516 
517  mCacheMinMaxDirty = false;
518 }
519 
520 QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString& value )
521 {
522  QVariant v( value );
523 
524  if ( !v.convert( type ) || value.isNull() )
525  v = QVariant( type );
526 
527  return v;
528 }
529 
530 static bool _compareEncodings( const QString& s1, const QString& s2 )
531 {
532  return s1.toLower() < s2.toLower();
533 }
534 
536 {
537  if ( smEncodings.isEmpty() )
538  {
539  Q_FOREACH ( const QString& codec, QTextCodec::availableCodecs() )
540  {
541  smEncodings << codec;
542  }
543 #if 0
544  smEncodings << "BIG5";
545  smEncodings << "BIG5-HKSCS";
546  smEncodings << "EUCJP";
547  smEncodings << "EUCKR";
548  smEncodings << "GB2312";
549  smEncodings << "GBK";
550  smEncodings << "GB18030";
551  smEncodings << "JIS7";
552  smEncodings << "SHIFT-JIS";
553  smEncodings << "TSCII";
554  smEncodings << "UTF-8";
555  smEncodings << "UTF-16";
556  smEncodings << "KOI8-R";
557  smEncodings << "KOI8-U";
558  smEncodings << "ISO8859-1";
559  smEncodings << "ISO8859-2";
560  smEncodings << "ISO8859-3";
561  smEncodings << "ISO8859-4";
562  smEncodings << "ISO8859-5";
563  smEncodings << "ISO8859-6";
564  smEncodings << "ISO8859-7";
565  smEncodings << "ISO8859-8";
566  smEncodings << "ISO8859-8-I";
567  smEncodings << "ISO8859-9";
568  smEncodings << "ISO8859-10";
569  smEncodings << "ISO8859-11";
570  smEncodings << "ISO8859-12";
571  smEncodings << "ISO8859-13";
572  smEncodings << "ISO8859-14";
573  smEncodings << "ISO8859-15";
574  smEncodings << "IBM 850";
575  smEncodings << "IBM 866";
576  smEncodings << "CP874";
577  smEncodings << "CP1250";
578  smEncodings << "CP1251";
579  smEncodings << "CP1252";
580  smEncodings << "CP1253";
581  smEncodings << "CP1254";
582  smEncodings << "CP1255";
583  smEncodings << "CP1256";
584  smEncodings << "CP1257";
585  smEncodings << "CP1258";
586  smEncodings << "Apple Roman";
587  smEncodings << "TIS-620";
588  smEncodings << "System";
589 #endif
590  }
591 
592  // Do case-insensitive sorting of encodings
593  qSort( smEncodings.begin(), smEncodings.end(), _compareEncodings );
594 
595  return smEncodings;
596 }
597 
599 {
600  mErrors.clear();
601 }
602 
604 {
605  return !mErrors.isEmpty();
606 }
607 
609 {
610  return mErrors;
611 }
612 
614 {
615  QgsDebugMsg( msg );
616  mErrors << msg;
617  emit raiseError( msg );
618 }
619 
621 {
622  return QSet<QString>();
623 }
624 
626 {
627  if ( !geom )
628  {
629  return nullptr;
630  }
631 
632  QgsAbstractGeometryV2* geometry = geom->geometry();
633  if ( !geometry )
634  {
635  return nullptr;
636  }
637 
638  QgsWKBTypes::Type providerGeomType = QGis::fromOldWkbType( geometryType() );
639 
640  //geom is already in the provider geometry type
641  if ( geometry->wkbType() == providerGeomType )
642  {
643  return nullptr;
644  }
645 
646  QgsAbstractGeometryV2* outputGeom = nullptr;
647 
648  //convert compoundcurve to circularstring (possible if compoundcurve consists of one circular string)
650  {
651  QgsCompoundCurveV2* compoundCurve = static_cast<QgsCompoundCurveV2*>( geometry );
652  if ( compoundCurve )
653  {
654  if ( compoundCurve->nCurves() == 1 )
655  {
656  const QgsCircularStringV2* circularString = dynamic_cast<const QgsCircularStringV2*>( compoundCurve->curveAt( 0 ) );
657  if ( circularString )
658  {
659  outputGeom = circularString->clone();
660  }
661  }
662  }
663  }
664 
665  //convert to multitype if necessary
666  if ( QgsWKBTypes::isMultiType( providerGeomType ) && !QgsWKBTypes::isMultiType( geometry->wkbType() ) )
667  {
668  outputGeom = QgsGeometryFactory::geomFromWkbType( providerGeomType );
669  QgsGeometryCollectionV2* geomCollection = dynamic_cast<QgsGeometryCollectionV2*>( outputGeom );
670  if ( geomCollection )
671  {
672  geomCollection->addGeometry( geometry->clone() );
673  }
674  }
675 
676  //convert to curved type if necessary
677  if ( !QgsWKBTypes::isCurvedType( geometry->wkbType() ) && QgsWKBTypes::isCurvedType( providerGeomType ) )
678  {
679  QgsAbstractGeometryV2* curveGeom = outputGeom ? outputGeom->toCurveType() : geometry->toCurveType();
680  if ( curveGeom )
681  {
682  delete outputGeom;
683  outputGeom = curveGeom;
684  }
685  }
686 
687  //convert to linear type from curved type
688  if ( QgsWKBTypes::isCurvedType( geometry->wkbType() ) && !QgsWKBTypes::isCurvedType( providerGeomType ) )
689  {
690  QgsAbstractGeometryV2* segmentizedGeom = nullptr;
691  segmentizedGeom = outputGeom ? outputGeom->segmentize() : geometry->segmentize();
692  if ( segmentizedGeom )
693  {
694  delete outputGeom;
695  outputGeom = segmentizedGeom;
696  }
697  }
698 
699  //set z/m types
700  if ( QgsWKBTypes::hasZ( providerGeomType ) )
701  {
702  if ( !outputGeom )
703  {
704  outputGeom = geometry->clone();
705  }
706  outputGeom->addZValue();
707  }
708  if ( QgsWKBTypes::hasM( providerGeomType ) )
709  {
710  if ( !outputGeom )
711  {
712  outputGeom = geometry->clone();
713  }
714  outputGeom->addMValue();
715  }
716 
717  // remove Z if provider does not have
718  // control added to fix https://issues.qgis.org/issues/16927
719  if ( !QgsWKBTypes::hasZ( providerGeomType ) && QgsWKBTypes::hasZ( geometry->wkbType() ) )
720  {
721  if ( !outputGeom )
722  {
723  outputGeom = geometry->clone();
724  }
725  outputGeom->dropZValue();
726  }
727 
728  // remove M if provider does not have
729  // control added as follow-up of https://issues.qgis.org/issues/16927
730  if ( !QgsWKBTypes::hasM( providerGeomType ) && QgsWKBTypes::hasM( geometry->wkbType() ) )
731  {
732  if ( !outputGeom )
733  {
734  outputGeom = geometry->clone();
735  }
736  outputGeom->dropMValue();
737  }
738 
739  if ( outputGeom )
740  {
741  return new QgsGeometry( outputGeom );
742  }
743 
744  QString msg = tr( "Geometry type %1 not compatible with provider type %2.", "not compatible geometry" )
745  .arg( QgsWKBTypes::displayString( geometry->wkbType() ) )
746  .arg( QgsWKBTypes::displayString( providerGeomType ) );
747  const_cast<QgsVectorDataProvider*>( this )->pushError( msg );
748  return nullptr;
749 }
750 
751 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)
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
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.
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
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.
virtual QVariant defaultValue(int fieldId, bool forceLazyEval=false)
Returns the default value for field specified by fieldId.
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.
QgsGeometry * convertToProviderType(const QgsGeometry *geom) const
Converts the geometry to the provider type if possible / necessary this is the list of possible modif...
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.
This is the base class for vector data providers.
virtual QgsAbstractGeometryV2 * clone() const =0
Clones the geometry by performing a deep copy.
static QString displayString(Type type)
Returns a display string type for a WKB type, eg the geometry name used in WKT geometry representatio...
Definition: qgswkbtypes.cpp:48
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.