QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
QgsOgrUtils Class Reference

Utilities for working with OGR features and layers. More...

#include <qgsogrutils.h>

Static Public Member Functions

static OGRFieldDomainH convertFieldDomain (const QgsFieldDomain *domain)
 Converts a QGIS field domain definition to an OGR field domain equivalent.
 
static std::unique_ptr< QgsFieldDomainconvertFieldDomain (OGRFieldDomainH domain)
 Converts an OGR field domain definition to a QgsFieldDomain equivalent.
 
static gdal::relationship_unique_ptr convertRelationship (const QgsWeakRelation &relation, QString &error)
 Converts a QGIS relation to a GDAL relationship equivalent.
 
static QgsWeakRelation convertRelationship (GDALRelationshipH relationship, const QString &datasetUri)
 Converts an GDAL relationship definition to a QgsWeakRelation equivalent.
 
static OGRSpatialReferenceH crsToOGRSpatialReference (const QgsCoordinateReferenceSystem &crs)
 Returns a OGRSpatialReferenceH corresponding to the specified crs object.
 
static QStringList cStringListToQStringList (char **stringList)
 Converts a c string list to a QStringList.
 
static bool deleteStyleById (GDALDatasetH hDS, const QString &styleId, QString &errCause)
 Helper function for deleting a style by id from ogr/gdal database datasources.
 
static QVariant getOgrFeatureAttribute (OGRFeatureH ogrFet, const QgsField &field, int attIndex, QTextCodec *encoding, bool *ok=nullptr)
 Retrieves an attribute value from an OGR feature, using a provided field definition.
 
static QVariant getOgrFeatureAttribute (OGRFeatureH ogrFet, const QgsFields &fields, int attIndex, QTextCodec *encoding, bool *ok=nullptr)
 Retrieves an attribute value from an OGR feature.
 
static QString getStyleById (GDALDatasetH hDS, const QString &styleId, QString &errCause)
 Helper function for getting a style by ID from ogr/gdal database datasources.
 
static int listStyles (GDALDatasetH hDS, const QString &layerName, const QString &geomColumn, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause)
 Helper function for listing styles in ogr/gdal database datasources.
 
static QString loadStoredStyle (GDALDatasetH hDS, const QString &layerName, const QString &geomColumn, QString &styleName, QString &errCause)
 Helper function for loading a stored styles in ogr/gdal database datasources.
 
static QList< QgsVectorDataProvider::NativeTypenativeFieldTypesForDriver (GDALDriverH driver)
 Returns the list of native field types supported for a driver.
 
static QVariant OGRFieldtoVariant (const OGRField *value, OGRFieldType type)
 Converts an OGRField value of the specified type into a QVariant.
 
static void ogrFieldTypeToQVariantType (OGRFieldType ogrType, OGRFieldSubType ogrSubType, QMetaType::Type &variantType, QMetaType::Type &variantSubType)
 Converts an OGR field type and sub type to the best matching QVariant::Type equivalent.
 
static QgsGeometry ogrGeometryToQgsGeometry (OGRGeometryH geom)
 Converts an OGR geometry representation to a QgsGeometry object.
 
static Qgis::WkbType ogrGeometryTypeToQgsWkbType (OGRwkbGeometryType ogrGeomType)
 Converts a OGRwkbGeometryType to QgsWkbTypes::Type.
 
static QgsCoordinateReferenceSystem OGRSpatialReferenceToCrs (OGRSpatialReferenceH srs)
 Returns a QgsCoordinateReferenceSystem corresponding to the specified OGR srs object, or an invalid QgsCoordinateReferenceSystem if srs could not be converted.
 
static QString OGRSpatialReferenceToWkt (OGRSpatialReferenceH srs)
 Returns a WKT string corresponding to the specified OGR srs object.
 
static int OGRTZFlagFromQt (const QDateTime &datetime)
 Gets the value of OGRField::Date::TZFlag from the timezone of a QDateTime.
 
static QVariantMap parseStyleString (const QString &string)
 Parses an OGR style string to a variant map containing the style string components.
 
static QgsFeature readOgrFeature (OGRFeatureH ogrFet, const QgsFields &fields, QTextCodec *encoding)
 Reads an OGR feature and converts it to a QgsFeature.
 
static bool readOgrFeatureAttributes (OGRFeatureH ogrFet, const QgsFields &fields, QgsFeature &feature, QTextCodec *encoding)
 Reads all attributes from an OGR feature into a QgsFeature.
 
static bool readOgrFeatureGeometry (OGRFeatureH ogrFet, QgsFeature &feature)
 Reads the geometry from an OGR feature into a QgsFeature.
 
