QGIS API Documentation 3.38.0-Grenoble (exported)
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 <cfloat>
19#include <climits>
20#include <limits>
21
23#include "qgscircularstring.h"
24#include "qgscompoundcurve.h"
25#include "qgsfeature.h"
26#include "qgsfeatureiterator.h"
27#include "qgsfeaturerequest.h"
28#include "qgsfeedback.h"
29#include "qgsfields.h"
30#include "qgsgeometry.h"
32#include "qgsgeometryfactory.h"
33#include "qgslogger.h"
34#include "qgsmessagelog.h"
36#include "qgsthreadingutils.h"
37#include <mutex>
39
42 : QgsDataProvider( uri, options, flags )
43 , mTemporalCapabilities( std::make_unique< QgsVectorDataProviderTemporalCapabilities >() )
44 , mElevationProperties( std::make_unique< QgsDataProviderElevationProperties >() )
45{
46}
47
49{
51
52 return QStringLiteral( "Generic vector file" );
53}
54
56{
58
59 QgsFeature f;
60 QgsFeatureRequest request;
61 request.setNoAttributes();
63 request.setLimit( 1 );
64 if ( getFeatures( request ).nextFeature( f ) )
65 return false;
66 else
67 return true;
68}
69
76
83
93
100
107
114
116{
118
119 return QString();
120}
121
123{
125
126 Q_UNUSED( flist )
127 Q_UNUSED( flags )
128 return false;
129}
130
132{
134
135 return mErrors.isEmpty() ? QString() : mErrors.last();
136}
137
139{
141
142 Q_UNUSED( ids )
143 return false;
144}
145
147{
149
150 if ( !( capabilities() & DeleteFeatures ) )
151 return false;
152
153 QgsFeatureIds toDelete;
155 QgsFeature f;
156 while ( it.nextFeature( f ) )
157 toDelete << f.id();
158
159 return deleteFeatures( toDelete );
160}
161
162bool QgsVectorDataProvider::addAttributes( const QList<QgsField> &attributes )
163{
165
166 Q_UNUSED( attributes )
167 return false;
168}
169
171{
173
174 Q_UNUSED( attributes )
175 return false;
176}
177
179{
181
182 Q_UNUSED( renamedAttributes )
183 return false;
184}
185
187{
189
190 Q_UNUSED( attr_map )
191 return false;
192}
193
194QVariant QgsVectorDataProvider::defaultValue( int fieldId ) const
195{
197
198 Q_UNUSED( fieldId )
199 return QVariant();
200}
201
202QString QgsVectorDataProvider::defaultValueClause( int fieldIndex ) const
203{
205
206 Q_UNUSED( fieldIndex )
207 return QString();
208}
209
211{
213
214 const QgsFields f = fields();
215 if ( fieldIndex < 0 || fieldIndex >= f.count() )
217
218 return f.at( fieldIndex ).constraints().constraints();
219}
220
222{
224
225 return false;
226}
227
229{
231
232 Q_UNUSED( geometry_map )
233 return false;
234}
235
237 const QgsGeometryMap &geometry_map )
238{
240
242 return false;
243
244 bool result = true;
245 result = result && changeAttributeValues( attr_map );
246 result = result && changeGeometryValues( geometry_map );
247 return result;
248}
249
256
258{
260
261 Q_UNUSED( field )
262 return true;
263}
264
271
273{
275
276 // Use UTF-8 if no encoding is specified
277 if ( e.isEmpty() )
278 {
279 mEncoding = QTextCodec::codecForName( "UTF-8" );
280 }
281 else
282 {
283 mEncoding = QTextCodec::codecForName( e.toLocal8Bit().constData() );
284 }
285 if ( !mEncoding && e != QLatin1String( "System" ) )
286 {
287 if ( !e.isEmpty() )
288 {
289 // can we use the OGR proxy codec?
290 if ( QgsOgrProxyTextCodec::supportedCodecs().contains( e, Qt::CaseInsensitive ) )
291 {
292 //from the Qt docs (https://doc.qt.io/qt-5/qtextcodec.html#QTextCodec-1)
293 // "The QTextCodec should always be constructed on the heap (i.e. with new).
294 // Qt takes ownership and will delete it when the application terminates."
295 mEncoding = new QgsOgrProxyTextCodec( e.toLocal8Bit() );
296 }
297 else
298 {
299 QgsMessageLog::logMessage( tr( "Codec %1 not found. Falling back to system locale" ).arg( e ) );
300 mEncoding = QTextCodec::codecForName( "System" );
301 }
302 }
303 }
304
305 if ( !mEncoding )
306 mEncoding = QTextCodec::codecForLocale();
307
308 Q_ASSERT( mEncoding );
309}
310
312{
314
315 if ( mEncoding )
316 {
317 return mEncoding->name();
318 }
319
320 return QString();
321}
322
324{
326
327 QStringList abilitiesList;
328
329 const int abilities = capabilities();
330
331 if ( abilities & QgsVectorDataProvider::AddFeatures )
332 {
333 abilitiesList += tr( "Add Features" );
334 }
335
337 {
338 abilitiesList += tr( "Delete Features" );
339 }
340
342 {
343 abilitiesList += tr( "Change Attribute Values" );
344 }
345
346 if ( abilities & QgsVectorDataProvider::AddAttributes )
347 {
348 abilitiesList += tr( "Add Attributes" );
349 }
350
352 {
353 abilitiesList += tr( "Delete Attributes" );
354 }
355
357 {
358 abilitiesList += tr( "Rename Attributes" );
359 }
360
362 {
363 // TODO: Tighten up this test. See QgsOgrProvider for details.
364 abilitiesList += tr( "Create Spatial Index" );
365 }
366
368 {
369 abilitiesList += tr( "Create Attribute Indexes" );
370 }
371
372 if ( abilities & QgsVectorDataProvider::SelectAtId )
373 {
374 abilitiesList += tr( "Fast Access to Features at ID" );
375 }
376
378 {
379 abilitiesList += tr( "Change Geometries" );
380 }
381
383 {
384 abilitiesList += tr( "Presimplify Geometries" );
385 }
386
388 {
389 abilitiesList += tr( "Presimplify Geometries with Validity Check" );
390 }
391
393 {
394 abilitiesList += tr( "Simultaneous Geometry and Attribute Updates" );
395 }
396
398 {
399 abilitiesList += tr( "Transactions" );
400 }
401
403 {
404 abilitiesList += tr( "Curved Geometries" );
405 }
406
408 {
409 abilitiesList += tr( "Feature Symbology" );
410 }
411
412 return abilitiesList.join( QLatin1String( ", " ) );
413}
414
419
420int QgsVectorDataProvider::fieldNameIndex( const QString &fieldName ) const
421{
423
424 return fields().lookupField( fieldName );
425}
426
427QMap<QString, int> QgsVectorDataProvider::fieldNameMap() const
428{
430
431 QMap<QString, int> resultMap;
432
433 const QgsFields fieldsCopy = fields();
434 for ( int i = 0; i < fieldsCopy.count(); ++i )
435 {
436 resultMap.insert( fieldsCopy.at( i ).name(), i );
437 }
438
439 return resultMap;
440}
441
448
455
456QList<QgsVectorDataProvider::NativeType> QgsVectorDataProvider::nativeTypes() const
457{
459
460 return mNativeTypes;
461}
462
469
471{
473
474 QgsDebugMsgLevel( QStringLiteral( "field name = %1 type = %2 length = %3 precision = %4" )
475 .arg( field.name(),
476 QVariant::typeToName( field.type() ) )
477 .arg( field.length() )
478 .arg( field.precision() ), 2 );
479
480 for ( const NativeType &nativeType : mNativeTypes )
481 {
482 QgsDebugMsgLevel( QStringLiteral( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
483 .arg( QVariant::typeToName( nativeType.mType ) )
484 .arg( nativeType.mMinLen )
485 .arg( nativeType.mMaxLen )
486 .arg( nativeType.mMinPrec )
487 .arg( nativeType.mMaxPrec ), 2 );
488
489 if ( field.type() != nativeType.mType )
490 continue;
491
492 if ( field.length() > 0 )
493 {
494 // source length limited
495 if ( ( nativeType.mMinLen > 0 && field.length() < nativeType.mMinLen ) ||
496 ( nativeType.mMaxLen > 0 && field.length() > nativeType.mMaxLen ) )
497 {
498 // source length exceeds destination limits
499 continue;
500 }
501 }
502
503 if ( field.precision() > 0 )
504 {
505 // source precision limited
506 if ( ( nativeType.mMinPrec > 0 && field.precision() < nativeType.mMinPrec ) ||
507 ( nativeType.mMaxPrec > 0 && field.precision() > nativeType.mMaxPrec ) )
508 {
509 // source precision exceeds destination limits
510 continue;
511 }
512 }
513
514 QgsDebugMsgLevel( QStringLiteral( "native type matches" ), 3 );
515 return true;
516 }
517
518 QgsDebugError( QStringLiteral( "no sufficient native type found" ) );
519 return false;
520}
521
522QVariant QgsVectorDataProvider::minimumValue( int index ) const
523{
525
526 if ( index < 0 || index >= fields().count() )
527 {
528 QgsDebugError( "Warning: access requested to invalid field index: " + QString::number( index ) );
529 return QVariant();
530 }
531
533
534 if ( !mCacheMinValues.contains( index ) )
535 return QVariant();
536
537 return mCacheMinValues[index];
538}
539
540QVariant QgsVectorDataProvider::maximumValue( int index ) const
541{
543
544 if ( index < 0 || index >= fields().count() )
545 {
546 QgsDebugError( "Warning: access requested to invalid field index: " + QString::number( index ) );
547 return QVariant();
548 }
549
551
552 if ( !mCacheMaxValues.contains( index ) )
553 return QVariant();
554
555 return mCacheMaxValues[index];
556}
557
558QStringList QgsVectorDataProvider::uniqueStringsMatching( int index, const QString &substring, int limit, QgsFeedback *feedback ) const
559{
561
562 QStringList results;
563
564 // Safety belt
565 if ( index < 0 || index >= fields().count() )
566 return results;
567
568 QgsFeature f;
569 QgsAttributeList keys;
570 keys.append( index );
571
572 QgsFeatureRequest request;
573 request.setSubsetOfAttributes( keys );
575 const QString fieldName = fields().at( index ).name();
576 request.setFilterExpression( QStringLiteral( "\"%1\" ILIKE '%%2%'" ).arg( fieldName, substring ) );
577 QgsFeatureIterator fi = getFeatures( request );
578
579 QSet<QString> set;
580
581 while ( fi.nextFeature( f ) )
582 {
583 const QString value = f.attribute( index ).toString();
584 if ( !set.contains( value ) )
585 {
586 results.append( value );
587 set.insert( value );
588 }
589
590 if ( ( limit >= 0 && results.size() >= limit ) || ( feedback && feedback->isCanceled() ) )
591 break;
592 }
593 return results;
594}
595
597 const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok, QgsFeatureIds *fids ) const
598{
599 // non fatal for now -- the "aggregate" functions are not thread safe and call this
601
602 //base implementation does nothing
603 Q_UNUSED( aggregate )
604 Q_UNUSED( index )
605 Q_UNUSED( parameters )
606 Q_UNUSED( context )
607 Q_UNUSED( fids )
608
609 ok = false;
610 return QVariant();
611}
612
614{
616
617 mCacheMinMaxDirty = true;
618 mCacheMinValues.clear();
619 mCacheMaxValues.clear();
620}
621
623{
625
626 if ( !mCacheMinMaxDirty )
627 return;
628
629 const QgsFields flds = fields();
630 for ( int i = 0; i < flds.count(); ++i )
631 {
632 if ( flds.at( i ).type() == QMetaType::Type::Int )
633 {
634 mCacheMinValues[i] = QVariant( std::numeric_limits<int>::max() );
635 mCacheMaxValues[i] = QVariant( std::numeric_limits<int>::lowest() );
636 }
637 else if ( flds.at( i ).type() == QMetaType::Type::LongLong )
638 {
639 mCacheMinValues[i] = QVariant( std::numeric_limits<qlonglong>::max() );
640 mCacheMaxValues[i] = QVariant( std::numeric_limits<qlonglong>::lowest() );
641 }
642 else if ( flds.at( i ).type() == QMetaType::Type::Double )
643 {
644 mCacheMinValues[i] = QVariant( std::numeric_limits<double>::max() );
645 mCacheMaxValues[i] = QVariant( std::numeric_limits<double>::lowest() );
646
647 }
648 else
649 {
650 mCacheMinValues[i] = QVariant();
651 mCacheMaxValues[i] = QVariant();
652 }
653 }
654
655 QgsFeature f;
656 const QgsAttributeList keys = mCacheMinValues.keys();
657 QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys )
659
660 while ( fi.nextFeature( f ) )
661 {
662 const QgsAttributes attrs = f.attributes();
663 for ( const int attributeIndex : keys )
664 {
665 const QVariant &varValue = attrs.at( attributeIndex );
666
667 if ( QgsVariantUtils::isNull( varValue ) )
668 continue;
669
670 switch ( flds.at( attributeIndex ).type() )
671 {
672 case QMetaType::Type::Int:
673 {
674 const int value = varValue.toInt();
675 if ( value < mCacheMinValues[ attributeIndex ].toInt() )
676 mCacheMinValues[ attributeIndex ] = value;
677 if ( value > mCacheMaxValues[ attributeIndex ].toInt() )
678 mCacheMaxValues[ attributeIndex ] = value;
679 break;
680 }
681 case QMetaType::Type::LongLong:
682 {
683 const qlonglong value = varValue.toLongLong();
684 if ( value < mCacheMinValues[ attributeIndex ].toLongLong() )
685 mCacheMinValues[ attributeIndex ] = value;
686 if ( value > mCacheMaxValues[ attributeIndex ].toLongLong() )
687 mCacheMaxValues[ attributeIndex ] = value;
688 break;
689 }
690 case QMetaType::Type::Double:
691 {
692 const double value = varValue.toDouble();
693 if ( value < mCacheMinValues[ attributeIndex ].toDouble() )
694 mCacheMinValues[attributeIndex ] = value;
695 if ( value > mCacheMaxValues[ attributeIndex ].toDouble() )
696 mCacheMaxValues[ attributeIndex ] = value;
697 break;
698 }
699 case QMetaType::Type::QDateTime:
700 {
701 const QDateTime value = varValue.toDateTime();
702 if ( value < mCacheMinValues[ attributeIndex ].toDateTime() || !mCacheMinValues[ attributeIndex ].isValid() )
703 mCacheMinValues[attributeIndex ] = value;
704 if ( value > mCacheMaxValues[ attributeIndex ].toDateTime() || !mCacheMaxValues[ attributeIndex ].isValid() )
705 mCacheMaxValues[ attributeIndex ] = value;
706 break;
707 }
708 case QMetaType::Type::QDate:
709 {
710 const QDate value = varValue.toDate();
711 if ( value < mCacheMinValues[ attributeIndex ].toDate() || !mCacheMinValues[ attributeIndex ].isValid() )
712 mCacheMinValues[attributeIndex ] = value;
713 if ( value > mCacheMaxValues[ attributeIndex ].toDate() || !mCacheMaxValues[ attributeIndex ].isValid() )
714 mCacheMaxValues[ attributeIndex ] = value;
715 break;
716 }
717 case QMetaType::Type::QTime:
718 {
719 const QTime value = varValue.toTime();
720 if ( value < mCacheMinValues[ attributeIndex ].toTime() || !mCacheMinValues[ attributeIndex ].isValid() )
721 mCacheMinValues[attributeIndex ] = value;
722 if ( value > mCacheMaxValues[ attributeIndex ].toTime() || !mCacheMaxValues[ attributeIndex ].isValid() )
723 mCacheMaxValues[ attributeIndex ] = value;
724 break;
725 }
726 default:
727 {
728 const QString value = varValue.toString();
729 if ( QgsVariantUtils::isNull( mCacheMinValues[ attributeIndex ] ) || value < mCacheMinValues[attributeIndex ].toString() )
730 {
731 mCacheMinValues[attributeIndex] = value;
732 }
733 if ( QgsVariantUtils::isNull( mCacheMaxValues[attributeIndex] ) || value > mCacheMaxValues[attributeIndex].toString() )
734 {
735 mCacheMaxValues[attributeIndex] = value;
736 }
737 break;
738 }
739 }
740 }
741 }
742
743 mCacheMinMaxDirty = false;
744}
745
746QVariant QgsVectorDataProvider::convertValue( QMetaType::Type type, const QString &value )
747{
748 QVariant v( value );
749
750 if ( !v.convert( type ) || value.isNull() )
752
753 return v;
754}
755
756QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString &value )
757{
759}
760
767
768static bool _compareEncodings( const QString &s1, const QString &s2 )
769{
770 return s1.toLower() < s2.toLower();
771}
772
773static bool _removeDuplicateEncodings( const QString &s1, const QString &s2 )
774{
775 return s1.compare( s2, Qt::CaseInsensitive ) == 0;
776}
777
779{
780 static std::once_flag initialized;
781 std::call_once( initialized, [ = ]
782 {
783 const auto codecs { QTextCodec::availableCodecs() };
784 for ( const QByteArray &codec : codecs )
785 {
786 sEncodings << codec;
787 }
788#if 0
789 smEncodings << "BIG5";
790 smEncodings << "BIG5-HKSCS";
791 smEncodings << "EUCJP";
792 smEncodings << "EUCKR";
793 smEncodings << "GB2312";
794 smEncodings << "GBK";
795 smEncodings << "GB18030";
796 smEncodings << "JIS7";
797 smEncodings << "SHIFT-JIS";
798 smEncodings << "TSCII";
799 smEncodings << "UTF-8";
800 smEncodings << "UTF-16";
801 smEncodings << "KOI8-R";
802 smEncodings << "KOI8-U";
803 smEncodings << "ISO8859-1";
804 smEncodings << "ISO8859-2";
805 smEncodings << "ISO8859-3";
806 smEncodings << "ISO8859-4";
807 smEncodings << "ISO8859-5";
808 smEncodings << "ISO8859-6";
809 smEncodings << "ISO8859-7";
810 smEncodings << "ISO8859-8";
811 smEncodings << "ISO8859-8-I";
812 smEncodings << "ISO8859-9";
813 smEncodings << "ISO8859-10";
814 smEncodings << "ISO8859-11";
815 smEncodings << "ISO8859-12";
816 smEncodings << "ISO8859-13";
817 smEncodings << "ISO8859-14";
818 smEncodings << "ISO8859-15";
819 smEncodings << "IBM 850";
820 smEncodings << "IBM 866";
821 smEncodings << "CP874";
822 smEncodings << "CP1250";
823 smEncodings << "CP1251";
824 smEncodings << "CP1252";
825 smEncodings << "CP1253";
826 smEncodings << "CP1254";
827 smEncodings << "CP1255";
828 smEncodings << "CP1256";
829 smEncodings << "CP1257";
830 smEncodings << "CP1258";
831 smEncodings << "Apple Roman";
832 smEncodings << "TIS-620";
833 smEncodings << "System";
834#endif
835
836 // Do case-insensitive sorting of encodings then remove duplicates
837 std::sort( sEncodings.begin(), sEncodings.end(), _compareEncodings );
838 const auto last = std::unique( sEncodings.begin(), sEncodings.end(), _removeDuplicateEncodings );
839 sEncodings.erase( last, sEncodings.end() );
840
841 } );
842
843 return sEncodings;
844}
845
847{
849
850 mErrors.clear();
851}
852
854{
856
857 return !mErrors.isEmpty();
858}
859
861{
863
864 return mErrors;
865}
866
868{
870
871 return nullptr;
872}
873
875{
877
878 return nullptr;
879}
880
881void QgsVectorDataProvider::pushError( const QString &msg ) const
882{
884
885 QgsDebugError( msg );
886 mErrors << msg;
887 emit raiseError( msg );
888}
889
890QSet<QgsMapLayerDependency> QgsVectorDataProvider::dependencies() const
891{
893
894 return QSet<QgsMapLayerDependency>();
895}
896
905
906void QgsVectorDataProvider::setNativeTypes( const QList<NativeType> &nativeTypes )
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 QgsCompoundCurve *compoundCurve = qgsgeometry_cast<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.reset( collGeom.release() );
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
1059
1066
1073
1080
1082{
1084
1085 return mElevationProperties.get();
1086}
QFlags< VectorLayerTypeFlag > VectorLayerTypeFlags
Vector layer type flags.
Definition qgis.h:332
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
FeatureAvailability
Possible return value for QgsFeatureSource::hasFeatures() to determine if a source is empty.
Definition qgis.h:387
@ FeaturesAvailable
There is at least one feature available in this source.
@ NoFeaturesAvailable
There are certainly no features available in this source.
Aggregate
Available aggregates to calculate.
Definition qgis.h:4949
@ SqlQuery
SQL query layer.
QFlags< VectorDataProviderAttributeEditCapability > VectorDataProviderAttributeEditCapabilities
Attribute editing capabilities which may be supported by vector data providers.
Definition qgis.h:412
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:201
@ 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.
QFlags< ReadFlag > ReadFlags
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.
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....
@ SimplifyGeometries
Supports simplification of geometries on provider side according to a distance tolerance.
@ SimplifyGeometriesWithTopologicalValidation
Supports topological simplification of geometries on provider side according to a distance tolerance.
@ CircularGeometries
Supports circular geometry types (circularstring, compoundcurve, curvepolygon)
@ SelectAtId
Fast access to features using their ID.
@ ChangeFeatures
Supports joint updates for attributes and geometry. Providers supporting this should still define Cha...
@ ChangeGeometries
Allows modifications of geometries.
@ DeleteAttributes
Allows deletion of attributes (fields)
@ DeleteFeatures
Allows deletion of features.
@ CreateAttributeIndex
Can create indexes on provider's fields.
@ TransactionSupport
Supports transactions.
@ NoCapabilities
Provider has no capabilities.
@ AddAttributes
Allows addition of new attributes (fields)
@ CreateSpatialIndex
Allows creation of spatial index.
@ FeatureSymbology
Provider is able retrieve embedded symbology associated with individual features. Since QGIS 3....
@ RenameAttributes
Supports renaming attributes (fields). Since QGIS 2.16.
@ ChangeAttributeValues
Allows modification of attribute values.
@ AddFeatures
Allows adding features.
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.
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.
QgsVectorDataProvider(const QString &uri=QString(), const QgsDataProvider::ProviderOptions &providerOptions=QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags flags=QgsDataProvider::ReadFlags())
Constructor for a vector data provider.
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.
QFlags< Capability > Capabilities
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 Q_INVOKABLE QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
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.