QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
192class CORE_EXPORT QgsOgrUtils
193{
194 public:
195
200 static QVariant OGRFieldtoVariant( const OGRField *value, OGRFieldType type );
201
209 static std::unique_ptr<OGRField> variantToOGRField( const QVariant &value, OGRFieldType type );
210
216 static int OGRTZFlagFromQt( const QDateTime &datetime );
217
225 static QgsFeature readOgrFeature( OGRFeatureH ogrFet, const QgsFields &fields, QTextCodec *encoding );
226
233 static QgsFields readOgrFields( OGRFeatureH ogrFet, QTextCodec *encoding );
234
245 static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsFields &fields, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
246
259 static QVariant getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField &field, int attIndex, QTextCodec *encoding, bool *ok = nullptr );
260
270 static bool readOgrFeatureAttributes( OGRFeatureH ogrFet, const QgsFields &fields, QgsFeature &feature, QTextCodec *encoding );
271
280 static bool readOgrFeatureGeometry( OGRFeatureH ogrFet, QgsFeature &feature );
281
289 static QgsGeometry ogrGeometryToQgsGeometry( OGRGeometryH geom );
290
300 static QgsFeatureList stringToFeatureList( const QString &string, const QgsFields &fields, QTextCodec *encoding );
301
309 static QgsFields stringToFields( const QString &string, QTextCodec *encoding );
310
316 static QStringList cStringListToQStringList( char **stringList );
317
323 static Qgis::WkbType ogrGeometryTypeToQgsWkbType( OGRwkbGeometryType ogrGeomType );
324
332 static QString OGRSpatialReferenceToWkt( OGRSpatialReferenceH srs );
333
340 static QgsCoordinateReferenceSystem OGRSpatialReferenceToCrs( OGRSpatialReferenceH srs );
341
349 static OGRSpatialReferenceH crsToOGRSpatialReference( const QgsCoordinateReferenceSystem &crs );
350
362 static QString readShapefileEncoding( const QString &path );
363
373 static QString readShapefileEncodingFromCpg( const QString &path );
374
384 static QString readShapefileEncodingFromLdid( const QString &path );
385
391 static QVariantMap parseStyleString( const QString &string );
392
398 static std::unique_ptr< QgsSymbol > symbolFromStyleString( const QString &string, Qgis::SymbolType type ) SIP_FACTORY;
399
411 static void ogrFieldTypeToQVariantType( OGRFieldType ogrType, OGRFieldSubType ogrSubType, QVariant::Type &variantType, QVariant::Type &variantSubType ) SIP_SKIP;
412
423 static void variantTypeToOgrFieldType( QVariant::Type variantType, OGRFieldType &ogrType, OGRFieldSubType &ogrSubType ) SIP_SKIP;
424
432 static QVariant stringToVariant( OGRFieldType type, OGRFieldSubType subType, const QString &string ) SIP_SKIP;
433
439 static QList<QgsVectorDataProvider::NativeType> nativeFieldTypesForDriver( GDALDriverH driver ) SIP_SKIP;
440
441#ifndef SIP_RUN
442#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,3,0)
443
451 static std::unique_ptr< QgsFieldDomain > convertFieldDomain( OGRFieldDomainH domain );
452
460 static OGRFieldDomainH convertFieldDomain( const QgsFieldDomain *domain );
461#endif
462#endif
463
464#ifndef SIP_RUN
465#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,6,0)
466
474 static QgsWeakRelation convertRelationship( GDALRelationshipH relationship, const QString &datasetUri );
475
483 static gdal::relationship_unique_ptr convertRelationship( const QgsWeakRelation &relation, QString &error );
484#endif
485#endif
486
492 static int listStyles( GDALDatasetH hDS, const QString &layerName,
493 const QString &geomColumn, QStringList &ids, QStringList &names,
494 QStringList &descriptions, QString &errCause );
495
501 static bool styleExists( GDALDatasetH hDS, const QString &layerName, const QString &geomColumn, const QString &styleId, QString &errorCause );
502
508 static QString getStyleById( GDALDatasetH hDS, const QString &styleId, QString &errCause );
509
515 static bool saveStyle( GDALDatasetH hDS, const QString &layerName,
516 const QString &geomColumn, const QString &qmlStyle, const QString &sldStyle,
517 const QString &styleName, const QString &styleDescription,
518 const QString &uiFileContent, bool useAsDefault, QString &errCause
519 );
520
526 static bool deleteStyleById( GDALDatasetH hDS, const QString &styleId, QString &errCause );
527
533 static QString loadStoredStyle( GDALDatasetH hDS, const QString &layerName, const QString &geomColumn, QString &styleName, QString &errCause );
534};
535
536#endif // QGSOGRUTILS_H
SymbolType
Attribute editing capabilities which may be supported by vector data providers.
Definition qgis.h:368
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:182
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:53
Container of fields for a vector layer.
Definition qgsfields.h:45
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
Definition qgsfeature.h:920
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.