static QgsFields readOgrFields (OGRFeatureH ogrFet, QTextCodec *encoding)
 Reads an OGR feature and returns a corresponding fields collection.
 
static QString readShapefileEncoding (const QString &path)
 Reads the encoding of the shapefile at the specified path (where path is the location of the ".shp" file).
 
static QString readShapefileEncodingFromCpg (const QString &path)
 Reads the encoding of the shapefile at the specified path (where path is the location of the ".shp" file), from the CPG specified encoding.
 
static QString readShapefileEncodingFromLdid (const QString &path)
 Reads the encoding of the shapefile at the specified path (where path is the location of the ".shp" file), from the DBF LDID encoding.
 
static bool saveStyle (GDALDatasetH hDS, const QString &layerName, const QString &geomColumn, const QString &qmlStyle, const QString &sldStyle, const QString &styleName, const QString &styleDescription, const QString &uiFileContent, bool useAsDefault, QString &errCause)
 Helper function for saving a style to ogr/gdal database datasources.
 
static QgsFeatureList stringToFeatureList (const QString &string, const QgsFields &fields, QTextCodec *encoding)
 Attempts to parse a string representing a collection of features using OGR.
 
static QgsFields stringToFields (const QString &string, QTextCodec *encoding)
 Attempts to retrieve the fields from a string representing a collection of features using OGR.
 
static QVariant stringToVariant (OGRFieldType type, OGRFieldSubType subType, const QString &string)
 Converts a string to a variant, using the provider OGR field type and subType to determine the most appropriate variant type.
 
static bool styleExists (GDALDatasetH hDS, const QString &layerName, const QString &geomColumn, const QString &styleId, QString &errorCause)
 Helper function for checking whether a style exists in ogr/gdal database datasources.
 
static std::unique_ptr< QgsSymbolsymbolFromStyleString (const QString &string, Qgis::SymbolType type)
 Creates a new QgsSymbol matching an OGR style string.
 
static std::unique_ptr< OGRField > variantToOGRField (const QVariant &value, OGRFieldType type)
 Converts a QVariant to an OGRField value of specified type.
 
static void variantTypeToOgrFieldType (QMetaType::Type variantType, OGRFieldType &ogrType, OGRFieldSubType &ogrSubType)
 Converts an QVariant type to the best matching OGR field type and sub type.
 

Detailed Description

Utilities for working with OGR features and layers.

Contains helper utilities for assisting work with both OGR features and layers.

Note
not available in Python bindings

Definition at line 191 of file qgsogrutils.h.

Member Function Documentation

◆ convertFieldDomain() [1/2]

OGRFieldDomainH QgsOgrUtils::convertFieldDomain ( const QgsFieldDomain domain)
static

Converts a QGIS field domain definition to an OGR field domain equivalent.

Note
Requires GDAL >= 3.3
Not available in Python bindings
Since
QGIS 3.26

Definition at line 2272 of file qgsogrutils.cpp.

◆ convertFieldDomain() [2/2]

std::unique_ptr< QgsFieldDomain > QgsOgrUtils::convertFieldDomain ( OGRFieldDomainH  domain)
static

Converts an OGR field domain definition to a QgsFieldDomain equivalent.

Note
Requires GDAL >= 3.3
Not available in Python bindings
Since
QGIS 3.26

Definition at line 2179 of file qgsogrutils.cpp.

◆ convertRelationship() [1/2]

gdal::relationship_unique_ptr QgsOgrUtils::convertRelationship ( const QgsWeakRelation relation,
QString &  error 
)
static

Converts a QGIS relation to a GDAL relationship equivalent.

Note
Requires GDAL >= 3.6
Not available in Python bindings
Since
QGIS 3.30

Definition at line 2508 of file qgsogrutils.cpp.

◆ convertRelationship() [2/2]

QgsWeakRelation QgsOgrUtils::convertRelationship ( GDALRelationshipH  relationship,
const QString &  datasetUri 
)
static

Converts an GDAL relationship definition to a QgsWeakRelation equivalent.

Note
Requires GDAL >= 3.6
Not available in Python bindings
Since
QGIS 3.30

Definition at line 2384 of file qgsogrutils.cpp.

◆ crsToOGRSpatialReference()

OGRSpatialReferenceH QgsOgrUtils::crsToOGRSpatialReference ( const QgsCoordinateReferenceSystem crs)
static

Returns a OGRSpatialReferenceH corresponding to the specified crs object.

Note
Caller must release the returned object with OSRRelease.
Since
QGIS 3.22

