QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsogrutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsogrutils.h
3 -------------
4 begin : February 2016
5 copyright : (C) 2016 Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSOGRUTILS_H
17#define QGSOGRUTILS_H
18
19#define SIP_NO_FILE
20
21#include "qgis_core.h"
22#include "qgsfeature.h"
24
25#include <ogr_api.h>
26#include <gdal.h>
27#include <gdalwarper.h>
28#include "cpl_conv.h"
29#include "cpl_string.h"
30
32class QgsFieldDomain;
33
34class QTextCodec;
35
36namespace gdal
37{
38
43 {
44
48 void CORE_EXPORT operator()( OGRDataSourceH source ) const;
49
50 };
51
56 {
57
61 void CORE_EXPORT operator()( OGRGeometryH geometry ) const;
62
63 };
64
69 {
70
74 void CORE_EXPORT operator()( OGRFieldDefnH definition ) const;
75
76 };
77
82 {
83
87 void CORE_EXPORT operator()( OGRFeatureH feature ) const;
88
89 };
90
95 {
96
100 void CORE_EXPORT operator()( GDALDatasetH datasource ) const;
101
102 };
103
108 {
109
113 void CORE_EXPORT operator()( GDALWarpOptions *options ) const;
114
115 };
116
120 using ogr_datasource_unique_ptr = std::unique_ptr< std::remove_pointer<OGRDataSourceH>::type, OGRDataSourceDeleter >;
121
125 using ogr_geometry_unique_ptr = std::unique_ptr< std::remove_pointer<OGRGeometryH>::type, OGRGeometryDeleter >;
126
130 using ogr_field_def_unique_ptr = std::unique_ptr< std::remove_pointer<OGRFieldDefnH>::type, OGRFldDeleter >;
131
135 using ogr_feature_unique_ptr = std::unique_ptr< std::remove_pointer<OGRFeatureH>::type, OGRFeatureDeleter >;
136
140 using dataset_unique_ptr = std::unique_ptr< std::remove_pointer<GDALDatasetH>::type, GDALDatasetCloser >;
141
150 void CORE_EXPORT fast_delete_and_close( dataset_unique_ptr &dataset, GDALDriverH driver, const QString &path );
151
155 using warp_options_unique_ptr = std::unique_ptr< GDALWarpOptions, GDALWarpOptionsDeleter >;
156}
157
167class CORE_EXPORT QgsOgrUtils
168{
169 public:
170
175 static QVariant OGRFieldtoVariant( const OGRField *value, OGRFieldType type );
176
182 static std::unique_ptr<OGRField> variantToOGRField( const QVariant &value );
183
191 static QgsFeature readOgrFeature( OGRFeatureH ogrFet, const QgsFields &fields, QTextCodec *encoding );
192
199 static QgsFields readOgrFields( OGRFeatureH ogrFet, QTextCodec *encoding );
200
211 static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsFields &fields, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
212
225 static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField &field, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
226
236 static bool readOgrFeatureAttributes( OGRFeatureH ogrFet, const QgsFields &fields, QgsFeature &feature, QTextCodec *encoding );
237
246 static bool readOgrFeatureGeometry( OGRFeatureH ogrFet, QgsFeature &feature );
247
255 static QgsGeometry ogrGeometryToQgsGeometry( OGRGeometryH geom );
256
266 static QgsFeatureList stringToFeatureList( const QString &string, const QgsFields &fields, QTextCodec *encoding );
267
275 static QgsFields stringToFields( const QString &string, QTextCodec *encoding );
276
282 static QStringList cStringListToQStringList( char **stringList );
283
289 static QgsWkbTypes::Type ogrGeometryTypeToQgsWkbType( OGRwkbGeometryType ogrGeomType );
290
298 static QString OGRSpatialReferenceToWkt( OGRSpatialReferenceH srs );
299
306 static QgsCoordinateReferenceSystem OGRSpatialReferenceToCrs( OGRSpatialReferenceH srs );
307
315 static OGRSpatialReferenceH crsToOGRSpatialReference( const QgsCoordinateReferenceSystem &crs );
316
328 static QString readShapefileEncoding( const QString &path );
329
339 static QString readShapefileEncodingFromCpg( const QString &path );
340
350 static QString readShapefileEncodingFromLdid( const QString &path );
351
357 static QVariantMap parseStyleString( const QString &string );
358
364 static std::unique_ptr< QgsSymbol > symbolFromStyleString( const QString &string, Qgis::SymbolType type ) SIP_FACTORY;
365
377 static void ogrFieldTypeToQVariantType( OGRFieldType ogrType, OGRFieldSubType ogrSubType, QVariant::Type &variantType, QVariant::Type &variantSubType ) SIP_SKIP;
378
389 static void variantTypeToOgrFieldType( QVariant::Type variantType, OGRFieldType &ogrType, OGRFieldSubType &ogrSubType ) SIP_SKIP;
390
398 static QVariant stringToVariant( OGRFieldType type, OGRFieldSubType subType, const QString &string ) SIP_SKIP;
399
405 static QList<QgsVectorDataProvider::NativeType> nativeFieldTypesForDriver( GDALDriverH driver ) SIP_SKIP;
406
407#ifndef SIP_RUN
408#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,3,0)
409
417 static std::unique_ptr< QgsFieldDomain > convertFieldDomain( OGRFieldDomainH domain );
418
426 static OGRFieldDomainH convertFieldDomain( const QgsFieldDomain *domain );
427#endif
428#endif
429};
430
431#endif // QGSOGRUTILS_H
SymbolType
Symbol types.
Definition: qgis.h:206
This class represents a coordinate reference system (CRS).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Base class for field domains.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:51
Container of fields for a vector layer.
Definition: qgsfields.h:45
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
Utilities for working with OGR features and layers.
Definition: qgsogrutils.h:168
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
void CORE_EXPORT fast_delete_and_close(dataset_unique_ptr &dataset, GDALDriverH driver, const QString &path)
Performs a fast close of an unwanted GDAL dataset handle by deleting the underlying data store.
Definition: qgsogrutils.cpp:81
std::unique_ptr< std::remove_pointer< OGRFeatureH >::type, OGRFeatureDeleter > ogr_feature_unique_ptr
Scoped OGR feature.
Definition: qgsogrutils.h:135
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
Definition: qgsogrutils.h:140
std::unique_ptr< std::remove_pointer< OGRDataSourceH >::type, OGRDataSourceDeleter > ogr_datasource_unique_ptr
Scoped OGR data source.
Definition: qgsogrutils.h:120
std::unique_ptr< std::remove_pointer< OGRFieldDefnH >::type, OGRFldDeleter > ogr_field_def_unique_ptr
Scoped OGR field definition.
Definition: qgsogrutils.h:130
std::unique_ptr< std::remove_pointer< OGRGeometryH >::type, OGRGeometryDeleter > ogr_geometry_unique_ptr
Scoped OGR geometry.
Definition: qgsogrutils.h:125
std::unique_ptr< GDALWarpOptions, GDALWarpOptionsDeleter > warp_options_unique_ptr
Scoped GDAL warp options.
Definition: qgsogrutils.h:155
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_FACTORY
Definition: qgis_sip.h:76
void * GDALDatasetH
void * OGRSpatialReferenceH
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:922
const QgsField & field
Definition: qgsfield.h:463
const QgsCoordinateReferenceSystem & crs
Closes and cleanups GDAL dataset.
Definition: qgsogrutils.h:95
void CORE_EXPORT operator()(GDALDatasetH datasource) const
Destroys an gdal dataset, using the correct gdal calls.
Definition: qgsogrutils.cpp:76
Closes and cleanups GDAL warp options.
Definition: qgsogrutils.h:108
void CORE_EXPORT operator()(GDALWarpOptions *options) const
Destroys GDAL warp options, using the correct gdal calls.
Destroys OGR data sources.
Definition: qgsogrutils.h:43
void CORE_EXPORT operator()(OGRDataSourceH source) const
Destroys an OGR data source, using the correct gdal calls.
Definition: qgsogrutils.cpp:55
Destroys OGR feature.
Definition: qgsogrutils.h:82
void CORE_EXPORT operator()(OGRFeatureH feature) const
Destroys an OGR feature, using the correct gdal calls.
Definition: qgsogrutils.cpp:71
Destroys OGR field definition.
Definition: qgsogrutils.h:69
void CORE_EXPORT operator()(OGRFieldDefnH definition) const
Destroys an OGR field definition, using the correct gdal calls.
Definition: qgsogrutils.cpp:66
Destroys OGR geometries.
Definition: qgsogrutils.h:56
void CORE_EXPORT operator()(OGRGeometryH geometry) const
Destroys an OGR geometry, using the correct gdal calls.
Definition: qgsogrutils.cpp:61