QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <QTextCodec>
38
39#include "moc_qgsvectordataprovider.cpp"
40
43 : QgsDataProvider( uri, options, flags )
44 , mTemporalCapabilities( std::make_unique< QgsVectorDataProviderTemporalCapabilities >() )
45 , mElevationProperties( std::make_unique< QgsDataProviderElevationProperties >() )
46{
47}
48
50{
52
53 return QStringLiteral( "Generic vector file" );
54}
55
57{
59
60 QgsFeature f;
61 QgsFeatureRequest request;
62 request.setNoAttributes();
64 request.setLimit( 1 );
65 if ( getFeatures( request ).nextFeature( f ) )
66 return false;
67 else
68 return true;
69}
70
77
84
94
101
108
115
117{
119
120 return QString();
121}
122
124{
126
127 Q_UNUSED( flist )
128 Q_UNUSED( flags )
129 return false;
130}
131
133{
135
136 return mErrors.isEmpty() ? QString() : mErrors.last();
137}
138
140{
142
143 Q_UNUSED( ids )
144 return false;
145}
146
148{
150
152 return false;
153
154 QgsFeatureIds toDelete;
156 QgsFeature f;
157 while ( it.nextFeature( f ) )
158 toDelete << f.id();
159
160 return deleteFeatures( toDelete );
161}
162
163bool QgsVectorDataProvider::addAttributes( const QList<QgsField> &attributes )
164{
166
167 Q_UNUSED( attributes )
168 return false;
169}
170
172{
174
175 Q_UNUSED( attributes )
176 return false;
177}
178
180{
182
183 Q_UNUSED( renamedAttributes )
184 return false;
185}
186
188{
190
191 Q_UNUSED( attr_map )
192 return false;
193}
194
195QVariant QgsVectorDataProvider::defaultValue( int fieldId ) const
196{
198
199 Q_UNUSED( fieldId )
200 return QVariant();
201}
202
203QString QgsVectorDataProvider::defaultValueClause( int fieldIndex ) const
204{
206
207 Q_UNUSED( fieldIndex )
208 return QString();
209}
210
212{
214
215 const QgsFields f = fields();
216 if ( fieldIndex < 0 || fieldIndex >= f.count() )
218
219 return f.at( fieldIndex ).constraints().constraints();
220}
221
223{
225
226 return false;
227}
228
230{
232
233 Q_UNUSED( geometry_map )
234 return false;
235}
236
238 const QgsGeometryMap &geometry_map )
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 != QLatin1String( "System" ) )
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( QLatin1String( ", " ) );
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( QStringLiteral( "field name = %1 type = %2 length = %3 precision = %4" )
483 .arg( field.name(),
484 QVariant::typeToName( field.type() ) )
485 .arg( field.length() )
486 .arg( field.precision() ), 2 );
487
488 for ( const NativeType &nativeType : mNativeTypes )
489 {
490 QgsDebugMsgLevel( QStringLiteral( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
491 .arg( QVariant::typeToName( nativeType.mType ) )
492 .arg( nativeType.mMinLen )
493 .arg( nativeType.mMaxLen )
494 .arg( nativeType.mMinPrec )
495 .arg( nativeType.mMaxPrec ), 2 );
496
497 if ( field.type() != nativeType.mType )
498 continue;
499
500 if ( field.length() > 0 )
501 {
502 // source length limited
503 if ( ( nativeType.mMinLen > 0 && field.length() < nativeType.mMinLen ) ||
504 ( nativeType.mMaxLen > 0 && field.length() > nativeType.mMaxLen ) )
505 {
506 // source length exceeds destination limits
507 continue;
508 }
509 }
510
511 if ( field.precision() > 0 )
512 {
513 // source precision limited
514 if ( ( nativeType.mMinPrec > 0 && field.precision() < nativeType.mMinPrec ) ||
515 ( nativeType.mMaxPrec > 0 && field.precision() > nativeType.mMaxPrec ) )
516 {
517 // source precision exceeds destination limits
518 continue;
519 }
520 }
521
522 QgsDebugMsgLevel( QStringLiteral( "native type matches" ), 3 );
523 return true;
524 }
525
526 QgsDebugError( QStringLiteral( "no sufficient native type found" ) );
527 return false;
528}
529
530QVariant QgsVectorDataProvider::minimumValue( int index ) const
531{
533
534 if ( index < 0 || index >= fields().count() )
535 {
536 QgsDebugError( "Warning: access requested to invalid field index: " + QString::number( index ) );
537 return QVariant();
538 }
539
541
542 if ( !mCacheMinValues.contains( index ) )
543 return QVariant();
544
545 return mCacheMinValues[index];
546}
547
548QVariant QgsVectorDataProvider::maximumValue( int index ) const
549{
551
552 if ( index < 0 || index >= fields().count() )
553 {
554 QgsDebugError( "Warning: access requested to invalid field index: " + QString::number( index ) );
555 return QVariant();
556 }
557
559
560 if ( !mCacheMaxValues.contains( index ) )
561 return QVariant();
562
563 return mCacheMaxValues[index];
564}
565
566QStringList QgsVectorDataProvider::uniqueStringsMatching( int index, const QString &substring, int limit, QgsFeedback *feedback ) const
567{
569
570 QStringList results;
571
572 // Safety belt
573 if ( index < 0 || index >= fields().count() )
574 return results;
575
576 QgsFeature f;
577 QgsAttributeList keys;
578 keys.append( index );
579
580 QgsFeatureRequest request;
581 request.setSubsetOfAttributes( keys );
583 const QString fieldName = fields().at( index ).name();
584 request.setFilterExpression( QStringLiteral( "\"%1\" ILIKE '%%2%'" ).arg( fieldName, substring ) );
585 QgsFeatureIterator fi = getFeatures( request );
586
587 QSet<QString> set;
588
589 while ( fi.nextFeature( f ) )
590 {
591 const QString value = f.attribute( index ).toString();
592 if ( !set.contains( value ) )
593 {
594 results.append( value );
595 set.insert( value );
596 }
597
598 if ( ( limit >= 0 && results.size() >= limit ) || ( feedback && feedback->isCanceled() ) )
599 break;
600 }
601 return results;
602}
603
605 const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok, QgsFeatureIds *fids ) const
606{
607 // non fatal for now -- the "aggregate" functions are not thread safe and call this
609
610 //base implementation does nothing
611 Q_UNUSED( aggregate )
612 Q_UNUSED( index )
613 Q_UNUSED( parameters )
614 Q_UNUSED( context )
615 Q_UNUSED( fids )
616
617 ok = false;
618 return QVariant();
619}
620
622{
624
625 mCacheMinMaxDirty = true;
626 mCacheMinValues.clear();
627 mCacheMaxValues.clear();
628}
629
631{
633
634 if ( !mCacheMinMaxDirty )
635 return;
636
637 const QgsFields flds = fields();
638 for ( int i = 0; i < flds.count(); ++i )
639 {
640 if ( flds.at( i ).type() == QMetaType::Type::Int )
641 {
642 mCacheMinValues[i] = QVariant( std::numeric_limits<int>::max() );
643 mCacheMaxValues[i] = QVariant( std::numeric_limits<int>::lowest() );
644 }
645 else if ( flds.at( i ).type() == QMetaType::Type::LongLong )
646 {
647 mCacheMinValues[i] = QVariant( std::numeric_limits<qlonglong>::max() );
648 mCacheMaxValues[i] = QVariant( std::numeric_limits<qlonglong>::lowest() );
649 }
650 else if ( flds.at( i ).type() == QMetaType::Type::Double )
651 {
652 mCacheMinValues[i] = QVariant( std::numeric_limits<double>::max() );
653 mCacheMaxValues[i] = QVariant( std::numeric_limits<double>::lowest() );
654
655 }
656 else
657 {
658 mCacheMinValues[i] = QVariant();
659 mCacheMaxValues[i] = QVariant();
660 }
661 }
662
663 QgsFeature f;
664 const QgsAttributeList keys = mCacheMinValues.keys();
665 QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys )
667
668 while ( fi.nextFeature( f ) )
669 {
670 const QgsAttributes attrs = f.attributes();
671 for ( const int attributeIndex : keys )
672 {
673 const QVariant &varValue = attrs.at( attributeIndex );
674
675 if ( QgsVariantUtils::isNull( varValue ) )
676 continue;
677
678 switch ( flds.at( attributeIndex ).type() )
679 {
680 case QMetaType::Type::Int:
681 {
682 const int value = varValue.toInt();
683 if ( value < mCacheMinValues[ attributeIndex ].toInt() )
684 mCacheMinValues[ attributeIndex ] = value;
685 if ( value > mCacheMaxValues[ attributeIndex ].toInt() )
686 mCacheMaxValues[ attributeIndex ] = value;
687 break;
688 }
689 case QMetaType::Type::LongLong:
690 {
691 const qlonglong value = varValue.toLongLong();
692 if ( value < mCacheMinValues[ attributeIndex ].toLongLong() )
693 mCacheMinValues[ attributeIndex ] = value;
694 if ( value > mCacheMaxValues[ attributeIndex ].toLongLong() )
695 mCacheMaxValues[ attributeIndex ] = value;
696 break;
697 }
698 case QMetaType::Type::Double:
699 {
700 const double value = varValue.toDouble();
701 if ( value < mCacheMinValues[ attributeIndex ].toDouble() )
702 mCacheMinValues[attributeIndex ] = value;
703 if ( value > mCacheMaxValues[ attributeIndex ].toDouble() )
704 mCacheMaxValues[ attributeIndex ] = value;
705 break;
706 }
707 case QMetaType::Type::QDateTime:
708 {
709 const QDateTime value = varValue.toDateTime();
710 if ( value < mCacheMinValues[ attributeIndex ].toDateTime() || !mCacheMinValues[ attributeIndex ].isValid() )
711 mCacheMinValues[attributeIndex ] = value;
712 if ( value > mCacheMaxValues[ attributeIndex ].toDateTime() || !mCacheMaxValues[ attributeIndex ].isValid() )
713 mCacheMaxValues[ attributeIndex ] = value;
714 break;
715 }
716 case QMetaType::Type::QDate:
717 {
718 const QDate value = varValue.toDate();
719 if ( value < mCacheMinValues[ attributeIndex ].toDate() || !mCacheMinValues[ attributeIndex ].isValid() )
720 mCacheMinValues[attributeIndex ] = value;
721 if ( value > mCacheMaxValues[ attributeIndex ].toDate() || !mCacheMaxValues[ attributeIndex ].isValid() )
722 mCacheMaxValues[ attributeIndex ] = value;
723 break;
724 }
725 case QMetaType::Type::QTime:
726 {
727 const QTime value = varValue.toTime();
728 if ( value < mCacheMinValues[ attributeIndex ].toTime() || !mCacheMinValues[ attributeIndex ].isValid() )
729 mCacheMinValues[attributeIndex ] = value;
730 if ( value > mCacheMaxValues[ attributeIndex ].toTime() || !mCacheMaxValues[ attributeIndex ].isValid() )
731 mCacheMaxValues[ attributeIndex ] = value;
732 break;
733 }
734 default:
735 {
736 const QString value = varValue.toString();
737 if ( QgsVariantUtils::isNull( mCacheMinValues[ attributeIndex ] ) || value < mCacheMinValues[attributeIndex ].toString() )
738 {
739 mCacheMinValues[attributeIndex] = value;
740 }
741 if ( QgsVariantUtils::isNull( mCacheMaxValues[attributeIndex] ) || value > mCacheMaxValues[attributeIndex].toString() )
742 {
743 mCacheMaxValues[attributeIndex] = value;
744 }
745 break;
746 }
747 }
748 }
749 }
750
751 mCacheMinMaxDirty = false;
752}
753
754QVariant QgsVectorDataProvider::convertValue( QMetaType::Type type, const QString &value )
755{
756 QVariant v( value );
757
758 if ( !v.convert( type ) || value.isNull() )
760
761 return v;
762}
763
764QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString &value )
765{
767}
768
775
776static bool _compareEncodings( const QString &s1, const QString &s2 )
777{
778 return s1.toLower() < s2.toLower();
779}
780
781static bool _removeDuplicateEncodings( const QString &s1, const QString &s2 )
782{
783 return s1.compare( s2, Qt::CaseInsensitive ) == 0;
784}
785
787{
788 static std::once_flag initialized;
789 std::call_once( initialized, []
790 {
791 const auto codecs { QTextCodec::availableCodecs() };
792 for ( const QByteArray &codec : codecs )
793 {
794 sEncodings << codec;
795 }
796#if 0
797 smEncodings << "BIG5";
798 smEncodings << "BIG5-HKSCS";
799 smEncodings << "EUCJP";
800 smEncodings << "EUCKR";
801 smEncodings << "GB2312";
802 smEncodings << "GBK";
803 smEncodings << "GB18030";
804 smEncodings << "JIS7";
805 smEncodings << "SHIFT-JIS";
806 smEncodings << "TSCII";
807 smEncodings << "UTF-8";
808 smEncodings << "UTF-16";
809 smEncodings << "KOI8-R";
810 smEncodings << "KOI8-U";
811 smEncodings << "ISO8859-1";
812 smEncodings << "ISO8859-2";
813 smEncodings << "ISO8859-3";
814 smEncodings << "ISO8859-4";
815 smEncodings << "ISO8859-5";
816 smEncodings << "ISO8859-6";
817 smEncodings << "ISO8859-7";
818 smEncodings << "ISO8859-8";
819 smEncodings << "ISO8859-8-I";
820 smEncodings << "ISO8859-9";
821 smEncodings << "ISO8859-10";
822 smEncodings << "ISO8859-11";
823 smEncodings << "ISO8859-12";
824 smEncodings << "ISO8859-13";
825 smEncodings << "ISO8859-14";
826 smEncodings << "ISO8859-15";
827 smEncodings << "IBM 850";
828 smEncodings << "IBM 866";
829 smEncodings << "CP874";
830 smEncodings << "CP1250";
831 smEncodings << "CP1251";
832 smEncodings << "CP1252";
833 smEncodings << "CP1253";
834 smEncodings << "CP1254";
835 smEncodings << "CP1255";
836 smEncodings << "CP1256";
837 smEncodings << "CP1257";
838 smEncodings << "CP1258";
839 smEncodings << "Apple Roman";
840 smEncodings << "TIS-620";
841 smEncodings << "System";
842#endif
843
844 // Do case-insensitive sorting of encodings then remove duplicates
845 std::sort( sEncodings.begin(), sEncodings.end(), _compareEncodings );
846 const auto last = std::unique( sEncodings.begin(), sEncodings.end(), _removeDuplicateEncodings );
847 sEncodings.erase( last, sEncodings.end() );
848
849 } );
850
851 return sEncodings;
852}
853
855{
857
858 mErrors.clear();
859}
860
862{
864
865 return !mErrors.isEmpty();
866}
867
869{
871
872 return mErrors;
873}
874
876{
878
879 return nullptr;
880}
881
883{
885
886 return nullptr;
887}
888
889void QgsVectorDataProvider::pushError( const QString &msg ) const
890{
892
893 QgsDebugError( msg );
894 mErrors << msg;
895 emit raiseError( msg );
896}
897
898QSet<QgsMapLayerDependency> QgsVectorDataProvider::dependencies() const
899{
901
902 return QSet<QgsMapLayerDependency>();
903}
904
913
915{
917
918 mNativeTypes = nativeTypes;
919}
920
922{
923 // non fatal for now -- the "rasterize" processing algorithm is not thread safe and calls this
925
926 return mEncoding;
927}
928
930{
931 if ( geometry.isNull() )
932 {
933 return QgsGeometry();
934 }
935
936 const QgsAbstractGeometry *convertedGeometry = geometry.constGet();
937 if ( !convertedGeometry )
938 {
939 return QgsGeometry();
940 }
941
942
943 //geom is already in the provider geometry type
944 if ( convertedGeometry->wkbType() == providerGeometryType )
945 {
946 return QgsGeometry();
947 }
948
949 std::unique_ptr< QgsAbstractGeometry > outputGeom;
950
951 //convert compoundcurve to circularstring (possible if compoundcurve consists of one circular string)
952 if ( QgsWkbTypes::flatType( providerGeometryType ) == Qgis::WkbType::CircularString )
953 {
954 const QgsCompoundCurve *compoundCurve = qgsgeometry_cast<const QgsCompoundCurve *>( convertedGeometry );
955 if ( compoundCurve )
956 {
957 if ( compoundCurve->nCurves() == 1 )
958 {
959 const QgsCircularString *circularString = qgsgeometry_cast<const QgsCircularString *>( compoundCurve->curveAt( 0 ) );
960 if ( circularString )
961 {
962 outputGeom.reset( circularString->clone() );
963 }
964 }
965 }
966 }
967
968 //convert to curved type if necessary
969 if ( !QgsWkbTypes::isCurvedType( convertedGeometry->wkbType() ) && QgsWkbTypes::isCurvedType( providerGeometryType ) )
970 {
971 QgsAbstractGeometry *curveGeom = outputGeom ? outputGeom->toCurveType() : convertedGeometry->toCurveType();
972 if ( curveGeom )
973 {
974 outputGeom.reset( curveGeom );
975 }
976 }
977
978 //convert to linear type from curved type
979 if ( QgsWkbTypes::isCurvedType( convertedGeometry->wkbType() ) && !QgsWkbTypes::isCurvedType( providerGeometryType ) )
980 {
981 QgsAbstractGeometry *segmentizedGeom = outputGeom ? outputGeom->segmentize() : convertedGeometry->segmentize();
982 if ( segmentizedGeom )
983 {
984 outputGeom.reset( segmentizedGeom );
985 }
986 }
987
988 //convert to multitype if necessary
989 if ( QgsWkbTypes::isMultiType( providerGeometryType ) && !QgsWkbTypes::isMultiType( convertedGeometry->wkbType() ) )
990 {
991 std::unique_ptr< QgsAbstractGeometry > collGeom( QgsGeometryFactory::geomFromWkbType( providerGeometryType ) );
992 QgsGeometryCollection *geomCollection = qgsgeometry_cast<QgsGeometryCollection *>( collGeom.get() );
993 if ( geomCollection )
994 {
995 if ( geomCollection->addGeometry( outputGeom ? outputGeom->clone() : convertedGeometry->clone() ) )
996 {
997 outputGeom = std::move( collGeom );
998 }
999 }
1000 }
1001
1002 //convert to single type if there's a single part of compatible type
1003 if ( !QgsWkbTypes::isMultiType( providerGeometryType ) && QgsWkbTypes::isMultiType( convertedGeometry->wkbType() ) )
1004 {
1005 const QgsGeometryCollection *collection = qgsgeometry_cast<const QgsGeometryCollection *>( convertedGeometry );
1006 if ( collection )
1007 {
1008 if ( collection->numGeometries() == 1 )
1009 {
1010 const QgsAbstractGeometry *firstGeom = collection->geometryN( 0 );
1011 if ( firstGeom && firstGeom->wkbType() == providerGeometryType )
1012 {
1013 outputGeom.reset( firstGeom->clone() );
1014 }
1015 }
1016 }
1017 }
1018
1019 //set z/m types
1020 if ( QgsWkbTypes::hasZ( providerGeometryType ) )
1021 {
1022 if ( !outputGeom )
1023 {
1024 outputGeom.reset( convertedGeometry->clone() );
1025 }
1026 outputGeom->addZValue();
1027 }
1028
1029 if ( QgsWkbTypes::hasM( providerGeometryType ) )
1030 {
1031 if ( !outputGeom )
1032 {
1033 outputGeom.reset( convertedGeometry->clone() );
1034 }
1035 outputGeom->addMValue();
1036 }
1037
1038 if ( outputGeom )
1039 {
1040 return QgsGeometry( outputGeom.release() );
1041 }
1042
1043 return QgsGeometry();
1044}
1045
1047{
1049
1050 return false;
1051}
1052
1053QStringList QgsVectorDataProvider::sEncodings;
1054
1055QList<QgsRelation> QgsVectorDataProvider::discoverRelations( const QgsVectorLayer *, const QList<QgsVectorLayer *> & ) const
1056{
1058
1059 return QList<QgsRelation>();
1060}
1061
1067
1074
1081
1088
1090{
1092
1093 return mElevationProperties.get();
1094}
@ SelectAtId
Fast access to features using their ID.
Definition qgis.h:507
@ ChangeFeatures
Supports joint updates for attributes and geometry. Providers supporting this should still define Cha...
Definition qgis.h:515
@ SimplifyGeometries
Supports simplification of geometries on provider side according to a distance tolerance.
Definition qgis.h:511
@ AddFeatures
Allows adding features.
Definition qgis.h:501
@ SimplifyGeometriesWithTopologicalValidation
Supports topological simplification of geometries on provider side according to a distance tolerance.
Definition qgis.h:512
@ CreateAttributeIndex
Can create indexes on provider's fields.
Definition qgis.h:510
@ CircularGeometries
Supports circular geometry types (circularstring, compoundcurve, curvepolygon).
Definition qgis.h:514
@ NoCapabilities
Provider has no capabilities.
Definition qgis.h:500
@ ChangeGeometries
Allows modifications of geometries.
Definition qgis.h:508
@ AddAttributes
Allows addition of new attributes (fields).
Definition qgis.h:504
@ CreateSpatialIndex
Allows creation of spatial index.
Definition qgis.h:506
@ RenameAttributes
Supports renaming attributes (fields).
Definition qgis.h:516
@ DeleteFeatures
Allows deletion of features.
Definition qgis.h:502
@ TransactionSupport
Supports transactions.
Definition qgis.h:513
@ DeleteAttributes
Allows deletion of attributes (fields).
Definition qgis.h:505
@ ChangeAttributeValues
Allows modification of attribute values.
Definition qgis.h:503
@ FeatureSymbology
Provider is able retrieve embedded symbology associated with individual features.
Definition qgis.h:524
QFlags< VectorLayerTypeFlag > VectorLayerTypeFlags
Vector layer type flags.
Definition qgis.h:416
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Definition qgis.h:2196
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:486
FeatureAvailability
Possible return value for QgsFeatureSource::hasFeatures() to determine if a source is empty.
Definition qgis.h:577
@ FeaturesAvailable
There is at least one feature available in this source.
Definition qgis.h:579
@ NoFeaturesAvailable
There are certainly no features available in this source.
Definition qgis.h:578
QFlags< VectorProviderCapability > VectorProviderCapabilities
Vector data provider capabilities.
Definition qgis.h:536
Aggregate
Available aggregates to calculate.
Definition qgis.h:5816
@ SqlQuery
SQL query layer.
Definition qgis.h:412
QFlags< VectorDataProviderAttributeEditCapability > VectorDataProviderAttributeEditCapabilities
Attribute editing capabilities which may be supported by vector data providers.
Definition qgis.h:602
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
@ CircularString
CircularString.
Definition qgis.h:287
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:42
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: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:54
QMetaType::Type type
Definition qgsfield.h:61
QString name
Definition qgsfield.h:63
int precision
Definition qgsfield.h:60
int length
Definition qgsfield.h:59
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())
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:61
#define QgsDebugError(str)
Definition qgslogger.h:57
#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.