QGIS API Documentation 3.41.0-Master (cea29feecf2)
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
16#include <QTextCodec>
17
18#include <limits>
19
21#include "moc_qgsvectordataprovider.cpp"
22#include "qgscircularstring.h"
23#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#include <mutex>
38
41 : QgsDataProvider( uri, options, flags )
42 , mTemporalCapabilities( std::make_unique< QgsVectorDataProviderTemporalCapabilities >() )
43 , mElevationProperties( std::make_unique< QgsDataProviderElevationProperties >() )
44{
45}
46
48{
50
51 return QStringLiteral( "Generic vector file" );
52}
53
55{
57
58 QgsFeature f;
59 QgsFeatureRequest request;
60 request.setNoAttributes();
62 request.setLimit( 1 );
63 if ( getFeatures( request ).nextFeature( f ) )
64 return false;
65 else
66 return true;
67}
68
75
82
92
99
106
113
115{
117
118 return QString();
119}
120
122{
124
125 Q_UNUSED( flist )
126 Q_UNUSED( flags )
127 return false;
128}
129
131{
133
134 return mErrors.isEmpty() ? QString() : mErrors.last();
135}
136
138{
140
141 Q_UNUSED( ids )
142 return false;
143}
144
146{
148
150 return false;
151
152 QgsFeatureIds toDelete;
154 QgsFeature f;
155 while ( it.nextFeature( f ) )
156 toDelete << f.id();
157
158 return deleteFeatures( toDelete );
159}
160
161bool QgsVectorDataProvider::addAttributes( const QList<QgsField> &attributes )
162{
164
165 Q_UNUSED( attributes )
166 return false;
167}
168
170{
172
173 Q_UNUSED( attributes )
174 return false;
175}
176
178{
180
181 Q_UNUSED( renamedAttributes )
182 return false;
183}
184
186{
188
189 Q_UNUSED( attr_map )
190 return false;
191}
192
193QVariant QgsVectorDataProvider::defaultValue( int fieldId ) const
194{
196
197 Q_UNUSED( fieldId )
198 return QVariant();
199}
200
201QString QgsVectorDataProvider::defaultValueClause( int fieldIndex ) const
202{
204
205 Q_UNUSED( fieldIndex )
206 return QString();
207}
208
210{
212
213 const QgsFields f = fields();
214 if ( fieldIndex < 0 || fieldIndex >= f.count() )
216
217 return f.at( fieldIndex ).constraints().constraints();
218}
219
221{
223
224 return false;
225}
226
228{
230
231 Q_UNUSED( geometry_map )
232 return false;
233}
234
236 const QgsGeometryMap &geometry_map )
237{
239
241 return false;
242
243 bool result = true;
244 result = result && changeAttributeValues( attr_map );
245 result = result && changeGeometryValues( geometry_map );
246 return result;
247}
248
255
257{
259
260 Q_UNUSED( field )
261 return true;
262}
263
270
272{
274
275 // Use UTF-8 if no encoding is specified
276 if ( e.isEmpty() )
277 {
278 mEncoding = QTextCodec::codecForName( "UTF-8" );
279 }
280 else
281 {
282 mEncoding = QTextCodec::codecForName( e.toLocal8Bit().constData() );
283 }
284 if ( !mEncoding && e != QLatin1String( "System" ) )
285 {
286 if ( !e.isEmpty() )
287 {
288 // can we use the OGR proxy codec?
289 if ( QgsOgrProxyTextCodec::supportedCodecs().contains( e, Qt::CaseInsensitive ) )
290 {
291 //from the Qt docs (https://doc.qt.io/qt-5/qtextcodec.html#QTextCodec-1)
292 // "The QTextCodec should always be constructed on the heap (i.e. with new).
293 // Qt takes ownership and will delete it when the application terminates."
294 mEncoding = new QgsOgrProxyTextCodec( e.toLocal8Bit() );
295 }
296 else
297 {
298 QgsMessageLog::logMessage( tr( "Codec %1 not found. Falling back to system locale" ).arg( e ) );
299 mEncoding = QTextCodec::codecForName( "System" );
300 }
301 }
302 }
303
304 if ( !mEncoding )
305 mEncoding = QTextCodec::codecForLocale();
306
307 Q_ASSERT( mEncoding );
308}
309
311{
313
314 if ( mEncoding )
315 {
316 return mEncoding->name();
317 }
318
319 return QString();
320}
321
323{
325
326 QStringList abilitiesList;
327
329
331 {
332 abilitiesList += tr( "Add Features" );
333 }
334
336 {
337 abilitiesList += tr( "Delete Features" );
338 }
339
341 {
342 abilitiesList += tr( "Change Attribute Values" );
343 }
344
346 {
347 abilitiesList += tr( "Add Attributes" );
348 }
349
351 {
352 abilitiesList += tr( "Delete Attributes" );
353 }
354
356 {
357 abilitiesList += tr( "Rename Attributes" );
358 }
359
361 {
362 // TODO: Tighten up this test. See QgsOgrProvider for details.
363 abilitiesList += tr( "Create Spatial Index" );
364 }
365
367 {
368 abilitiesList += tr( "Create Attribute Indexes" );
369 }
370
372 {
373 abilitiesList += tr( "Fast Access to Features at ID" );
374 }
375
377 {
378 abilitiesList += tr( "Change Geometries" );
379 }
380
382 {
383 abilitiesList += tr( "Presimplify Geometries" );
384 }
385
387 {
388 abilitiesList += tr( "Presimplify Geometries with Validity Check" );
389 }
390
392 {
393 abilitiesList += tr( "Simultaneous Geometry and Attribute Updates" );
394 }
395
397 {
398 abilitiesList += tr( "Transactions" );
399 }
400
402 {
403 abilitiesList += tr( "Curved Geometries" );
404 }
405
407 {
408 abilitiesList += tr( "Feature Symbology" );
409 }
410
411 return abilitiesList.join( QLatin1String( ", " ) );
412}
413
418
419int QgsVectorDataProvider::fieldNameIndex( const QString &fieldName ) const
420{
422
423 return fields().lookupField( fieldName );
424}
425
426QMap<QString, int> QgsVectorDataProvider::fieldNameMap() const
427{
429
430 QMap<QString, int> resultMap;
431
432 const QgsFields fieldsCopy = fields();
433 for ( int i = 0; i < fieldsCopy.count(); ++i )
434 {
435 resultMap.insert( fieldsCopy.at( i ).name(), i );
436 }
437
438 return resultMap;
439}
440
447
454
455QList<QgsVectorDataProvider::NativeType> QgsVectorDataProvider::nativeTypes() const
456{
458
459 return mNativeTypes;
460}
461
468
470{
472
473 QgsDebugMsgLevel( QStringLiteral( "field name = %1 type = %2 length = %3 precision = %4" )
474 .arg( field.name(),
475 QVariant::typeToName( field.type() ) )
476 .arg( field.length() )
477 .arg( field.precision() ), 2 );
478
479 for ( const NativeType &nativeType : mNativeTypes )
480 {
481 QgsDebugMsgLevel( QStringLiteral( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
482 .arg( QVariant::typeToName( nativeType.mType ) )
483 .arg( nativeType.mMinLen )
484 .arg( nativeType.mMaxLen )
485 .arg( nativeType.mMinPrec )
486 .arg( nativeType.mMaxPrec ), 2 );
487
488 if ( field.type() != nativeType.mType )
489 continue;
490
491 if ( field.length() > 0 )
492 {
493 // source length limited
494 if ( ( nativeType.mMinLen > 0 && field.length() < nativeType.mMinLen ) ||
495 ( nativeType.mMaxLen > 0 && field.length() > nativeType.mMaxLen ) )
496 {
497 // source length exceeds destination limits
498 continue;
499 }
500 }
501
502 if ( field.precision() > 0 )
503 {
504 // source precision limited
505 if ( ( nativeType.mMinPrec > 0 && field.precision() < nativeType.mMinPrec ) ||
506 ( nativeType.mMaxPrec > 0 && field.precision() > nativeType.mMaxPrec ) )
507 {
508 // source precision exceeds destination limits
509 continue;
510 }
511 }
512
513 QgsDebugMsgLevel( QStringLiteral( "native type matches" ), 3 );
514 return true;
515 }
516
517 QgsDebugError( QStringLiteral( "no sufficient native type found" ) );
518 return false;
519}
520
521QVariant QgsVectorDataProvider::minimumValue( int index ) const
522{
524
525 if ( index < 0 || index >= fields().count() )
526 {
527 QgsDebugError( "Warning: access requested to invalid field index: " + QString::number( index ) );
528 return QVariant();
529 }
530
532
533 if ( !mCacheMinValues.contains( index ) )
534 return QVariant();
535
536 return mCacheMinValues[index];
537}
538
539QVariant QgsVectorDataProvider::maximumValue( int index ) const
540{
542
543 if ( index < 0 || index >= fields().count() )
544 {
545 QgsDebugError( "Warning: access requested to invalid field index: " + QString::number( index ) );
546 return QVariant();
547 }
548
550
551 if ( !mCacheMaxValues.contains( index ) )
552 return QVariant();
553
554 return mCacheMaxValues[index];
555}
556
557QStringList QgsVectorDataProvider::uniqueStringsMatching( int index, const QString &substring, int limit, QgsFeedback *feedback ) const
558{
560
561 QStringList results;
562
563 // Safety belt
564 if ( index < 0 || index >= fields().count() )
565 return results;
566
567 QgsFeature f;
568 QgsAttributeList keys;
569 keys.append( index );
570
571 QgsFeatureRequest request;
572 request.setSubsetOfAttributes( keys );
574 const QString fieldName = fields().at( index ).name();
575 request.setFilterExpression( QStringLiteral( "\"%1\" ILIKE '%%2%'" ).arg( fieldName, substring ) );
576 QgsFeatureIterator fi = getFeatures( request );
577
578 QSet<QString> set;
579
580 while ( fi.nextFeature( f ) )
581 {
582 const QString value = f.attribute( index ).toString();
583 if ( !set.contains( value ) )
584 {
585 results.append( value );
586 set.insert( value );
587 }
588
589 if ( ( limit >= 0 && results.size() >= limit ) || ( feedback && feedback->isCanceled() ) )
590 break;
591 }
592 return results;
593}
594
596 const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok, QgsFeatureIds *fids ) const
597{
598 // non fatal for now -- the "aggregate" functions are not thread safe and call this
600
601 //base implementation does nothing
602 Q_UNUSED( aggregate )
603 Q_UNUSED( index )
604 Q_UNUSED( parameters )
605 Q_UNUSED( context )
606 Q_UNUSED( fids )
607
608 ok = false;
609 return QVariant();
610}
611
613{
615
616 mCacheMinMaxDirty = true;
617 mCacheMinValues.clear();
618 mCacheMaxValues.clear();
619}
620
622{
624
625 if ( !mCacheMinMaxDirty )
626 return;
627
628 const QgsFields flds = fields();
629 for ( int i = 0; i < flds.count(); ++i )
630 {
631 if ( flds.at( i ).type() == QMetaType::Type::Int )
632 {
633 mCacheMinValues[i] = QVariant( std::numeric_limits<int>::max() );
634 mCacheMaxValues[i] = QVariant( std::numeric_limits<int>::lowest() );
635 }
636 else if ( flds.at( i ).type() == QMetaType::Type::LongLong )
637 {
638 mCacheMinValues[i] = QVariant( std::numeric_limits<qlonglong>::max() );
639 mCacheMaxValues[i] = QVariant( std::numeric_limits<qlonglong>::lowest() );
640 }
641 else if ( flds.at( i ).type() == QMetaType::Type::Double )
642 {
643 mCacheMinValues[i] = QVariant( std::numeric_limits<double>::max() );
644 mCacheMaxValues[i] = QVariant( std::numeric_limits<double>::lowest() );
645
646 }
647 else
648 {
649 mCacheMinValues[i] = QVariant();
650 mCacheMaxValues[i] = QVariant();
651 }
652 }
653
654 QgsFeature f;
655 const QgsAttributeList keys = mCacheMinValues.keys();
656 QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys )
658
659 while ( fi.nextFeature( f ) )
660 {
661 const QgsAttributes attrs = f.attributes();
662 for ( const int attributeIndex : keys )
663 {
664 const QVariant &varValue = attrs.at( attributeIndex );
665
666 if ( QgsVariantUtils::isNull( varValue ) )
667 continue;
668
669 switch ( flds.at( attributeIndex ).type() )
670 {
671 case QMetaType::Type::Int:
672 {
673 const int value = varValue.toInt();
674 if ( value < mCacheMinValues[ attributeIndex ].toInt() )
675 mCacheMinValues[ attributeIndex ] = value;
676 if ( value > mCacheMaxValues[ attributeIndex ].toInt() )
677 mCacheMaxValues[ attributeIndex ] = value;
678 break;
679 }
680 case QMetaType::Type::LongLong:
681 {
682 const qlonglong value = varValue.toLongLong();
683 if ( value < mCacheMinValues[ attributeIndex ].toLongLong() )
684 mCacheMinValues[ attributeIndex ] = value;
685 if ( value > mCacheMaxValues[ attributeIndex ].toLongLong() )
686 mCacheMaxValues[ attributeIndex ] = value;
687 break;
688 }
689 case QMetaType::Type::Double:
690 {
691 const double value = varValue.toDouble();
692 if ( value < mCacheMinValues[ attributeIndex ].toDouble() )
693 mCacheMinValues[attributeIndex ] = value;
694 if ( value > mCacheMaxValues[ attributeIndex ].toDouble() )
695 mCacheMaxValues[ attributeIndex ] = value;
696 break;
697 }
698 case QMetaType::Type::QDateTime:
699 {
700 const QDateTime value = varValue.toDateTime();
701 if ( value < mCacheMinValues[ attributeIndex ].toDateTime() || !mCacheMinValues[ attributeIndex ].isValid() )
702 mCacheMinValues[attributeIndex ] = value;
703 if ( value > mCacheMaxValues[ attributeIndex ].toDateTime() || !mCacheMaxValues[ attributeIndex ].isValid() )
704 mCacheMaxValues[ attributeIndex ] = value;
705 break;
706 }
707 case QMetaType::Type::QDate:
708 {
709 const QDate value = varValue.toDate();
710 if ( value < mCacheMinValues[ attributeIndex ].toDate() || !mCacheMinValues[ attributeIndex ].isValid() )
711 mCacheMinValues[attributeIndex ] = value;
712 if ( value > mCacheMaxValues[ attributeIndex ].toDate() || !mCacheMaxValues[ attributeIndex ].isValid() )
713 mCacheMaxValues[ attributeIndex ] = value;
714 break;
715 }
716 case QMetaType::Type::QTime:
717 {
718 const QTime value = varValue.toTime();
719 if ( value < mCacheMinValues[ attributeIndex ].toTime() || !mCacheMinValues[ attributeIndex ].isValid() )
720 mCacheMinValues[attributeIndex ] = value;
721 if ( value > mCacheMaxValues[ attributeIndex ].toTime() || !mCacheMaxValues[ attributeIndex ].isValid() )
722 mCacheMaxValues[ attributeIndex ] = value;
723 break;
724 }
725 default:
726 {
727 const QString value = varValue.toString();
728 if ( QgsVariantUtils::isNull( mCacheMinValues[ attributeIndex ] ) || value < mCacheMinValues[attributeIndex ].toString() )
729 {
730 mCacheMinValues[attributeIndex] = value;
731 }
732 if ( QgsVariantUtils::isNull( mCacheMaxValues[attributeIndex] ) || value > mCacheMaxValues[attributeIndex].toString() )
733 {
734 mCacheMaxValues[attributeIndex] = value;
735 }
736 break;
737 }
738 }
739 }
740 }
741
742 mCacheMinMaxDirty = false;
743}
744
745QVariant QgsVectorDataProvider::convertValue( QMetaType::Type type, const QString &value )
746{
747 QVariant v( value );
748
749 if ( !v.convert( type ) || value.isNull() )
751
752 return v;
753}
754
755QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString &value )
756{
758}
759
766
767static bool _compareEncodings( const QString &s1, const QString &s2 )
768{
769 return s1.toLower() < s2.toLower();
770}
771
772static bool _removeDuplicateEncodings( const QString &s1, const QString &s2 )
773{
774 return s1.compare( s2, Qt::CaseInsensitive ) == 0;
775}
776
778{
779 static std::once_flag initialized;
780 std::call_once( initialized, [ = ]
781 {
782 const auto codecs { QTextCodec::availableCodecs() };
783 for ( const QByteArray &codec : codecs )
784 {
785 sEncodings << codec;
786 }
787#if 0
788 smEncodings << "BIG5";
789 smEncodings << "BIG5-HKSCS";
790 smEncodings << "EUCJP";
791 smEncodings << "EUCKR";
792 smEncodings << "GB2312";
793 smEncodings << "GBK";
794 smEncodings << "GB18030";
795 smEncodings << "JIS7";
796 smEncodings << "SHIFT-JIS";
797 smEncodings << "TSCII";
798 smEncodings << "UTF-8";
799 smEncodings << "UTF-16";
800 smEncodings << "KOI8-R";
801 smEncodings << "KOI8-U";
802 smEncodings << "ISO8859-1";
803 smEncodings << "ISO8859-2";
804 smEncodings << "ISO8859-3";
805 smEncodings << "ISO8859-4";
806 smEncodings << "ISO8859-5";
807 smEncodings << "ISO8859-6";
808 smEncodings << "ISO8859-7";
809 smEncodings << "ISO8859-8";
810 smEncodings << "ISO8859-8-I";
811 smEncodings << "ISO8859-9";
812 smEncodings << "ISO8859-10";
813 smEncodings << "ISO8859-11";
814 smEncodings << "ISO8859-12";
815 smEncodings << "ISO8859-13";
816 smEncodings << "ISO8859-14";
817 smEncodings << "ISO8859-15";
818 smEncodings << "IBM 850";
819 smEncodings << "IBM 866";
820 smEncodings << "CP874";
821 smEncodings << "CP1250";
822 smEncodings << "CP1251";
823 smEncodings << "CP1252";
824 smEncodings << "CP1253";
825 smEncodings << "CP1254";
826 smEncodings << "CP1255";
827 smEncodings << "CP1256";
828 smEncodings << "CP1257";
829 smEncodings << "CP1258";
830 smEncodings << "Apple Roman";
831 smEncodings << "TIS-620";
832 smEncodings << "System";
833#endif
834
835 // Do case-insensitive sorting of encodings then remove duplicates
836 std::sort( sEncodings.begin(), sEncodings.end(), _compareEncodings );
837 const auto last = std::unique( sEncodings.begin(), sEncodings.end(), _removeDuplicateEncodings );
838 sEncodings.erase( last, sEncodings.end() );
839
840 } );
841
842 return sEncodings;
843}
844
846{
848
849 mErrors.clear();
850}
851
853{
855
856 return !mErrors.isEmpty();
857}
858
860{
862
863 return mErrors;
864}
865
867{
869
870 return nullptr;
871}
872
874{
876
877 return nullptr;
878}
879
880void QgsVectorDataProvider::pushError( const QString &msg ) const
881{
883
884 QgsDebugError( msg );
885 mErrors << msg;
886 emit raiseError( msg );
887}
888
889QSet<QgsMapLayerDependency> QgsVectorDataProvider::dependencies() const
890{
892
893 return QSet<QgsMapLayerDependency>();
894}
895
904
905void QgsVectorDataProvider::setNativeTypes( const QList<NativeType> &nativeTypes )
906{
908
909 mNativeTypes = nativeTypes;
910}
911
913{
914 // non fatal for now -- the "rasterize" processing algorithm is not thread safe and calls this
916
917 return mEncoding;
918}
919
921{
922 if ( geometry.isNull() )
923 {
924 return QgsGeometry();
925 }
926
927 const QgsAbstractGeometry *convertedGeometry = geometry.constGet();
928 if ( !convertedGeometry )
929 {
930 return QgsGeometry();
931 }
932
933
934 //geom is already in the provider geometry type
935 if ( convertedGeometry->wkbType() == providerGeometryType )
936 {
937 return QgsGeometry();
938 }
939
940 std::unique_ptr< QgsAbstractGeometry > outputGeom;
941
942 //convert compoundcurve to circularstring (possible if compoundcurve consists of one circular string)
943 if ( QgsWkbTypes::flatType( providerGeometryType ) == Qgis::WkbType::CircularString )
944 {
945 QgsCompoundCurve *compoundCurve = qgsgeometry_cast<QgsCompoundCurve *>( convertedGeometry );
946 if ( compoundCurve )
947 {
948 if ( compoundCurve->nCurves() == 1 )
949 {
950 const QgsCircularString *circularString = qgsgeometry_cast<const QgsCircularString *>( compoundCurve->curveAt( 0 ) );
951 if ( circularString )
952 {
953 outputGeom.reset( circularString->clone() );
954 }
955 }
956 }
957 }
958
959 //convert to curved type if necessary
960 if ( !QgsWkbTypes::isCurvedType( convertedGeometry->wkbType() ) && QgsWkbTypes::isCurvedType( providerGeometryType ) )
961 {
962 QgsAbstractGeometry *curveGeom = outputGeom ? outputGeom->toCurveType() : convertedGeometry->toCurveType();
963 if ( curveGeom )
964 {
965 outputGeom.reset( curveGeom );
966 }
967 }
968
969 //convert to linear type from curved type
970 if ( QgsWkbTypes::isCurvedType( convertedGeometry->wkbType() ) && !QgsWkbTypes::isCurvedType( providerGeometryType ) )
971 {
972 QgsAbstractGeometry *segmentizedGeom = outputGeom ? outputGeom->segmentize() : convertedGeometry->segmentize();
973 if ( segmentizedGeom )
974 {
975 outputGeom.reset( segmentizedGeom );
976 }
977 }
978
979 //convert to multitype if necessary
980 if ( QgsWkbTypes::isMultiType( providerGeometryType ) && !QgsWkbTypes::isMultiType( convertedGeometry->wkbType() ) )
981 {
982 std::unique_ptr< QgsAbstractGeometry > collGeom( QgsGeometryFactory::geomFromWkbType( providerGeometryType ) );
983 QgsGeometryCollection *geomCollection = qgsgeometry_cast<QgsGeometryCollection *>( collGeom.get() );
984 if ( geomCollection )
985 {
986 if ( geomCollection->addGeometry( outputGeom ? outputGeom->clone() : convertedGeometry->clone() ) )
987 {
988 outputGeom.reset( collGeom.release() );
989 }
990 }
991 }
992
993 //convert to single type if there's a single part of compatible type
994 if ( !QgsWkbTypes::isMultiType( providerGeometryType ) && QgsWkbTypes::isMultiType( convertedGeometry->wkbType() ) )
995 {
996 const QgsGeometryCollection *collection = qgsgeometry_cast<const QgsGeometryCollection *>( convertedGeometry );
997 if ( collection )
998 {
999 if ( collection->numGeometries() == 1 )
1000 {
1001 const QgsAbstractGeometry *firstGeom = collection->geometryN( 0 );
1002 if ( firstGeom && firstGeom->wkbType() == providerGeometryType )
1003 {
1004 outputGeom.reset( firstGeom->clone() );
1005 }
1006 }
1007 }
1008 }
1009
1010 //set z/m types
1011 if ( QgsWkbTypes::hasZ( providerGeometryType ) )
1012 {
1013 if ( !outputGeom )
1014 {
1015 outputGeom.reset( convertedGeometry->clone() );
1016 }
1017 outputGeom->addZValue();
1018 }
1019
1020 if ( QgsWkbTypes::hasM( providerGeometryType ) )
1021 {
1022 if ( !outputGeom )
1023 {
1024 outputGeom.reset( convertedGeometry->clone() );
1025 }
1026 outputGeom->addMValue();
1027 }
1028
1029 if ( outputGeom )
1030 {
1031 return QgsGeometry( outputGeom.release() );
1032 }
1033
1034 return QgsGeometry();
1035}
1036
1038{
1040
1041 return false;
1042}
1043
1044QStringList QgsVectorDataProvider::sEncodings;
1045
1046QList<QgsRelation> QgsVectorDataProvider::discoverRelations( const QgsVectorLayer *, const QList<QgsVectorLayer *> & ) const
1047{
1049
1050 return QList<QgsRelation>();
1051}
1052
1058
1065
1072
1079
1081{
1083
1084 return mElevationProperties.get();
1085}
@ SelectAtId
Fast access to features using their ID.
@ ChangeFeatures
Supports joint updates for attributes and geometry. Providers supporting this should still define Cha...
@ SimplifyGeometries
Supports simplification of geometries on provider side according to a distance tolerance.
@ AddFeatures
Allows adding features.
@ SimplifyGeometriesWithTopologicalValidation
Supports topological simplification of geometries on provider side according to a distance tolerance.
@ CreateAttributeIndex
Can create indexes on provider's fields.
@ CircularGeometries
Supports circular geometry types (circularstring, compoundcurve, curvepolygon)
@ NoCapabilities
Provider has no capabilities.
@ ChangeGeometries
Allows modifications of geometries.
@ AddAttributes
Allows addition of new attributes (fields)
@ CreateSpatialIndex
Allows creation of spatial index.
@ RenameAttributes
Supports renaming attributes (fields)
@ DeleteFeatures
Allows deletion of features.
@ TransactionSupport
Supports transactions.
@ DeleteAttributes
Allows deletion of attributes (fields)
@ ChangeAttributeValues
Allows modification of attribute values.
@ FeatureSymbology
Provider is able retrieve embedded symbology associated with individual features.
QFlags< VectorLayerTypeFlag > VectorLayerTypeFlags
Vector layer type flags.
Definition qgis.h:395
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
FeatureAvailability
Possible return value for QgsFeatureSource::hasFeatures() to determine if a source is empty.
Definition qgis.h:541
@ FeaturesAvailable
There is at least one feature available in this source.
@ NoFeaturesAvailable
There are certainly no features available in this source.
QFlags< VectorProviderCapability > VectorProviderCapabilities
Vector data provider capabilities.
Definition qgis.h:500
Aggregate
Available aggregates to calculate.
Definition qgis.h:5459
@ SqlQuery
SQL query layer.
QFlags< VectorDataProviderAttributeEditCapability > VectorDataProviderAttributeEditCapabilities
Attribute editing capabilities which may be supported by vector data providers.
Definition qgis.h:566
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
@ CircularString
CircularString.
Abstract base class for all geometries.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
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:43
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.
This class represents a coordinate reference system (CRS).
Base class for handling elevation related properties for a data provider.
Abstract base class for spatial data provider implementations.
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 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.
This class 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:58
QgsAttributes attributes
Definition qgsfeature.h:67
QgsFeatureId id
Definition qgsfeature.h:66
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:53
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:53
QMetaType::Type type
Definition qgsfield.h:60
QString name
Definition qgsfield.h:62
int precision
Definition qgsfield.h:59
int length
Definition qgsfield.h:58
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)
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.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
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.
This is the base class for vector data providers.
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.
virtual 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 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 data sets.
static bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
static bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
static 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.
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:39
#define QgsDebugError(str)
Definition qgslogger.h:38
#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.