29 case QMetaType::Type::Int:
30 return QStringLiteral(
"integer" );
32 case QMetaType::Type::LongLong:
33 return QStringLiteral(
"long" );
35 case QMetaType::Type::Double:
36 return QStringLiteral(
"double" );
38 case QMetaType::Type::QString:
39 return QStringLiteral(
"string" );
41 case QMetaType::Type::QDate:
42 return QStringLiteral(
"date" );
44 case QMetaType::Type::QTime:
45 return QStringLiteral(
"time" );
47 case QMetaType::Type::QDateTime:
48 return QStringLiteral(
"datetime" );
50 case QMetaType::Type::QByteArray:
51 return QStringLiteral(
"binary" );
53 case QMetaType::Type::Bool:
54 return QStringLiteral(
"boolean" );
56 case QMetaType::Type::QVariantMap:
57 return QStringLiteral(
"map" );
59 case QMetaType::Type::User:
60 if ( typeString.compare( QLatin1String(
"geometry" ), Qt::CaseInsensitive ) == 0 )
62 return QStringLiteral(
"geometry" );
69 return QStringLiteral(
"string" );
75 if ( geomType.isNull() )
76 geomType = QStringLiteral(
"none" );
81 if ( !crs.
authid().isEmpty() )
82 parts << QStringLiteral(
"crs=%1" ).arg( crs.
authid() );
88 parts << QStringLiteral(
"crs=" );
90 for (
const QgsField &field : fields )
92 const QString lengthPrecision = QStringLiteral(
"(%1,%2)" ).arg( field.length() ).arg( field.precision() );
93 parts << QStringLiteral(
"field=%1:%2%3%4" ).arg( QString( QUrl::toPercentEncoding( field.name() ) ),
94 memoryLayerFieldType( field.type() == QMetaType::Type::QVariantList || field.type() == QMetaType::Type::QStringList ? field.subType() : field.type(), field.typeName() ),
96 field.type() == QMetaType::Type::QVariantList || field.type() == QMetaType::Type::QStringList ? QStringLiteral(
"[]" ) : QString() );
99 const QString uri = geomType +
'?' + parts.join(
'&' );
103 return new QgsVectorLayer( uri, name, QStringLiteral(
"memory" ), options );
WkbType
The WKB type describes the number of dimensions a geometry has.
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Contains information about the context in which a coordinate transform is executed.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
static QgsVectorLayer * createMemoryLayer(const QString &name, const QgsFields &fields, Qgis::WkbType geometryType=Qgis::WkbType::NoGeometry, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), bool loadDefaultStyle=true) SIP_FACTORY
Creates a new memory layer using the specified parameters.
Represents a vector layer which manages a vector based dataset.
static Q_INVOKABLE QString displayString(Qgis::WkbType type)
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
QString memoryLayerFieldType(QMetaType::Type type, const QString &typeString)
Setting options for loading vector layers.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.