QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
30 namespace gdal
31 {
32 
37  {
38 
42  void CORE_EXPORT operator()( OGRDataSourceH source );
43 
44  };
45 
50  {
51 
55  void CORE_EXPORT operator()( OGRGeometryH geometry );
56 
57  };
58 
63  {
64 
68  void CORE_EXPORT operator()( OGRFieldDefnH definition );
69 
70  };
71 
76  {
77 
81  void CORE_EXPORT operator()( OGRFeatureH feature );
82 
83  };
84 
89  {
90 
94  void CORE_EXPORT operator()( GDALDatasetH datasource );
95 
96  };
97 
102  {
103 
107  void CORE_EXPORT operator()( GDALWarpOptions *options );
108 
109  };
110 
114  using ogr_datasource_unique_ptr = std::unique_ptr< std::remove_pointer<OGRDataSourceH>::type, OGRDataSourceDeleter >;
115 
119  using ogr_geometry_unique_ptr = std::unique_ptr< std::remove_pointer<OGRGeometryH>::type, OGRGeometryDeleter >;
120 
124  using ogr_field_def_unique_ptr = std::unique_ptr< std::remove_pointer<OGRFieldDefnH>::type, OGRFldDeleter >;
125 
129  using ogr_feature_unique_ptr = std::unique_ptr< std::remove_pointer<OGRFeatureH>::type, OGRFeatureDeleter >;
130 
134  using dataset_unique_ptr = std::unique_ptr< std::remove_pointer<GDALDatasetH>::type, GDALDatasetCloser >;
135 
144  void CORE_EXPORT fast_delete_and_close( dataset_unique_ptr &dataset, GDALDriverH driver, const QString &path );
145 
149  using warp_options_unique_ptr = std::unique_ptr< GDALWarpOptions, GDALWarpOptionsDeleter >;
150 }
151 
161 class CORE_EXPORT QgsOgrUtils
162 {
163  public:
164 
172  static QgsFeature readOgrFeature( OGRFeatureH ogrFet, const QgsFields &fields, QTextCodec *encoding );
173 
180  static QgsFields readOgrFields( OGRFeatureH ogrFet, QTextCodec *encoding );
181 
192  static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsFields &fields, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
193 
206  static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField &field, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
207 
217  static bool readOgrFeatureAttributes( OGRFeatureH ogrFet, const QgsFields &fields, QgsFeature &feature, QTextCodec *encoding );
218 
227  static bool readOgrFeatureGeometry( OGRFeatureH ogrFet, QgsFeature &feature );
228 
236  static QgsGeometry ogrGeometryToQgsGeometry( OGRGeometryH geom );
237 
247  static QgsFeatureList stringToFeatureList( const QString &string, const QgsFields &fields, QTextCodec *encoding );
248 
256  static QgsFields stringToFields( const QString &string, QTextCodec *encoding );
257 
263  static QStringList cStringListToQStringList( char **stringList );
264 
270  static QgsWkbTypes::Type ogrGeometryTypeToQgsWkbType( OGRwkbGeometryType ogrGeomType );
271 
279  static QString OGRSpatialReferenceToWkt( OGRSpatialReferenceH srs );
280 
287  static QgsCoordinateReferenceSystem OGRSpatialReferenceToCrs( OGRSpatialReferenceH srs );
288 
300  static QString readShapefileEncoding( const QString &path );
301 
311  static QString readShapefileEncodingFromCpg( const QString &path );
312 
322  static QString readShapefileEncodingFromLdid( const QString &path );
323 };
324 
325 #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:129
gdal::OGRDataSourceDeleter
Destroys OGR data sources.
Definition: qgsogrutils.h:37
gdal::OGRFldDeleter::operator()
void CORE_EXPORT operator()(OGRFieldDefnH definition)
Destroys an OGR field definition, using the correct gdal calls.
Definition: qgsogrutils.cpp:56
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:114
gdal::GDALDatasetCloser::operator()
void CORE_EXPORT operator()(GDALDatasetH datasource)
Destroys an gdal dataset, using the correct gdal calls.
Definition: qgsogrutils.cpp:66
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
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:124
qgsfeature.h
gdal::OGRDataSourceDeleter::operator()
void CORE_EXPORT operator()(OGRDataSourceH source)
Destroys an OGR data source, using the correct gdal calls.
Definition: qgsogrutils.cpp:45
gdal
Definition: qgsogrutils.h:31
gdal::GDALDatasetCloser
Closes and cleanups GDAL dataset.
Definition: qgsogrutils.h:89
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
field
const QgsField & field
Definition: qgsfield.h:456
gdal::OGRFeatureDeleter
Destroys OGR feature.
Definition: qgsogrutils.h:76
OGRSpatialReferenceH
void * OGRSpatialReferenceH
Definition: qgscoordinatereferencesystem.h:60
gdal::dataset_unique_ptr
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
Definition: qgsogrutils.h:134
gdal::OGRFeatureDeleter::operator()
void CORE_EXPORT operator()(OGRFeatureH feature)
Destroys an OGR feature, using the correct gdal calls.
Definition: qgsogrutils.cpp:61
gdal::OGRGeometryDeleter
Destroys OGR geometries.
Definition: qgsogrutils.h:50
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:583
gdal::ogr_geometry_unique_ptr
std::unique_ptr< std::remove_pointer< OGRGeometryH >::type, OGRGeometryDeleter > ogr_geometry_unique_ptr
Scoped OGR geometry.
Definition: qgsogrutils.h:119
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:71
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
gdal::GDALWarpOptionsDeleter
Closes and cleanups GDAL warp options.
Definition: qgsogrutils.h:102
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
gdal::OGRGeometryDeleter::operator()
void CORE_EXPORT operator()(OGRGeometryH geometry)
Destroys an OGR geometry, using the correct gdal calls.
Definition: qgsogrutils.cpp:51
QgsOgrUtils
Utilities for working with OGR features and layers.
Definition: qgsogrutils.h:162
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
gdal::OGRFldDeleter
Destroys OGR field definition.
Definition: qgsogrutils.h:63
gdal::GDALWarpOptionsDeleter::operator()
void CORE_EXPORT operator()(GDALWarpOptions *options)
Destroys GDAL warp options, using the correct gdal calls.
Definition: qgsogrutils.cpp:91
gdal::warp_options_unique_ptr
std::unique_ptr< GDALWarpOptions, GDALWarpOptionsDeleter > warp_options_unique_ptr
Scoped GDAL warp options.
Definition: qgsogrutils.h:149
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50
GDALDatasetH
void * GDALDatasetH
Definition: qgsalignraster.h:28