Definition at line 1236 of file qgsogrutils.cpp.

◆ cStringListToQStringList()

QStringList QgsOgrUtils::cStringListToQStringList ( char **  stringList)
static

Converts a c string list to a QStringList.

Presumes a null terminated string list.

Since
QGIS 3.2

Definition at line 1172 of file qgsogrutils.cpp.

◆ deleteStyleById()

bool QgsOgrUtils::deleteStyleById ( GDALDatasetH  hDS,
const QString &  styleId,
QString &  errCause 
)
static

Helper function for deleting a style by id from ogr/gdal database datasources.

Since
QGIS 3.34

Definition at line 2819 of file qgsogrutils.cpp.

◆ getOgrFeatureAttribute() [1/2]

QVariant QgsOgrUtils::getOgrFeatureAttribute ( OGRFeatureH  ogrFet,
const QgsField field,
int  attIndex,
QTextCodec *  encoding,
bool *  ok = nullptr 
)
static

Retrieves an attribute value from an OGR feature, using a provided field definition.

Parameters
ogrFetOGR feature handle
fielddefinition of corresponding field
attIndexindex of attribute to retrieve from ogrFet
encodingtext encoding
okoptional storage for success of retrieval
Returns
attribute converted to a QVariant object
See also
readOgrFeatureAttributes()
Since
QGIS 3.10.1

Definition at line 519 of file qgsogrutils.cpp.

◆ getOgrFeatureAttribute() [2/2]

QVariant QgsOgrUtils::getOgrFeatureAttribute ( OGRFeatureH  ogrFet,
const QgsFields fields,
int  attIndex,
QTextCodec *  encoding,
bool *  ok = nullptr 
)
static

Retrieves an attribute value from an OGR feature.

Parameters
ogrFetOGR feature handle
fieldsfields collection corresponding to feature
attIndexindex of attribute to retrieve
encodingtext encoding
okoptional storage for success of retrieval
Returns
attribute converted to a QVariant object
See also
readOgrFeatureAttributes()

Definition at line 506 of file qgsogrutils.cpp.

◆ getStyleById()

QString QgsOgrUtils::getStyleById ( GDALDatasetH  hDS,
const QString &  styleId,
QString &  errCause 
)
static

Helper function for getting a style by ID from ogr/gdal database datasources.

Since
QGIS 3.34

Definition at line 2785 of file qgsogrutils.cpp.

◆ listStyles()

int QgsOgrUtils::listStyles ( GDALDatasetH  hDS,
const QString &  layerName,
const QString &  geomColumn,
QStringList &  ids,
QStringList &  names,
QStringList &  descriptions,
QString &  errCause 
)
static

Helper function for listing styles in ogr/gdal database datasources.

Since
QGIS 3.34

Definition at line 2667 of file qgsogrutils.cpp.

◆ loadStoredStyle()

QString QgsOgrUtils::loadStoredStyle ( GDALDatasetH  hDS,
const QString &  layerName,
const QString &  geomColumn,
QString &  styleName,
QString &  errCause 
)
static

Helper function for loading a stored styles in ogr/gdal database datasources.

Since
QGIS 3.34

Definition at line 2846 of file qgsogrutils.cpp.

◆ nativeFieldTypesForDriver()

QList< QgsVectorDataProvider::NativeType > QgsOgrUtils::nativeFieldTypesForDriver ( GDALDriverH  driver)
static

Returns the list of native field types supported for a driver.

Since
QGIS 3.28

Definition at line 2059 of file qgsogrutils.cpp.

◆ OGRFieldtoVariant()

QVariant QgsOgrUtils::OGRFieldtoVariant ( const OGRField *  value,
OGRFieldType  type 
)
static

Converts an OGRField value of the specified type into a QVariant.

Since
QGIS 3.20

Definition at line 144 of file qgsogrutils.cpp.

◆ ogrFieldTypeToQVariantType()

void QgsOgrUtils::ogrFieldTypeToQVariantType ( OGRFieldType  ogrType,
OGRFieldSubType  ogrSubType,
QMetaType::Type &  variantType,
QMetaType::Type &  variantSubType 
)
static

Converts an OGR field type and sub type to the best matching QVariant::Type equivalent.

Parameters
ogrTypeOGR field type
ogrSubTypeOGR field sub type
variantTypewill be set to matching QVariant type
variantSubTypewill be set to matching QVariant sub type, for list, map and other complex OGR field types.
Note
Not available in Python bindings
Since
QGIS 3.26

Definition at line 1883 of file qgsogrutils.cpp.

◆ ogrGeometryToQgsGeometry()

