QGIS API Documentation  3.21.0-Master (5b68dc587e)
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 
32 class QTextCodec;
33 
34 namespace gdal
35 {
36 
41  {
42 
46  void CORE_EXPORT operator()( OGRDataSourceH source );
47 
48  };
49 
54  {
55 
59  void CORE_EXPORT operator()( OGRGeometryH geometry );
60 
61  };
62 
67  {
68 
72  void CORE_EXPORT operator()( OGRFieldDefnH definition );
73 
74  };
75 
80  {
81 
85  void CORE_EXPORT operator()( OGRFeatureH feature );
86 
87  };
88 
93  {
94 
98  void CORE_EXPORT operator()( GDALDatasetH datasource );
99 
100  };
101 
106  {
107 
111  void CORE_EXPORT operator()( GDALWarpOptions *options );
112 
113  };
114 
118  using ogr_datasource_unique_ptr = std::unique_ptr< std::remove_pointer<OGRDataSourceH>::type, OGRDataSourceDeleter >;
119 
123  using ogr_geometry_unique_ptr = std::unique_ptr< std::remove_pointer<OGRGeometryH>::type, OGRGeometryDeleter >;
124 
128  using ogr_field_def_unique_ptr = std::unique_ptr< std::remove_pointer<OGRFieldDefnH>::type, OGRFldDeleter >;
129 
133  using ogr_feature_unique_ptr = std::unique_ptr< std::remove_pointer<OGRFeatureH>::type, OGRFeatureDeleter >;
134 
138  using dataset_unique_ptr = std::unique_ptr< std::remove_pointer<GDALDatasetH>::type, GDALDatasetCloser >;
139 
148  void CORE_EXPORT fast_delete_and_close( dataset_unique_ptr &dataset, GDALDriverH driver, const QString &path );
149 
153  using warp_options_unique_ptr = std::unique_ptr< GDALWarpOptions, GDALWarpOptionsDeleter >;
154 }
155 
165 class CORE_EXPORT QgsOgrUtils
166 {
167  public:
168 
173  static QVariant OGRFieldtoVariant( const OGRField *value, OGRFieldType type );
174 
182  static QgsFeature readOgrFeature( OGRFeatureH ogrFet, const QgsFields &fields, QTextCodec *encoding );
183 
190  static QgsFields readOgrFields( OGRFeatureH ogrFet, QTextCodec *encoding );
191 
202  static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsFields &fields, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
203 
216  static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField &field, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
217 
227  static bool readOgrFeatureAttributes( OGRFeatureH ogrFet, const QgsFields &fields, QgsFeature &feature, QTextCodec *encoding );
228 
237  static bool readOgrFeatureGeometry( OGRFeatureH ogrFet, QgsFeature &feature );
238 
246  static QgsGeometry ogrGeometryToQgsGeometry( OGRGeometryH geom );
247 
257  static QgsFeatureList stringToFeatureList( const QString &string, const QgsFields &fields, QTextCodec *encoding );
258 
266  static QgsFields stringToFields( const QString &string, QTextCodec *encoding );
267 
273  static QStringList cStringListToQStringList( char **stringList );
274 
280  static QgsWkbTypes::Type ogrGeometryTypeToQgsWkbType( OGRwkbGeometryType ogrGeomType );
281 
289  static QString OGRSpatialReferenceToWkt( OGRSpatialReferenceH srs );
290 
297  static QgsCoordinateReferenceSystem OGRSpatialReferenceToCrs( OGRSpatialReferenceH srs );
298 
306  static OGRSpatialReferenceH crsToOGRSpatialReference( const QgsCoordinateReferenceSystem &crs );
307 
319  static QString readShapefileEncoding( const QString &path );
320 
330  static QString readShapefileEncodingFromCpg( const QString &path );
331 
341  static QString readShapefileEncodingFromLdid( const QString &path );
342 
348  static QVariantMap parseStyleString( const QString &string );
349 
355  static std::unique_ptr< QgsSymbol > symbolFromStyleString( const QString &string, Qgis::SymbolType type ) SIP_FACTORY;
356 };
357 
358 #endif // QGSOGRUTILS_H
SymbolType
Symbol types.
Definition: qgis.h:169
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
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:124
Utilities for working with OGR features and layers.
Definition: qgsogrutils.h:166
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:78
std::unique_ptr< std::remove_pointer< OGRFeatureH >::type, OGRFeatureDeleter > ogr_feature_unique_ptr
Scoped OGR feature.
Definition: qgsogrutils.h:133
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
Definition: qgsogrutils.h:138
std::unique_ptr< std::remove_pointer< OGRDataSourceH >::type, OGRDataSourceDeleter > ogr_datasource_unique_ptr
Scoped OGR data source.
Definition: qgsogrutils.h:118
std::unique_ptr< std::remove_pointer< OGRFieldDefnH >::type, OGRFldDeleter > ogr_field_def_unique_ptr
Scoped OGR field definition.
Definition: qgsogrutils.h:128
std::unique_ptr< std::remove_pointer< OGRGeometryH >::type, OGRGeometryDeleter > ogr_geometry_unique_ptr
Scoped OGR geometry.
Definition: qgsogrutils.h:123
std::unique_ptr< GDALWarpOptions, GDALWarpOptionsDeleter > warp_options_unique_ptr
Scoped GDAL warp options.
Definition: qgsogrutils.h:153
#define SIP_FACTORY
Definition: qgis_sip.h:76
void * GDALDatasetH
void * OGRSpatialReferenceH
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:834
const QgsField & field
Definition: qgsfield.h:463
const QgsCoordinateReferenceSystem & crs
Closes and cleanups GDAL dataset.
Definition: qgsogrutils.h:93
void CORE_EXPORT operator()(GDALDatasetH datasource)
Destroys an gdal dataset, using the correct gdal calls.
Definition: qgsogrutils.cpp:73
Closes and cleanups GDAL warp options.
Definition: qgsogrutils.h:106
void CORE_EXPORT operator()(GDALWarpOptions *options)
Destroys GDAL warp options, using the correct gdal calls.
Definition: qgsogrutils.cpp:98
Destroys OGR data sources.
Definition: qgsogrutils.h:41
void CORE_EXPORT operator()(OGRDataSourceH source)
Destroys an OGR data source, using the correct gdal calls.
Definition: qgsogrutils.cpp:52
Destroys OGR feature.
Definition: qgsogrutils.h:80
void CORE_EXPORT operator()(OGRFeatureH feature)
Destroys an OGR feature, using the correct gdal calls.
Definition: qgsogrutils.cpp:68
Destroys OGR field definition.
Definition: qgsogrutils.h:67
void CORE_EXPORT operator()(OGRFieldDefnH definition)
Destroys an OGR field definition, using the correct gdal calls.
Definition: qgsogrutils.cpp:63
Destroys OGR geometries.
Definition: qgsogrutils.h:54
void CORE_EXPORT operator()(OGRGeometryH geometry)
Destroys an OGR geometry, using the correct gdal calls.
Definition: qgsogrutils.cpp:58