27 case QMetaType::Type::Int:
28 return QStringLiteral(
"integer" );
30 case QMetaType::Type::LongLong:
31 return QStringLiteral(
"long" );
33 case QMetaType::Type::Double:
34 return QStringLiteral(
"double" );
36 case QMetaType::Type::QString:
37 return QStringLiteral(
"string" );
39 case QMetaType::Type::QDate:
40 return QStringLiteral(
"date" );
42 case QMetaType::Type::QTime:
43 return QStringLiteral(
"time" );
45 case QMetaType::Type::QDateTime:
46 return QStringLiteral(
"datetime" );
48 case QMetaType::Type::QByteArray:
49 return QStringLiteral(
"binary" );
51 case QMetaType::Type::Bool:
52 return QStringLiteral(
"boolean" );
54 case QMetaType::Type::QVariantMap:
55 return QStringLiteral(
"map" );
57 case QMetaType::Type::User:
58 if ( typeString.compare( QLatin1String(
"geometry" ), Qt::CaseInsensitive ) == 0 )
60 return QStringLiteral(
"geometry" );
67 return QStringLiteral(
"string" );
73 if ( geomType.isNull() )
74 geomType = QStringLiteral(
"none" );
80 parts << QStringLiteral(
"crs=%1" ).arg(
crs.
authid() );
86 parts << QStringLiteral(
"crs=" );
88 for (
const QgsField &field : fields )
90 const QString lengthPrecision = QStringLiteral(
"(%1,%2)" ).arg( field.length() ).arg( field.precision() );
91 parts << QStringLiteral(
"field=%1:%2%3%4" ).arg( QString( QUrl::toPercentEncoding( field.name() ) ),
92 memoryLayerFieldType( field.type() == QMetaType::Type::QVariantList || field.type() == QMetaType::Type::QStringList ? field.subType() : field.type(), field.typeName() ),
94 field.type() == QMetaType::Type::QVariantList || field.type() == QMetaType::Type::QStringList ? QStringLiteral(
"[]" ) : QString() );
97 const QString uri = geomType +
'?' + parts.join(
'&' );
99 options.skipCrsValidation =
true;
100 options.loadDefaultStyle = loadDefaultStyle;
101 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,...
This class 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 data sets.
static 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)
const QgsCoordinateReferenceSystem & crs
Setting options for loading vector layers.