QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
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
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
17
18#include <limits>
19#include <mutex>
20
21#include "qgscircularstring.h"
22#include "qgscompoundcurve.h"
24#include "qgsfeature.h"
25#include "qgsfeatureiterator.h"
26#include "qgsfeaturerequest.h"
27#include "qgsfeedback.h"
28#include "qgsfields.h"
29#include "qgsgeometry.h"
31#include "qgsgeometryfactory.h"
32#include "qgslogger.h"
33#include "qgsmessagelog.h"
35#include "qgsthreadingutils.h"
36
37#include <QString>
38#include <QTextCodec>
39
40#include "moc_qgsvectordataprovider.cpp"
41
42using namespace Qt::StringLiterals;
43
45 : QgsDataProvider( uri, options, flags )
46 , mTemporalCapabilities( std::make_unique< QgsVectorDataProviderTemporalCapabilities >() )
47 , mElevationProperties( std::make_unique< QgsDataProviderElevationProperties >() )
48{}
49
51{
53
54 return u"Generic vector file"_s;
55}
56
58{
60
61 QgsFeature f;
62 QgsFeatureRequest request;
63 request.setNoAttributes();
65 request.setLimit( 1 );
66 if ( getFeatures( request ).nextFeature( f ) )
67 return false;
68 else
69 return true;
70}
71
78
85
95
102
109
116
118{
120
121 return QString();
122}
123
125{
127
128 Q_UNUSED( flist )
129 Q_UNUSED( flags )
130 return false;
131}
132
134{
136
137 return mErrors.isEmpty() ? QString() : mErrors.last();
138}
139
141{
143
144 Q_UNUSED( ids )
145 return false;
146}
147
149{
151
153 return false;
154
155 QgsFeatureIds toDelete;
157 QgsFeature f;
158 while ( it.nextFeature( f ) )
159 toDelete << f.id();
160
161 return deleteFeatures( toDelete );
162}
163
164bool QgsVectorDataProvider::addAttributes( const QList<QgsField> &attributes )
165{
167
168 Q_UNUSED( attributes )
169 return false;
170}
171
173{
175
176 Q_UNUSED( attributes )
177 return false;
178}
179
181{
183
184 Q_UNUSED( renamedAttributes )
185 return false;
186}
187
189{
191
192 Q_UNUSED( attr_map )
193 return false;
194}
195
196QVariant QgsVectorDataProvider::defaultValue( int fieldId ) const
197{
199
200 Q_UNUSED( fieldId )
201 return QVariant();
202}
203
204QString QgsVectorDataProvider::defaultValueClause( int fieldIndex ) const
205{
207
208 Q_UNUSED( fieldIndex )
209 return QString();
210}
211
213{
215
216 const QgsFields f = fields();
217 if ( fieldIndex < 0 || fieldIndex >= f.count() )
219
220 return f.at( fieldIndex ).constraints().constraints();
221}
222
224{
226
227 return false;
228}
229
231{
233
234 Q_UNUSED( geometry_map )
235 return false;
236}
237
239{
241
243 return false;
244
245 bool result = true;
246 result = result && changeAttributeValues( attr_map );
247 result = result && changeGeometryValues( geometry_map );
248 return result;
249}
250
257
259{
261
262 Q_UNUSED( field )
263 return true;
264}
265
272
274{
276
277 // Use UTF-8 if no encoding is specified
278 if ( e.isEmpty() )
279 {
280 mEncoding = QTextCodec::codecForName( "UTF-8" );
281 }
282 else
283 {
284 mEncoding = QTextCodec::codecForName( e.toLocal8Bit().constData() );
285 }
286 if ( !mEncoding && e != "System"_L1 )
287 {
288 if ( !e.isEmpty() )
289 {
290 // can we use the OGR proxy codec?
291 if ( QgsOgrProxyTextCodec::supportedCodecs().contains( e, Qt::CaseInsensitive ) )
292 {
293 //from the Qt docs (https://doc.qt.io/qt-5/qtextcodec.html#QTextCodec-1)
294 // "The QTextCodec should always be constructed on the heap (i.e. with new).
295 // Qt takes ownership and will delete it when the application terminates."
296 mEncoding = new QgsOgrProxyTextCodec( e.toLocal8Bit() );
297 }
298 else
299 {
300 QgsMessageLog::logMessage( tr( "Codec %1 not found. Falling back to system locale" ).arg( e ) );
301 mEncoding = QTextCodec::codecForName( "System" );
302 }
303 }
304 }
305
306 if ( !mEncoding )
307 mEncoding = QTextCodec::codecForLocale();
308
309 Q_ASSERT( mEncoding );
310}
311
313{
315
316 if ( mEncoding )
317 {
318 return mEncoding->name();
319 }
320
321 return QString();
322}
323
325{
327
328 QStringList abilitiesList;
329
331
333 {
334 abilitiesList += tr( "Add Features" );
335 }
336
338 {
339 abilitiesList += tr( "Delete Features" );
340 }
341
343 {
344 abilitiesList += tr( "Change Attribute Values" );
345 }
346
348 {
349 abilitiesList += tr( "Add Attributes" );
350 }
351
353 {
354 abilitiesList += tr( "Delete Attributes" );
355 }
356
358 {
359 abilitiesList += tr( "Rename Attributes" );
360 }
361
363 {
364 // TODO: Tighten up this test. See QgsOgrProvider for details.
365 abilitiesList += tr( "Create Spatial Index" );
366 }
367
369 {
370 abilitiesList += tr( "Create Attribute Indexes" );
371 }
372
374 {
375 abilitiesList += tr( "Fast Access to Features at ID" );
376 }
377
379 {
380 abilitiesList += tr( "Change Geometries" );
381 }
382
384 {
385 abilitiesList += tr( "Presimplify Geometries" );
386 }
387
389 {
390 abilitiesList += tr( "Presimplify Geometries with Validity Check" );
391 }
392
394 {
395 abilitiesList += tr( "Simultaneous Geometry and Attribute Updates" );
396 }
397
399 {
400 abilitiesList += tr( "Transactions" );
401 }
402
404 {
405 abilitiesList += tr( "Curved Geometries" );
406 }
407
409 {
410 abilitiesList += tr( "Feature Symbology" );
411 }
412
413 return abilitiesList.join( ", "_L1 );
414}
415
420
421int QgsVectorDataProvider::fieldNameIndex( const QString &fieldName ) const
422{
424
425 return fields().lookupField( fieldName );
426}
427
428QMap<QString, int> QgsVectorDataProvider::fieldNameMap() const
429{
431
432 QMap<QString, int> resultMap;
433
434 const QgsFields fieldsCopy = fields();
435 for ( int i = 0; i < fieldsCopy.count(); ++i )
436 {
437 resultMap.insert( fieldsCopy.at( i ).name(), i );
438 }
439
440 return resultMap;
441}
442
449
456
458{
460
461 return QString();
462}
463
464QList<QgsVectorDataProvider::NativeType> QgsVectorDataProvider::nativeTypes() const
465{
467
468 return mNativeTypes;
469}
470
477
479{
481
482 QgsDebugMsgLevel( u"field name = %1 type = %2 length = %3 precision = %4"_s.arg( field.name(), QVariant::typeToName( field.type() ) ).arg( field.length() ).arg( field.precision() ), 2 );
483
484 for ( const NativeType &nativeType : mNativeTypes )
485 {
487 u"native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5"_s.arg( QVariant::typeToName( nativeType.mType ) )
488 .arg( nativeType.mMinLen )
489 .arg( nativeType.mMaxLen )
490 .arg( nativeType.mMinPrec )
491 .arg( nativeType.mMaxPrec ),
492 2
493 );
494
495 if ( field.type() != nativeType.mType )
496 continue;
497
498 if ( field.length() > 0 )
499 {
500 // source length limited
501 if ( ( nativeType.mMinLen > 0 && field.length() < nativeType.mMinLen ) || ( nativeType.mMaxLen > 0 && field.length() > nativeType.mMaxLen ) )
502 {
503 // source length exceeds destination limits
504 continue;
505 }
506 }
507
508 if ( field.precision() > 0 )
509 {
510 // source precision limited
511 if ( ( nativeType.mMinPrec > 0 && field.precision() < nativeType.mMinPrec ) || ( nativeType.mMaxPrec > 0 && field.precision() > nativeType.mMaxPrec ) )
512 {
513 // source precision exceeds destination limits
514 continue;
515 }
516 }
517
518 QgsDebugMsgLevel( u"native type matches"_s, 3 );
519 return true;
520 }
521
522 QgsDebugError( u"no sufficient native type found"_s );
523 return false;
524}
525
526QVariant QgsVectorDataProvider::minimumValue( int index ) const
527{
529
530 if ( index < 0 || index >= fields().count() )
531 {
532 QgsDebugError( "Warning: access requested to invalid field index: " + QString::number( index ) );
533 return QVariant();
534 }
535
537
538 if ( !mCacheMinValues.contains( index ) )
539 return QVariant();
540
541 return mCacheMinValues[index];
542}
543
544QVariant QgsVectorDataProvider::maximumValue( int index ) const
545{
547
548 if ( index < 0 || index >= fields().count() )
549 {
550 QgsDebugError( "Warning: access requested to invalid field index: " + QString::number( index ) );
551 return QVariant();
552 }
553
555
556 if ( !mCacheMaxValues.contains( index ) )
557 return QVariant();
558
559 return mCacheMaxValues[index];
560}
561
562QStringList QgsVectorDataProvider::uniqueStringsMatching( int index, const QString &substring, int limit, QgsFeedback *feedback ) const
563{
565
566 QStringList results;
567
568 // Safety belt
569 if ( index < 0 || index >= fields().count() )
570 return results;
571
572 QgsFeature f;
573 QgsAttributeList keys;
574 keys.append( index );
575
576 QgsFeatureRequest request;
577 request.setSubsetOfAttributes( keys );
579 const QString fieldName = fields().at( index ).name();
580 request.setFilterExpression( u"\"%1\" ILIKE '%%2%'"_s.arg( fieldName, substring ) );
581 QgsFeatureIterator fi = getFeatures( request );
582
583 QSet<QString> set;
584
585 while ( fi.nextFeature( f ) )
586 {
587 const QString value = f.attribute( index ).toString();
588 if ( !set.contains( value ) )
589 {
590 results.append( value );
591 set.insert( value );
592 }
593
594 if ( ( limit >= 0 && results.size() >= limit ) || ( feedback && feedback->isCanceled() ) )
595 break;
596 }
597 return results;
598}
599
602) const
603{
604 // non fatal for now -- the "aggregate" functions are not thread safe and call this
606
607 //base implementation does nothing
608 Q_UNUSED( aggregate )
609 Q_UNUSED( index )
610 Q_UNUSED( parameters )
611 Q_UNUSED( context )
612 Q_UNUSED( fids )
613
614 ok = false;
615 return QVariant();
616}
617
619{
621
622 mCacheMinMaxDirty = true;
623 mCacheMinValues.clear();
624 mCacheMaxValues.clear();
625}
626
628{
630
631 if ( !mCacheMinMaxDirty )
632 return;
633
634 const QgsFields flds = fields();
635 for ( int i = 0; i < flds.count(); ++i )
636 {
637 if ( flds.at( i ).type() == QMetaType::Type::Int )
638 {
639 mCacheMinValues[i] = QVariant( std::numeric_limits<int>::max() );
640 mCacheMaxValues[i] = QVariant( std::numeric_limits<int>::lowest() );
641 }
642 else if ( flds.at( i ).type() == QMetaType::Type::LongLong )
643 {
644 mCacheMinValues[i] = QVariant( std::numeric_limits<qlonglong>::max() );
645 mCacheMaxValues[i] = QVariant( std::numeric_limits<qlonglong>::lowest() );
646 }
647 else if ( flds.at( i ).type() == QMetaType::Type::Double )
648 {
649 mCacheMinValues[i] = QVariant( std::numeric_limits<double>::max() );
650 mCacheMaxValues[i] = QVariant( std::numeric_limits<double>::lowest() );
651 }
652 else
653 {
654 mCacheMinValues[i] = QVariant();
655 mCacheMaxValues[i] = QVariant();
656 }
657 }
658
659 QgsFeature f;
660 const QgsAttributeList keys = mCacheMinValues.keys();
661 QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys ).setFlags( Qgis::FeatureRequestFlag::NoGeometry ) );
662
663 while ( fi.nextFeature( f ) )
664 {
665 const QgsAttributes attrs = f.attributes();
666 for ( const int attributeIndex : keys )
667 {
668 const QVariant &varValue = attrs.at( attributeIndex );
669
670 if ( QgsVariantUtils::isNull( varValue ) )
671 continue;
672
673 switch ( flds.at( attributeIndex ).type() )
674 {
675 case QMetaType::Type::Int:
676 {
677 const int value = varValue.toInt();
678 if ( value < mCacheMinValues[attributeIndex].toInt() )
679 mCacheMinValues[attributeIndex] = value;
680 if ( value > mCacheMaxValues[attributeIndex].toInt() )
681 mCacheMaxValues[attributeIndex] = value;
682 break;
683 }
684 case QMetaType::Type::LongLong:
685 {
686 const qlonglong value = varValue.toLongLong();
687 if ( value < mCacheMinValues[attributeIndex].toLongLong() )
688 mCacheMinValues[attributeIndex] = value;
689 if ( value > mCacheMaxValues[attributeIndex].toLongLong() )
690 mCacheMaxValues[attributeIndex] = value;
691 break;
692 }
693 case QMetaType::Type::Double:
694 {
695 const double value = varValue.toDouble();
696 if ( value < mCacheMinValues[attributeIndex].toDouble() )
697 mCacheMinValues[attributeIndex] = value;
698 if ( value > mCacheMaxValues[attributeIndex].toDouble() )
699 mCacheMaxValues[attributeIndex] = value;
700 break;
701 }
702 case QMetaType::Type::QDateTime:
703 {
704 const QDateTime value = varValue.toDateTime();
705 if ( value < mCacheMinValues[attributeIndex].toDateTime() || !mCacheMinValues[attributeIndex].isValid() )
706 mCacheMinValues[attributeIndex] = value;
707 if ( value > mCacheMaxValues[attributeIndex].toDateTime() || !mCacheMaxValues[attributeIndex].isValid() )
708 mCacheMaxValues[attributeIndex] = value;
709 break;
710 }
711 case QMetaType::Type::QDate:
712 {
713 const QDate value = varValue.toDate();
714 if ( value < mCacheMinValues[attributeIndex].toDate() || !mCacheMinValues[attributeIndex].isValid() )
715 mCacheMinValues[attributeIndex] = value;
716 if ( value > mCacheMaxValues[attributeIndex].toDate() || !mCacheMaxValues[attributeIndex].isValid() )
717 mCacheMaxValues[attributeIndex] = value;
718 break;
719 }
720 case QMetaType::Type::QTime:
721 {
722 const QTime value = varValue.toTime();
723 if ( value < mCacheMinValues[attributeIndex].toTime() || !mCacheMinValues[attributeIndex].isValid() )
724 mCacheMinValues[attributeIndex] = value;
725 if ( value > mCacheMaxValues[attributeIndex].toTime() || !mCacheMaxValues[attributeIndex].isValid() )
726 mCacheMaxValues[attributeIndex] = value;
727 break;
728 }
729 default:
730 {
731 const QString value = varValue.toString();
732 if ( QgsVariantUtils::isNull( mCacheMinValues[attributeIndex] ) || value < mCacheMinValues[attributeIndex].toString() )
733 {
734 mCacheMinValues[attributeIndex] = value;
735 }
736 if ( QgsVariantUtils::isNull( mCacheMaxValues[attributeIndex] ) || value > mCacheMaxValues[attributeIndex].toString() )
737 {
738 mCacheMaxValues[attributeIndex] = value;
739 }
740 break;
741 }
742 }
743 }
744 }
745
746 mCacheMinMaxDirty = false;
747}
748
749QVariant QgsVectorDataProvider::convertValue( QMetaType::Type type, const QString &value )
750{
751 QVariant v( value );
752
753 if ( !v.convert( type ) || value.isNull() )
755
756 return v;
757}
758
759QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString &value )
760{
762}
763
770
771static bool _compareEncodings( const QString &s1, const QString &s2 )
772{
773 return s1.toLower() < s2.toLower();
774}
775
776static bool _removeDuplicateEncodings( const QString &s1, const QString &s2 )
777{
778 return s1.compare( s2, Qt::CaseInsensitive ) == 0;
779}
780
782{
783 static std::once_flag initialized;
784 std::call_once( initialized, [] {
785 const auto codecs { QTextCodec::availableCodecs() };
786 for ( const QByteArray &codec : codecs )
787 {
788 sEncodings << codec;
789 }
790#if 0
791 smEncodings << "BIG5";
792 smEncodings << "BIG5-HKSCS";
793 smEncodings << "EUCJP";
794 smEncodings << "EUCKR";
795 smEncodings << "GB2312";
796 smEncodings << "GBK";
797 smEncodings << "GB18030";
798 smEncodings << "JIS7";
799 smEncodings << "SHIFT-JIS";
800 smEncodings << "TSCII";
801 smEncodings << "UTF-8";
802 smEncodings << "UTF-16";
803 smEncodings << "KOI8-R";
804 smEncodings << "KOI8-U";
805 smEncodings << "ISO8859-1";
806 smEncodings << "ISO8859-2";
807 smEncodings << "ISO8859-3";
808 smEncodings << "ISO8859-4";
809 smEncodings << "ISO8859-5";
810 smEncodings << "ISO8859-6";
811 smEncodings << "ISO8859-7";
812 smEncodings << "ISO8859-8";
813 smEncodings << "ISO8859-8-I";
814 smEncodings << "ISO8859-9";
815 smEncodings << "ISO8859-10";
816 smEncodings << "ISO8859-11";
817 smEncodings << "ISO8859-12";
818 smEncodings << "ISO8859-13";
819 smEncodings << "ISO8859-14";
820 smEncodings << "ISO8859-15";
821 smEncodings << "IBM 850";
822 smEncodings << "IBM 866";
823 smEncodings << "CP874";
824 smEncodings << "CP1250";
825 smEncodings << "CP1251";
826 smEncodings << "CP1252";
827 smEncodings << "CP1253";
828 smEncodings << "CP1254";
829 smEncodings << "CP1255";
830 smEncodings << "CP1256";
831 smEncodings << "CP1257";
832 smEncodings << "CP1258";
833 smEncodings << "Apple Roman";
834 smEncodings << "TIS-620";
835 smEncodings << "System";
836#endif
837
838 // Do case-insensitive sorting of encodings then remove duplicates
839 std::sort( sEncodings.begin(), sEncodings.end(), _compareEncodings );
840 const auto last = std::unique( sEncodings.begin(), sEncodings.end(), _removeDuplicateEncodings );
841 sEncodings.erase( last, sEncodings.end() );
842 } );
843
844 return sEncodings;
845}
846
848{
850
851 mErrors.clear();
852}
853
855{
857
858 return !mErrors.isEmpty();
859}
860
862{
864
865 return mErrors;
866}
867
869{
871
872 return nullptr;
873}
874
876{
878
879 return nullptr;
880}
881
882void QgsVectorDataProvider::pushError( const QString &msg ) const
883{
885
886 QgsDebugError( msg );
887 mErrors << msg;
888 emit raiseError( msg );
889}
890
891QSet<QgsMapLayerDependency> QgsVectorDataProvider::dependencies() const
892{
894
895 return QSet<QgsMapLayerDependency>();
896}
897
905
907{
909
910 mNativeTypes = nativeTypes;
911}
912
914{
915 // non fatal for now -- the "rasterize" processing algorithm is not thread safe and calls this
917
918 return mEncoding;
919}
920
922{
923 if ( geometry.isNull() )
924 {
925 return QgsGeometry();
926 }
927
928 const QgsAbstractGeometry *convertedGeometry = geometry.constGet();
929 if ( !convertedGeometry )
930 {
931 return QgsGeometry();
932 }
933
934
935 //geom is already in the provider geometry type
936 if ( convertedGeometry->wkbType() == providerGeometryType )
937 {
938 return QgsGeometry();
939 }
940
941 std::unique_ptr< QgsAbstractGeometry > outputGeom;
942
943 //convert compoundcurve to circularstring (possible if compoundcurve consists of one circular string)
944 if ( QgsWkbTypes::flatType( providerGeometryType ) == Qgis::WkbType::CircularString )
945 {
946 const QgsCompoundCurve *compoundCurve = qgsgeometry_cast<const QgsCompoundCurve *>( convertedGeometry );
947 if ( compoundCurve )
948 {
949 if ( compoundCurve->nCurves() == 1 )
950 {
951 const QgsCircularString *circularString = qgsgeometry_cast<const QgsCircularString *>( compoundCurve->curveAt( 0 ) );
952 if ( circularString )
953 {
954 outputGeom.reset( circularString->clone() );
955 }
956 }
957 }
958 }
959
960 //convert to curved type if necessary
961 if ( !QgsWkbTypes::isCurvedType( convertedGeometry->wkbType() ) && QgsWkbTypes::isCurvedType( providerGeometryType ) )
962 {
963 QgsAbstractGeometry *curveGeom = outputGeom ? outputGeom->toCurveType() : convertedGeometry->toCurveType();
964 if ( curveGeom )
965 {
966 outputGeom.reset( curveGeom );
967 }
968 }
969
970 //convert to linear type from curved type
971 if ( QgsWkbTypes::isCurvedType( convertedGeometry->wkbType() ) && !QgsWkbTypes::isCurvedType( providerGeometryType ) )
972 {
973 QgsAbstractGeometry *segmentizedGeom = outputGeom ? outputGeom->segmentize() : convertedGeometry->segmentize();
974 if ( segmentizedGeom )
975 {
976 outputGeom.reset( segmentizedGeom );
977 }
978 }
979
980 //convert to multitype if necessary
981 if ( QgsWkbTypes::isMultiType( providerGeometryType ) && !QgsWkbTypes::isMultiType( convertedGeometry->wkbType() ) )
982 {
983 std::unique_ptr< QgsAbstractGeometry > collGeom( QgsGeometryFactory::geomFromWkbType( providerGeometryType ) );
984 QgsGeometryCollection *geomCollection = qgsgeometry_cast<QgsGeometryCollection *>( collGeom.get() );
985 if ( geomCollection )
986 {
987 if ( geomCollection->addGeometry( outputGeom ? outputGeom->clone() : convertedGeometry->clone() ) )
988 {
989 outputGeom = std::move( collGeom );
990 }
991 }
992 }
993
994 //convert to single type if there's a single part of compatible type
995 if ( !QgsWkbTypes::isMultiType( providerGeometryType ) && QgsWkbTypes::isMultiType( convertedGeometry->wkbType() ) )
996 {
997 const QgsGeometryCollection *collection = qgsgeometry_cast<const QgsGeometryCollection *>( convertedGeometry );
998 if ( collection )
999 {
1000 if ( collection->numGeometries() == 1 )
1001 {
1002 const QgsAbstractGeometry *firstGeom = collection->geometryN( 0 );
1003 if ( firstGeom && firstGeom->wkbType() == providerGeometryType )
1004 {
1005 outputGeom.reset( firstGeom->clone() );
1006 }
1007 }
1008 }
1009 }
1010
1011 //set z/m types
1012 if ( QgsWkbTypes::hasZ( providerGeometryType ) )
1013 {
1014 if ( !outputGeom )
1015 {
1016 outputGeom.reset( convertedGeometry->clone() );
1017 }
1018 outputGeom->addZValue();
1019 }
1020
1021 if ( QgsWkbTypes::hasM( providerGeometryType ) )
1022 {
1023 if ( !outputGeom )
1024 {
1025 outputGeom.reset( convertedGeometry->clone() );
1026 }
1027 outputGeom->addMValue();
1028 }
1029
1030 if ( outputGeom )
1031 {
1032 return QgsGeometry( outputGeom.release() );
1033 }
1034
1035 return QgsGeometry();
1036}
1037
1039{
1041
1042 return false;
1043}
1044
1045QStringList QgsVectorDataProvider::sEncodings;
1046
1047QList<QgsRelation> QgsVectorDataProvider::discoverRelations( const QgsVectorLayer *, const QList<QgsVectorLayer *> & ) const
1048{
1050
1051 return QList<QgsRelation>();
1052}
1053
1058
1065
1072
1079
1081{
1083
1084 return mElevationProperties.get();
1085}
@ SelectAtId
Fast access to features using their ID.
Definition qgis.h:533
@ ChangeFeatures
Supports joint updates for attributes and geometry. Providers supporting this should still define Cha...
Definition qgis.h:541
@ SimplifyGeometries
Supports simplification of geometries on provider side according to a distance tolerance.
Definition qgis.h:537
@ AddFeatures
Allows adding features.
Definition qgis.h:527
@ SimplifyGeometriesWithTopologicalValidation
Supports topological simplification of geometries on provider side according to a distance tolerance.
Definition qgis.h:538
@ CreateAttributeIndex
Can create indexes on provider's fields.
Definition qgis.h:536
@ CircularGeometries
Supports circular geometry types (circularstring, compoundcurve, curvepolygon).
Definition qgis.h:540
@ NoCapabilities
Provider has no capabilities.
Definition qgis.h:526
@ ChangeGeometries
Allows modifications of geometries.
Definition qgis.h:534
@ AddAttributes
Allows addition of new attributes (fields).
Definition qgis.h:530
@ CreateSpatialIndex
Allows creation of spatial index.
Definition qgis.h:532
@ RenameAttributes
Supports renaming attributes (fields).
Definition qgis.h:542
@ DeleteFeatures
Allows deletion of features.
Definition qgis.h:528
@ TransactionSupport
Supports transactions.
Definition qgis.h:539
@ DeleteAttributes
Allows deletion of attributes (fields).
Definition qgis.h:531
@ ChangeAttributeValues
Allows modification of attribute values.
Definition qgis.h:529
@ FeatureSymbology
Provider is able retrieve embedded symbology associated with individual features.
Definition qgis.h:550
QFlags< VectorLayerTypeFlag > VectorLayerTypeFlags
Vector layer type flags.
Definition qgis.h:440
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Definition qgis.h:2276
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:512
FeatureAvailability
Possible return value for QgsFeatureSource::hasFeatures() to determine if a source is empty.
Definition qgis.h:603
@ FeaturesAvailable
There is at least one feature available in this source.
Definition qgis.h:605
@ NoFeaturesAvailable
There are certainly no features available in this source.
Definition qgis.h:604
QFlags< VectorProviderCapability > VectorProviderCapabilities
Vector data provider capabilities.
Definition qgis.h:562
Aggregate
Available aggregates to calculate.
Definition qgis.h:6174
@ SqlQuery
SQL query layer.
Definition qgis.h:436
QFlags< VectorDataProviderAttributeEditCapability > VectorDataProviderAttributeEditCapabilities
Attribute editing capabilities which may be supported by vector data providers.
Definition qgis.h:628
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
@ CircularString
CircularString.
Definition qgis.h:304
Abstract base class for all geometries.
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
virtual QgsAbstractGeometry * toCurveType() const =0
Returns the geometry converted to the more generic curve type.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
A vector of attributes.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
Circular string geometry type.
QgsCircularString * clone() const override
Clones the geometry by performing a deep copy.
Compound curve geometry type.
int nCurves() const
Returns the number of curves in the geometry.
const QgsCurve * curveAt(int i) const
Returns the curve at the specified index.
Represents a coordinate reference system (CRS).
Base class for handling elevation related properties for a data provider.
virtual Qgis::DataProviderFlags flags() const
Returns the generic data provider flags.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
virtual QgsBox3D extent3D() const
Returns the 3D extent of the layer.
virtual bool isValid() const =0
Returns true if this is a valid layer.
QgsDataProvider(const QString &uri=QString(), const QgsDataProvider::ProviderOptions &providerOptions=QgsDataProvider::ProviderOptions(), Qgis::DataProviderReadFlags flags=Qgis::DataProviderReadFlags())
Create a new dataprovider with the specified in the uri.
QgsDataSourceUri uri() const
Gets the data source specification.
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Abstract base class for all 2D vector feature renderers.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setLimit(long long limit)
Set the maximum number of features to request.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
QFlags< Flag > Flags
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsAttributes attributes
Definition qgsfeature.h:69
QgsFeatureId id
Definition qgsfeature.h:68
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:56
Constraint
Constraints which may be present on a field.
QFlags< Constraint > Constraints
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
QMetaType::Type type
Definition qgsfield.h:63
QString name
Definition qgsfield.h:65
int precision
Definition qgsfield.h:62
int length
Definition qgsfield.h:61
Container of fields for a vector layer.
Definition qgsfields.h:46
int count
Definition qgsfields.h:50
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkbType(Qgis::WkbType t)
Returns empty geometry from wkb type.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
A QTextCodec implementation which relies on OGR to do the text conversion.
static QStringList supportedCodecs()
Returns a list of supported text codecs.
A rectangle specified with double values.
static QMetaType::Type variantTypeToMetaType(QVariant::Type variantType)
Converts a QVariant::Type to a QMetaType::Type.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static QVariant createNullVariant(QMetaType::Type metaType)
Helper method to properly create a null QVariant from a metaType Returns the created QVariant.
Implementation of data provider temporal properties for QgsVectorDataProviders.
void pushError(const QString &msg) const
Push a notification about errors that happened in this providers scope.
QgsRectangle sourceExtent() const override
Returns the extent of all geometries from the source.
virtual bool cancelReload()
Cancels the current reloading of data.
QString lastError() const override
Returns the most recent error encountered by the sink, e.g.
void setNativeTypes(const QList< QgsVectorDataProvider::NativeType > &nativeTypes)
Set the list of native types supported by this provider.
virtual QList< QgsRelation > discoverRelations(const QgsVectorLayer *target, const QList< QgsVectorLayer * > &layers) const
Discover the available relations with the given layers.
static QStringList availableEncodings()
Returns a list of available encodings.
QString dataComment() const override
Returns a short comment for the data that this provider is providing access to (e....
virtual QVariant aggregate(Qgis::Aggregate aggregate, int index, const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok, QgsFeatureIds *fids=nullptr) const
Calculates an aggregated value from the layer's features.
bool supportedType(const QgsField &field) const
check if provider supports type of field
virtual bool changeGeometryValues(const QgsGeometryMap &geometry_map)
Changes geometries of existing features.
virtual bool createSpatialIndex()
Creates a spatial index on the datasource (if supported by the provider type).
Q_DECL_DEPRECATED QgsAttrPalIndexNameHash palAttributeIndexNames() const
Returns list of indexes to names for QgsPalLabeling fix.
QgsCoordinateReferenceSystem sourceCrs() const override
Returns the coordinate reference system for features in the source.
virtual QgsFeatureRenderer * createRenderer(const QVariantMap &configuration=QVariantMap()) const
Creates a new vector layer feature renderer, using provider backend specific information.
virtual QString geometryColumnName() const
Returns the name of the column storing geometry, if applicable.
virtual QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
void clearMinMaxCache()
Invalidates the min/max cache.
virtual bool truncate()
Removes all features from the layer.
virtual QStringList uniqueStringsMatching(int index, const QString &substring, int limit=-1, QgsFeedback *feedback=nullptr) const
Returns unique string values of an attribute which contain a specified subset string.
void raiseError(const QString &msg) const
Signals an error in this provider.
QTextCodec * textEncoding() const
Gets this providers encoding.
QgsVectorDataProvider(const QString &uri=QString(), const QgsDataProvider::ProviderOptions &providerOptions=QgsDataProvider::ProviderOptions(), Qgis::DataProviderReadFlags flags=Qgis::DataProviderReadFlags())
Constructor for a vector data provider.
virtual bool isSqlQuery() const
Returns true if the layer is a query (SQL) layer.
void clearErrors()
Clear recorded errors.
QStringList errors() const
Gets recorded errors.
virtual bool empty() const
Returns true if the layer does not contain any feature.
virtual Q_INVOKABLE Qgis::VectorProviderCapabilities capabilities() const
Returns flags containing the supported capabilities.
QList< QgsVectorDataProvider::NativeType > nativeTypes() const
Returns the names of the supported types.
QgsBox3D sourceExtent3D() const override
Returns the 3D extent of all geometries from the source.
virtual QgsAttributeList pkAttributeIndexes() const
Returns list of indexes of fields that make up the primary key.
virtual void handlePostCloneOperations(QgsVectorDataProvider *source)
Handles any post-clone operations required after this vector data provider was cloned from the source...
QgsGeometry convertToProviderType(const QgsGeometry &geom) const
Converts the geometry to the provider type if possible / necessary.
virtual bool changeFeatures(const QgsChangedAttributesMap &attr_map, const QgsGeometryMap &geometry_map)
Changes attribute values and geometries of existing features.
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of layer ids on which this layer depends.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
virtual QString defaultValueClause(int fieldIndex) const
Returns any default value clauses which are present at the provider for a specified field index.
virtual void setEncoding(const QString &e)
Set encoding used for accessing data from layer.
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features from the provider.
virtual Qgis::VectorLayerTypeFlags vectorLayerTypeFlags() const
Returns the vector layer type flags.
QVariant maximumValue(int index) const override
Returns the maximum value of an attribute.
virtual bool createAttributeIndex(int field)
Create an attribute index on the datasource.
bool addFeatures(QgsFeatureList &flist, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a list of features to the sink.
QgsDataProviderElevationProperties * elevationProperties() override
Returns the provider's elevation properties.
QgsFields fields() const override=0
Returns the fields associated with this data provider.
QMap< QString, int > fieldNameMap() const
Returns a map where the key is the name of the field and the value is its index.
Qgis::WkbType wkbType() const override=0
Returns the geometry type which is returned by this layer.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const override=0
Query the provider for features specified in request.
virtual QgsAttributeList attributeIndexes() const
Returns list of indexes to fetch all attributes in nextFeature().
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes to the provider.
QVariant minimumValue(int index) const override
Returns the minimum value of an attribute.
void fillMinMaxCache() const
Populates the cache of minimum and maximum attribute values.
QString encoding() const
Returns the encoding which is used for accessing data.
virtual QVariant defaultValue(int fieldIndex) const
Returns any literal default values which are present at the provider for a specified field index.
QgsFieldConstraints::Constraints fieldConstraints(int fieldIndex) const
Returns any constraints which are present at the provider for a specified field index.
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
virtual QgsAbstractVectorLayerLabeling * createLabeling(const QVariantMap &configuration=QVariantMap()) const
Creates labeling settings, using provider backend specific information.
static QVariant convertValue(QMetaType::Type type, const QString &value)
Convert value to type.
Qgis::FeatureAvailability hasFeatures() const override
Will always return FeatureAvailability::FeaturesAvailable or FeatureAvailability::NoFeaturesAvailable...
virtual bool renameAttributes(const QgsFieldNameMap &renamedAttributes)
Renames existing attributes.
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes from the provider.
virtual bool skipConstraintCheck(int fieldIndex, QgsFieldConstraints::Constraint constraint, const QVariant &value=QVariant()) const
Returns true if a constraint check should be skipped for a specified field (e.g., if the value return...
virtual Qgis::VectorDataProviderAttributeEditCapabilities attributeEditCapabilities() const
Returns the provider's supported attribute editing capabilities.
bool hasErrors() const
Provider has errors to report.
QgsVectorDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
QString capabilitiesString() const
Returns the above in friendly format.
Represents a vector layer which manages a vector based dataset.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
static Q_INVOKABLE bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
static Q_INVOKABLE bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QMap< int, QString > QgsFieldNameMap
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:63
#define QgsDebugError(str)
Definition qgslogger.h:59
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
QList< int > QgsAttributeList
QSet< int > QgsAttributeIds
QHash< int, QString > QgsAttrPalIndexNameHash
A bundle of parameters controlling aggregate calculation.
Setting options for creating vector data providers.