QgsGeometry QgsOgrUtils::ogrGeometryToQgsGeometry ( OGRGeometryH  geom)
static

Converts an OGR geometry representation to a QgsGeometry object.

Parameters
geomOGR geometry handle
Returns
QgsGeometry object. If conversion was not successful the geometry will be empty.
See also
readOgrFeatureGeometry()

Definition at line 961 of file qgsogrutils.cpp.

◆ ogrGeometryTypeToQgsWkbType()

Qgis::WkbType QgsOgrUtils::ogrGeometryTypeToQgsWkbType ( OGRwkbGeometryType  ogrGeomType)
static

Converts a OGRwkbGeometryType to QgsWkbTypes::Type.

Since
QGIS 3.4.9

Definition at line 875 of file qgsogrutils.cpp.

◆ OGRSpatialReferenceToCrs()

QgsCoordinateReferenceSystem QgsOgrUtils::OGRSpatialReferenceToCrs ( OGRSpatialReferenceH  srs)
static

Returns a QgsCoordinateReferenceSystem corresponding to the specified OGR srs object, or an invalid QgsCoordinateReferenceSystem if srs could not be converted.

Since
QGIS 3.10.1

Definition at line 1203 of file qgsogrutils.cpp.

◆ OGRSpatialReferenceToWkt()

QString QgsOgrUtils::OGRSpatialReferenceToWkt ( OGRSpatialReferenceH  srs)
static

Returns a WKT string corresponding to the specified OGR srs object.

The WKT string format will be selected using the most appropriate format (usually WKT2 if GDAL 3 is available).

Since
QGIS 3.10.1

Definition at line 1187 of file qgsogrutils.cpp.

◆ OGRTZFlagFromQt()

int QgsOgrUtils::OGRTZFlagFromQt ( const QDateTime &  datetime)
static

Gets the value of OGRField::Date::TZFlag from the timezone of a QDateTime.

Since
QGIS 3.30

Definition at line 229 of file qgsogrutils.cpp.

◆ parseStyleString()

QVariantMap QgsOgrUtils::parseStyleString ( const QString &  string)
static

Parses an OGR style string to a variant map containing the style string components.

Since
QGIS 3.20

Definition at line 1317 of file qgsogrutils.cpp.

◆ readOgrFeature()

QgsFeature QgsOgrUtils::readOgrFeature ( OGRFeatureH  ogrFet,
const QgsFields fields,
QTextCodec *  encoding 
)
static

Reads an OGR feature and converts it to a QgsFeature.

Parameters
ogrFetOGR feature handle
fieldsfields collection corresponding to feature
encodingtext encoding
Returns
valid feature if read was successful

Definition at line 424 of file qgsogrutils.cpp.

◆ readOgrFeatureAttributes()

bool QgsOgrUtils::readOgrFeatureAttributes ( OGRFeatureH  ogrFet,
const QgsFields fields,
QgsFeature feature,
QTextCodec *  encoding 
)
static

Reads all attributes from an OGR feature into a QgsFeature.

Parameters
ogrFetOGR feature handle
fieldsfields collection corresponding to feature
featureQgsFeature to store attributes in
encodingtext encoding
Returns
true if attribute read was successful
See also
getOgrFeatureAttribute()

Definition at line 745 of file qgsogrutils.cpp.

◆ readOgrFeatureGeometry()

bool QgsOgrUtils::readOgrFeatureGeometry ( OGRFeatureH  ogrFet,
QgsFeature feature 
)
static

Reads the geometry from an OGR feature into a QgsFeature.

Parameters
ogrFetOGR feature handle
featureQgsFeature to store geometry in
Returns
true if geometry read was successful
See also
readOgrFeatureAttributes()
ogrGeometryToQgsGeometry()

Definition at line 766 of file qgsogrutils.cpp.

◆ readOgrFields()

QgsFields QgsOgrUtils::readOgrFields ( OGRFeatureH  ogrFet,
QTextCodec *  encoding 
)
static

Reads an OGR feature and returns a corresponding fields collection.

Parameters
ogrFetOGR feature handle
encodingtext encoding
Returns
fields collection if read was successful

Definition at line 449 of file qgsogrutils.cpp.

◆ readShapefileEncoding()

QString QgsOgrUtils::readShapefileEncoding ( const QString &  path)
static

Reads the encoding of the shapefile at the specified path (where path is the location of the ".shp" file).

This method considers both the CPG specified encoding and the DBF LDID encoding (priority goes to CPG based encoding)

See also
readShapefileEncodingFromCpg()
readShapefileEncodingFromLdid()
Since
QGIS 3.12

