QgsOgrUtils class
Utilities for working with OGR features and layers.
Contents
- Reference
Contains helper utilities for assisting work with both OGR features and layers.
Public static functions
- static auto cStringListToQStringList(char** stringList) -> QStringList
- Converts a c string list to a QStringList.
- static auto getOgrFeatureAttribute(OGRFeatureH ogrFet, const QgsFields& fields, int attIndex, QTextCodec* encoding, bool* ok = nullptr) -> QVariant
- Retrieves an attribute value from an OGR feature.
- static auto ogrGeometryToQgsGeometry(OGRGeometryH geom) -> QgsGeometry
- Converts an OGR geometry representation to a QgsGeometry object.
- static auto readOgrFeature(OGRFeatureH ogrFet, const QgsFields& fields, QTextCodec* encoding) -> QgsFeature
- Reads an OGR feature and converts it to a QgsFeature.
- static auto readOgrFeatureAttributes(OGRFeatureH ogrFet, const QgsFields& fields, QgsFeature& feature, QTextCodec* encoding) -> bool
- Reads all attributes from an OGR feature into a QgsFeature.
- static auto readOgrFeatureGeometry(OGRFeatureH ogrFet, QgsFeature& feature) -> bool
- Reads the geometry from an OGR feature into a QgsFeature.
- static auto readOgrFields(OGRFeatureH ogrFet, QTextCodec* encoding) -> QgsFields
- Reads an OGR feature and returns a corresponding fields collection.
- static auto stringToFeatureList(const QString& string, const QgsFields& fields, QTextCodec* encoding) -> QgsFeatureList
- Attempts to parse a string representing a collection of features using OGR.
- static auto stringToFields(const QString& string, QTextCodec* encoding) -> QgsFields
- Attempts to retrieve the fields from a string representing a collection of features using OGR.
Function documentation
static QStringList QgsOgrUtils:: cStringListToQStringList(char** stringList)
Converts a c string list to a QStringList.
Presumes a null terminated string list.
static QVariant QgsOgrUtils:: getOgrFeatureAttribute(OGRFeatureH ogrFet,
const QgsFields& fields,
int attIndex,
QTextCodec* encoding,
bool* ok = nullptr)
Retrieves an attribute value from an OGR feature.
| Parameters | |
|---|---|
| ogrFet | OGR feature handle |
| fields | fields collection corresponding to feature |
| attIndex | index of attribute to retrieve |
| encoding | text encoding |
| ok | optional storage for success of retrieval |
| Returns | attribute converted to a QVariant object |
static QgsGeometry QgsOgrUtils:: ogrGeometryToQgsGeometry(OGRGeometryH geom)
Converts an OGR geometry representation to a QgsGeometry object.
| Parameters | |
|---|---|
| geom | OGR geometry handle |
| Returns | QgsGeometry object. If conversion was not successful the geometry will be empty. |
static QgsFeature QgsOgrUtils:: readOgrFeature(OGRFeatureH ogrFet,
const QgsFields& fields,
QTextCodec* encoding)
Reads an OGR feature and converts it to a QgsFeature.
| Parameters | |
|---|---|
| ogrFet | OGR feature handle |
| fields | fields collection corresponding to feature |
| encoding | text encoding |
| Returns | valid feature if read was successful |
static bool QgsOgrUtils:: readOgrFeatureAttributes(OGRFeatureH ogrFet,
const QgsFields& fields,
QgsFeature& feature,
QTextCodec* encoding)
Reads all attributes from an OGR feature into a QgsFeature.
| Parameters | |
|---|---|
| ogrFet | OGR feature handle |
| fields | fields collection corresponding to feature |
| feature | QgsFeature to store attributes in |
| encoding | text encoding |
| Returns | true if attribute read was successful |
static bool QgsOgrUtils:: readOgrFeatureGeometry(OGRFeatureH ogrFet,
QgsFeature& feature)
Reads the geometry from an OGR feature into a QgsFeature.
| Parameters | |
|---|---|
| ogrFet | OGR feature handle |
| feature | QgsFeature to store geometry in |
| Returns | true if geometry read was successful |
static QgsFields QgsOgrUtils:: readOgrFields(OGRFeatureH ogrFet,
QTextCodec* encoding)
Reads an OGR feature and returns a corresponding fields collection.
| Parameters | |
|---|---|
| ogrFet | OGR feature handle |
| encoding | text encoding |
| Returns | fields collection if read was successful |
static QgsFeatureList QgsOgrUtils:: stringToFeatureList(const QString& string,
const QgsFields& fields,
QTextCodec* encoding)
Attempts to parse a string representing a collection of features using OGR.
| Parameters | |
|---|---|
| string | string to parse |
| fields | fields collection to use for parsed features ( |
| encoding | text encoding |
| Returns | list of parsed features, or an empty list if no features could be parsed |
For example, this method can be used to convert a GeoJSON encoded collection to a list of QgsFeatures.
static QgsFields QgsOgrUtils:: stringToFields(const QString& string,
QTextCodec* encoding)
Attempts to retrieve the fields from a string representing a collection of features using OGR.
| Parameters | |
|---|---|
| string | string to parse |
| encoding | text encoding |
| Returns | retrieved fields collection, or an empty list if no fields could be determined from the string |