QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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;
35class QgsWeakRelation;
36
37namespace gdal
38{
39
44 {
45
49 void CORE_EXPORT operator()( OGRDataSourceH source ) const;
50
51 };
52
57 {
58
62 void CORE_EXPORT operator()( OGRGeometryH geometry ) const;
63
64 };
65
70 {
71
75 void CORE_EXPORT operator()( OGRFieldDefnH definition ) const;
76
77 };
78
83 {
84
88 void CORE_EXPORT operator()( OGRFeatureH feature ) const;
89
90 };
91
96 {
97
101 void CORE_EXPORT operator()( GDALDatasetH datasource ) const;
102
103 };
104
109 {
110
114 void CORE_EXPORT operator()( GDALWarpOptions *options ) const;
115
116 };
117
118#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,6,0)
119
124 {
125
129 void CORE_EXPORT operator()( GDALRelationshipH relationship ) const;
130
131 };
132#endif
133
137 using ogr_datasource_unique_ptr = std::unique_ptr< std::remove_pointer<OGRDataSourceH>::type, OGRDataSourceDeleter >;
138
142 using ogr_geometry_unique_ptr = std::unique_ptr< std::remove_pointer<OGRGeometryH>::type, OGRGeometryDeleter >;
143
147 using ogr_field_def_unique_ptr = std::unique_ptr< std::remove_pointer<OGRFieldDefnH>::type, OGRFldDeleter >;
148
152 using ogr_feature_unique_ptr = std::unique_ptr< std::remove_pointer<OGRFeatureH>::type, OGRFeatureDeleter >;
153
157 using dataset_unique_ptr = std::unique_ptr< std::remove_pointer<GDALDatasetH>::type, GDALDatasetCloser >;
158
167 void CORE_EXPORT fast_delete_and_close( dataset_unique_ptr &dataset, GDALDriverH driver, const QString &path );
168
172 using warp_options_unique_ptr = std::unique_ptr< GDALWarpOptions, GDALWarpOptionsDeleter >;
173
174#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,6,0)
175
179 using relationship_unique_ptr = std::unique_ptr< std::remove_pointer<GDALRelationshipH>::type, GDALRelationshipDeleter >;
180#endif
181}
182
191class CORE_EXPORT QgsOgrUtils
192{
193 public:
194
199 static QVariant OGRFieldtoVariant( const OGRField *value, OGRFieldType type );
200
208 static std::unique_ptr<OGRField> variantToOGRField( const QVariant &value, OGRFieldType type );
209
215 static int OGRTZFlagFromQt( const QDateTime &datetime );
216
224 static QgsFeature readOgrFeature( OGRFeatureH ogrFet, const QgsFields &fields, QTextCodec *encoding );
225
232 static QgsFields readOgrFields( OGRFeatureH ogrFet, QTextCodec *encoding );
233
244 static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsFields &fields, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
245
258 static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField &field, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
259
269 static bool readOgrFeatureAttributes( OGRFeatureH ogrFet, const QgsFields &fields, QgsFeature &feature, QTextCodec *encoding );
270
279 static bool readOgrFeatureGeometry( OGRFeatureH ogrFet, QgsFeature &feature );
280
288 static QgsGeometry ogrGeometryToQgsGeometry( OGRGeometryH geom );
289
299 static QgsFeatureList stringToFeatureList( const QString &string, const QgsFields &fields, QTextCodec *encoding );
300
308 static QgsFields stringToFields( const QString &string, QTextCodec *encoding );
309
315 static QStringList cStringListToQStringList( char **stringList );
316
322 static Qgis::WkbType ogrGeometryTypeToQgsWkbType( OGRwkbGeometryType ogrGeomType );
323
331 static QString OGRSpatialReferenceToWkt( OGRSpatialReferenceH srs );
332
339 static QgsCoordinateReferenceSystem OGRSpatialReferenceToCrs( OGRSpatialReferenceH srs );
340
348 static OGRSpatialReferenceH crsToOGRSpatialReference( const QgsCoordinateReferenceSystem &crs );
349
361 static QString readShapefileEncoding( const QString &path );
362
372 static QString readShapefileEncodingFromCpg( const QString &path );
373
383 static QString readShapefileEncodingFromLdid( const QString &path );
384
390 static QVariantMap parseStyleString( const QString &string );
391
397 static std::unique_ptr< QgsSymbol > symbolFromStyleString( const QString &string, Qgis::SymbolType type ) SIP_FACTORY;
398
410 static void ogrFieldTypeToQVariantType( OGRFieldType ogrType, OGRFieldSubType ogrSubType, QMetaType::Type &variantType, QMetaType::Type &variantSubType ) SIP_SKIP;
411
422 static void variantTypeToOgrFieldType( QMetaType::Type variantType, OGRFieldType &ogrType, OGRFieldSubType &ogrSubType ) SIP_SKIP;
423
431 static QVariant stringToVariant( OGRFieldType type, OGRFieldSubType subType, const QString &string ) SIP_SKIP;
432
438 static QList<QgsVectorDataProvider::NativeType> nativeFieldTypesForDriver( GDALDriverH driver ) SIP_SKIP;
439
440#ifndef SIP_RUN
441#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,3,0)
442
450 static std::unique_ptr< QgsFieldDomain > convertFieldDomain( OGRFieldDomainH domain );
451
459 static OGRFieldDomainH convertFieldDomain( const QgsFieldDomain *domain );
460#endif
461#endif
462
463#ifndef SIP_RUN
464#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,6,0)
465
473 static QgsWeakRelation convertRelationship( GDALRelationshipH relationship, const QString &datasetUri );
474
482 static gdal::relationship_unique_ptr convertRelationship( const QgsWeakRelation &relation, QString &error );
483#endif
484#endif
485
491 static int listStyles( GDALDatasetH hDS, const QString &layerName,
492 const QString &geomColumn, QStringList &ids, QStringList &names,
493 QStringList &descriptions, QString &errCause );
494
500 static bool styleExists( GDALDatasetH hDS, const QString &layerName, const QString &geomColumn, const QString &styleId, QString &errorCause );
501
507 static QString getStyleById( GDALDatasetH hDS, const QString &styleId, QString &errCause );
508
514 static bool saveStyle( GDALDatasetH hDS, const QString &layerName,
515 const QString &geomColumn, const QString &qmlStyle, const QString &sldStyle,
516 const QString &styleName, const QString &styleDescription,
517 const QString &uiFileContent, bool useAsDefault, QString &errCause
518 );
519
525 static bool deleteStyleById( GDALDatasetH hDS, const QString &styleId, QString &errCause );
526
532 static QString loadStoredStyle( GDALDatasetH hDS, const QString &layerName, const QString &geomColumn, QString &styleName, QString &errCause );
533};
534
535#endif // QGSOGRUTILS_H
SymbolType
Symbol types.
Definition qgis.h:574
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
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:58
Base class for field domains.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
Utilities for working with OGR features and layers.
The QgsWeakRelation class represent a QgsRelation with possibly unresolved layers or unmatched fields...
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.
std::unique_ptr< std::remove_pointer< OGRFeatureH >::type, OGRFeatureDeleter > ogr_feature_unique_ptr
Scoped OGR feature.
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
std::unique_ptr< std::remove_pointer< OGRDataSourceH >::type, OGRDataSourceDeleter > ogr_datasource_unique_ptr
Scoped OGR data source.
std::unique_ptr< std::remove_pointer< OGRFieldDefnH >::type, OGRFldDeleter > ogr_field_def_unique_ptr
Scoped OGR field definition.
std::unique_ptr< std::remove_pointer< OGRGeometryH >::type, OGRGeometryDeleter > ogr_geometry_unique_ptr
Scoped OGR geometry.
std::unique_ptr< GDALWarpOptions, GDALWarpOptionsDeleter > warp_options_unique_ptr
Scoped GDAL warp options.
std::unique_ptr< std::remove_pointer< GDALRelationshipH >::type, GDALRelationshipDeleter > relationship_unique_ptr
Scoped GDAL relationship.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_FACTORY
Definition qgis_sip.h:76
void * GDALDatasetH
void * OGRSpatialReferenceH
QList< QgsFeature > QgsFeatureList
const QgsCoordinateReferenceSystem & crs
Closes and cleanups GDAL dataset.
Definition qgsogrutils.h:96
void CORE_EXPORT operator()(GDALDatasetH datasource) const
Destroys an gdal dataset, using the correct gdal calls.
Closes and cleanups GDAL relationship.
void CORE_EXPORT operator()(GDALRelationshipH relationship) const
Destroys GDAL relationship, using the correct gdal calls.
Closes and cleanups GDAL warp options.
void CORE_EXPORT operator()(GDALWarpOptions *options) const
Destroys GDAL warp options, using the correct gdal calls.
Destroys OGR data sources.
Definition qgsogrutils.h:44
void CORE_EXPORT operator()(OGRDataSourceH source) const
Destroys an OGR data source, using the correct gdal calls.
Destroys OGR feature.
Definition qgsogrutils.h:83
void CORE_EXPORT operator()(OGRFeatureH feature) const
Destroys an OGR feature, using the correct gdal calls.
Destroys OGR field definition.
Definition qgsogrutils.h:70
void CORE_EXPORT operator()(OGRFieldDefnH definition) const
Destroys an OGR field definition, using the correct gdal calls.
Destroys OGR geometries.
Definition qgsogrutils.h:57
void CORE_EXPORT operator()(OGRGeometryH geometry) const
Destroys an OGR geometry, using the correct gdal calls.