Definition at line 1294 of file qgsogrutils.cpp.

◆ readShapefileEncodingFromCpg()

QString QgsOgrUtils::readShapefileEncodingFromCpg ( const QString &  path)
static

Reads the encoding of the shapefile at the specified path (where path is the location of the ".shp" file), from the CPG specified encoding.

Return an empty string if CPG based encoding was not found.

See also
readShapefileEncoding()
Since
QGIS 3.12

Definition at line 1303 of file qgsogrutils.cpp.

◆ readShapefileEncodingFromLdid()

QString QgsOgrUtils::readShapefileEncodingFromLdid ( const QString &  path)
static

Reads the encoding of the shapefile at the specified path (where path is the location of the ".shp" file), from the DBF LDID encoding.

Return an empty string if LDID based encoding was not found.

See also
readShapefileEncoding()
Since
QGIS 3.12

Definition at line 1310 of file qgsogrutils.cpp.

◆ saveStyle()

bool QgsOgrUtils::saveStyle ( GDALDatasetH  hDS,
const QString &  layerName,
const QString &  geomColumn,
const QString &  qmlStyle,
const QString &  sldStyle,
const QString &  styleName,
const QString &  styleDescription,
const QString &  uiFileContent,
bool  useAsDefault,
QString &  errCause 
)
static

Helper function for saving a style to ogr/gdal database datasources.

Since
QGIS 3.34

Definition at line 2901 of file qgsogrutils.cpp.

◆ stringToFeatureList()

QgsFeatureList QgsOgrUtils::stringToFeatureList ( const QString &  string,
const QgsFields fields,
QTextCodec *  encoding 
)
static

Attempts to parse a string representing a collection of features using OGR.

For example, this method can be used to convert a GeoJSON encoded collection to a list of QgsFeatures.

Parameters
stringstring to parse
fieldsfields collection to use for parsed features (
See also
stringToFields())
Parameters
encodingtext encoding
Returns
list of parsed features, or an empty list if no features could be parsed
See also
stringToFields()

Definition at line 1090 of file qgsogrutils.cpp.

◆ stringToFields()

QgsFields QgsOgrUtils::stringToFields ( const QString &  string,
QTextCodec *  encoding 
)
static

Attempts to retrieve the fields from a string representing a collection of features using OGR.

Parameters
stringstring to parse
encodingtext encoding
Returns
retrieved fields collection, or an empty list if no fields could be determined from the string
See also
stringToFeatureList()

Definition at line 1132 of file qgsogrutils.cpp.

◆ stringToVariant()

QVariant QgsOgrUtils::stringToVariant ( OGRFieldType  type,
OGRFieldSubType  subType,
const QString &  string 
)
static

Converts a string to a variant, using the provider OGR field type and subType to determine the most appropriate variant type.

Note
Not available in Python bindings
Since
QGIS 3.26

Definition at line 2008 of file qgsogrutils.cpp.

◆ styleExists()

bool QgsOgrUtils::styleExists ( GDALDatasetH  hDS,
const QString &  layerName,
const QString &  geomColumn,
const QString &  styleId,
QString &  errorCause 
)
static

Helper function for checking whether a style exists in ogr/gdal database datasources.

Since
QGIS 3.34

Definition at line 2756 of file qgsogrutils.cpp.

◆ symbolFromStyleString()

std::unique_ptr< QgsSymbol > QgsOgrUtils::symbolFromStyleString ( const QString &  string,
Qgis::SymbolType  type 
)
static

Creates a new QgsSymbol matching an OGR style string.

Since
QGIS 3.20

Definition at line 1364 of file qgsogrutils.cpp.

◆ variantToOGRField()

std::unique_ptr< OGRField > QgsOgrUtils::variantToOGRField ( const QVariant &  value,
OGRFieldType  type 
)
static

Converts a QVariant to an OGRField value of specified type.

Returns nullptr in case of error

Since
QGIS 3.26

Definition at line 236 of file qgsogrutils.cpp.

◆ variantTypeToOgrFieldType()

void QgsOgrUtils::variantTypeToOgrFieldType ( QMetaType::Type  variantType,
OGRFieldType &  ogrType,
OGRFieldSubType &  ogrSubType 
)
static

Converts an QVariant type to the best matching OGR field type and sub type.

Parameters
variantTypeQVariant field type
ogrTypewill be set to matching OGR type
ogrSubTypewill be set to matching OGR sub type
Note
Not available in Python bindings
Since
QGIS 3.26

Definition at line 1956 of file qgsogrutils.cpp.


The documentation for this class was generated from the following files: