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