QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
23 
24 #include <ogr_api.h>
25 #include <gdal.h>
26 #include <gdalwarper.h>
27 #include "cpl_conv.h"
28 #include "cpl_string.h"
29 
31 class QgsFieldDomain;
32 
33 class QTextCodec;
34 
35 namespace gdal
36 {
37 
42  {
43 
47  void CORE_EXPORT operator()( OGRDataSourceH source ) const;
48 
49  };
50 
55  {
56 
60  void CORE_EXPORT operator()( OGRGeometryH geometry ) const;
61 
62  };
63 
68  {
69 
73  void CORE_EXPORT operator()( OGRFieldDefnH definition ) const;
74 
75  };
76 
81  {
82 
86  void CORE_EXPORT operator()( OGRFeatureH feature ) const;
87 
88  };
89 
94  {
95 
99  void CORE_EXPORT operator()( GDALDatasetH datasource ) const;
100 
101  };
102 
107  {
108 
112  void CORE_EXPORT operator()( GDALWarpOptions *options ) const;
113 
114  };
115 
119  using ogr_datasource_unique_ptr = std::unique_ptr< std::remove_pointer<OGRDataSourceH>::type, OGRDataSourceDeleter >;
120 
124  using ogr_geometry_unique_ptr = std::unique_ptr< std::remove_pointer<OGRGeometryH>::type, OGRGeometryDeleter >;
125 
129  using ogr_field_def_unique_ptr = std::unique_ptr< std::remove_pointer<OGRFieldDefnH>::type, OGRFldDeleter >;
130 
134  using ogr_feature_unique_ptr = std::unique_ptr< std::remove_pointer<OGRFeatureH>::type, OGRFeatureDeleter >;
135 
139  using dataset_unique_ptr = std::unique_ptr< std::remove_pointer<GDALDatasetH>::type, GDALDatasetCloser >;
140 
149  void CORE_EXPORT fast_delete_and_close( dataset_unique_ptr &dataset, GDALDriverH driver, const QString &path );
150 
154  using warp_options_unique_ptr = std::unique_ptr< GDALWarpOptions, GDALWarpOptionsDeleter >;
155 }
156 
166 class CORE_EXPORT QgsOgrUtils
167 {
168  public:
169 
174  static QVariant OGRFieldtoVariant( const OGRField *value, OGRFieldType type );
175 
181  static std::unique_ptr<OGRField> variantToOGRField( const QVariant &value );
182 
190  static QgsFeature readOgrFeature( OGRFeatureH ogrFet, const QgsFields &fields, QTextCodec *encoding );
191 
198  static QgsFields readOgrFields( OGRFeatureH ogrFet, QTextCodec *encoding );
199 
210  static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsFields &fields, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
211 
224  static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField &field, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
225 
235  static bool readOgrFeatureAttributes( OGRFeatureH ogrFet, const QgsFields &fields, QgsFeature &feature, QTextCodec *encoding );
236 
245  static bool readOgrFeatureGeometry( OGRFeatureH ogrFet, QgsFeature &feature );
246 
254  static QgsGeometry ogrGeometryToQgsGeometry( OGRGeometryH geom );
255 
265  static QgsFeatureList stringToFeatureList( const QString &string, const QgsFields &fields, QTextCodec *encoding );
266 
274  static QgsFields stringToFields( const QString &string, QTextCodec *encoding );
275 
281  static QStringList cStringListToQStringList( char **stringList );
282 
288  static QgsWkbTypes::Type ogrGeometryTypeToQgsWkbType( OGRwkbGeometryType ogrGeomType );
289 
297  static QString OGRSpatialReferenceToWkt( OGRSpatialReferenceH srs );
298 
305  static QgsCoordinateReferenceSystem OGRSpatialReferenceToCrs( OGRSpatialReferenceH srs );
306 
314  static OGRSpatialReferenceH crsToOGRSpatialReference( const QgsCoordinateReferenceSystem &crs );
315 
327  static QString readShapefileEncoding( const QString &path );
328 
338  static QString readShapefileEncodingFromCpg( const QString &path );
339 
349  static QString readShapefileEncodingFromLdid( const QString &path );
350 
356  static QVariantMap parseStyleString( const QString &string );
357 
363  static std::unique_ptr< QgsSymbol > symbolFromStyleString( const QString &string, Qgis::SymbolType type ) SIP_FACTORY;
364 
376  static void ogrFieldTypeToQVariantType( OGRFieldType ogrType, OGRFieldSubType ogrSubType, QVariant::Type &variantType, QVariant::Type &variantSubType ) SIP_SKIP;
377 
388  static void variantTypeToOgrFieldType( QVariant::Type variantType, OGRFieldType &ogrType, OGRFieldSubType &ogrSubType ) SIP_SKIP;
389 
397  static QVariant stringToVariant( OGRFieldType type, OGRFieldSubType subType, const QString &string ) SIP_SKIP;
398 
399 #ifndef SIP_RUN
400 #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,3,0)
401 
409  static std::unique_ptr< QgsFieldDomain > convertFieldDomain( OGRFieldDomainH domain );
410 
418  static OGRFieldDomainH convertFieldDomain( const QgsFieldDomain *domain );
419 #endif
420 #endif
421 };
422 
423 #endif // QGSOGRUTILS_H
gdal::ogr_feature_unique_ptr
std::unique_ptr< std::remove_pointer< OGRFeatureH >::type, OGRFeatureDeleter > ogr_feature_unique_ptr
Scoped OGR feature.
Definition: qgsogrutils.h:134
gdal::OGRDataSourceDeleter
Destroys OGR data sources.
Definition: qgsogrutils.h:41
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
gdal::ogr_datasource_unique_ptr
std::unique_ptr< std::remove_pointer< OGRDataSourceH >::type, OGRDataSourceDeleter > ogr_datasource_unique_ptr
Scoped OGR data source.
Definition: qgsogrutils.h:119
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
gdal::ogr_field_def_unique_ptr
std::unique_ptr< std::remove_pointer< OGRFieldDefnH >::type, OGRFldDeleter > ogr_field_def_unique_ptr
Scoped OGR field definition.
Definition: qgsogrutils.h:129
qgsfeature.h
gdal
Definition: qgsogrutils.h:35
gdal::GDALDatasetCloser
Closes and cleanups GDAL dataset.
Definition: qgsogrutils.h:93
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
field
const QgsField & field
Definition: qgsfield.h:463
gdal::OGRFeatureDeleter
Destroys OGR feature.
Definition: qgsogrutils.h:80
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
gdal::OGRFeatureDeleter::operator()
void CORE_EXPORT operator()(OGRFeatureH feature) const
Destroys an OGR feature, using the correct gdal calls.
Definition: qgsogrutils.cpp:69
OGRSpatialReferenceH
void * OGRSpatialReferenceH
Definition: qgscoordinatereferencesystem.h:66
gdal::OGRDataSourceDeleter::operator()
void CORE_EXPORT operator()(OGRDataSourceH source) const
Destroys an OGR data source, using the correct gdal calls.
Definition: qgsogrutils.cpp:53
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
gdal::GDALWarpOptionsDeleter::operator()
void CORE_EXPORT operator()(GDALWarpOptions *options) const
Destroys GDAL warp options, using the correct gdal calls.
Definition: qgsogrutils.cpp:99
Qgis::SymbolType
SymbolType
Symbol types.
Definition: qgis.h:205
gdal::dataset_unique_ptr
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
Definition: qgsogrutils.h:139
gdal::OGRFldDeleter::operator()
void CORE_EXPORT operator()(OGRFieldDefnH definition) const
Destroys an OGR field definition, using the correct gdal calls.
Definition: qgsogrutils.cpp:64
gdal::OGRGeometryDeleter
Destroys OGR geometries.
Definition: qgsogrutils.h:54
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:882
gdal::ogr_geometry_unique_ptr
std::unique_ptr< std::remove_pointer< OGRGeometryH >::type, OGRGeometryDeleter > ogr_geometry_unique_ptr
Scoped OGR geometry.
Definition: qgsogrutils.h:124
gdal::fast_delete_and_close
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:79
gdal::OGRGeometryDeleter::operator()
void CORE_EXPORT operator()(OGRGeometryH geometry) const
Destroys an OGR geometry, using the correct gdal calls.
Definition: qgsogrutils.cpp:59
gdal::GDALDatasetCloser::operator()
void CORE_EXPORT operator()(GDALDatasetH datasource) const
Destroys an gdal dataset, using the correct gdal calls.
Definition: qgsogrutils.cpp:74
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
gdal::GDALWarpOptionsDeleter
Closes and cleanups GDAL warp options.
Definition: qgsogrutils.h:106
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsOgrUtils
Utilities for working with OGR features and layers.
Definition: qgsogrutils.h:166
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsFieldDomain
Base class for field domains.
Definition: qgsfielddomain.h:33
gdal::OGRFldDeleter
Destroys OGR field definition.
Definition: qgsogrutils.h:67
gdal::warp_options_unique_ptr
std::unique_ptr< GDALWarpOptions, GDALWarpOptionsDeleter > warp_options_unique_ptr
Scoped GDAL warp options.
Definition: qgsogrutils.h:154
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50
GDALDatasetH
void * GDALDatasetH
Definition: qgsalignraster.h:28