QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 QStringList cStringListToQStringList (char **stringList)
 Converts a c string list to a QStringList. More...
 
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. More...
 
static QVariant getOgrFeatureAttribute (OGRFeatureH ogrFet, const QgsFields &fields, int attIndex, QTextCodec *encoding, bool *ok=nullptr)
 Retrieves an attribute value from an OGR feature. More...
 
static QgsGeometry ogrGeometryToQgsGeometry (OGRGeometryH geom)
 Converts an OGR geometry representation to a QgsGeometry object. More...
 
static QgsWkbTypes::Type ogrGeometryTypeToQgsWkbType (OGRwkbGeometryType ogrGeomType)
 Converts a OGRwkbGeometryType to QgsWkbTypes::Type. More...
 
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. More...
 
static QString OGRSpatialReferenceToWkt (OGRSpatialReferenceH srs)
 Returns a WKT string corresponding to the specified OGR srs object. More...
 
static QgsFeature readOgrFeature (OGRFeatureH ogrFet, const QgsFields &fields, QTextCodec *encoding)
 Reads an OGR feature and converts it to a QgsFeature. More...
 
static bool readOgrFeatureAttributes (OGRFeatureH ogrFet, const QgsFields &fields, QgsFeature &feature, QTextCodec *encoding)
 Reads all attributes from an OGR feature into a QgsFeature. More...
 
static bool readOgrFeatureGeometry (OGRFeatureH ogrFet, QgsFeature &feature)
 Reads the geometry from an OGR feature into a QgsFeature. More...
 
static QgsFields readOgrFields (OGRFeatureH ogrFet, QTextCodec *encoding)
 Reads an OGR feature and returns a corresponding fields collection. More...
 
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). More...
 
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. More...
 
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. More...
 
static QgsFeatureList stringToFeatureList (const QString &string, const QgsFields &fields, QTextCodec *encoding)
 Attempts to parse a string representing a collection of features using OGR. More...
 
static QgsFields stringToFields (const QString &string, QTextCodec *encoding)
 Attempts to retrieve the fields from a string representing a collection of features using OGR. More...
 

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
Since
QGIS 2.16

Definition at line 161 of file qgsogrutils.h.

Member Function Documentation

◆ 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 719 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 193 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 180 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 516 of file qgsogrutils.cpp.

◆ ogrGeometryTypeToQgsWkbType()

QgsWkbTypes::Type QgsOgrUtils::ogrGeometryTypeToQgsWkbType ( OGRwkbGeometryType  ogrGeomType)
static

Converts a OGRwkbGeometryType to QgsWkbTypes::Type.

Since
QGIS 3.4.9

Definition at line 430 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 752 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 732 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 96 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 332 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 353 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 121 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 761 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 770 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 826 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 637 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 679 of file qgsogrutils.cpp.


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