/
qgsvectorfilewriter.sip.in
732 lines (549 loc) · 23.8 KB
/
qgsvectorfilewriter.sip.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsvectorfilewriter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsVectorFileWriter : QgsFeatureSink
{
%Docstring(signature="appended")
A convenience class for writing vector layers to disk based formats (e.g. Shapefiles, GeoPackage).
There are two possibilities how to use this class:
1. A static call to :py:class:`QgsVectorFileWriter`.writeAsVectorFormat(...) which saves the whole vector layer.
2. Create an instance of the class and issue calls to addFeature(...).
%End
%TypeHeaderCode
#include "qgsvectorfilewriter.h"
%End
public:
enum OptionType
{
Set,
String,
Int,
Hidden
};
class Option
{
%TypeHeaderCode
#include "qgsvectorfilewriter.h"
%End
public:
Option( const QString &docString, QgsVectorFileWriter::OptionType type );
QString docString;
QgsVectorFileWriter::OptionType type;
};
class SetOption : QgsVectorFileWriter::Option
{
%TypeHeaderCode
#include "qgsvectorfilewriter.h"
%End
public:
SetOption( const QString &docString, const QStringList &values, const QString &defaultValue, bool allowNone = false );
QSet<QString> values;
QString defaultValue;
bool allowNone;
};
class StringOption: QgsVectorFileWriter::Option
{
%TypeHeaderCode
#include "qgsvectorfilewriter.h"
%End
public:
StringOption( const QString &docString, const QString &defaultValue = QString() );
QString defaultValue;
};
class IntOption: QgsVectorFileWriter::Option
{
%TypeHeaderCode
#include "qgsvectorfilewriter.h"
%End
public:
IntOption( const QString &docString, int defaultValue );
int defaultValue;
};
class BoolOption : QgsVectorFileWriter::SetOption
{
%TypeHeaderCode
#include "qgsvectorfilewriter.h"
%End
public:
BoolOption( const QString &docString, bool defaultValue );
};
class HiddenOption : QgsVectorFileWriter::Option
{
%TypeHeaderCode
#include "qgsvectorfilewriter.h"
%End
public:
explicit HiddenOption( const QString &value );
QString mValue;
};
struct MetaData
{
MetaData();
%Docstring
Constructor for MetaData
%End
MetaData( const QString &longName, const QString &trLongName, const QString &glob, const QString &ext, const QMap<QString, QgsVectorFileWriter::Option *> &driverOptions, const QMap<QString, QgsVectorFileWriter::Option *> &layerOptions, const QString &compulsoryEncoding = QString() );
QString longName;
QString trLongName;
QString glob;
QString ext;
QMap<QString, QgsVectorFileWriter::Option *> driverOptions;
QMap<QString, QgsVectorFileWriter::Option *> layerOptions;
QString compulsoryEncoding;
};
enum WriterError
{
NoError,
ErrDriverNotFound,
ErrCreateDataSource,
ErrCreateLayer,
ErrAttributeTypeUnsupported,
ErrAttributeCreationFailed,
ErrProjection,
ErrFeatureWriteFailed,
ErrInvalidLayer,
Canceled,
};
enum SymbologyExport
{
NoSymbology,
FeatureSymbology,
SymbolLayerSymbology
};
enum FieldNameSource
{
Original,
PreferAlias,
};
enum VectorFormatOption
{
SortRecommended,
SkipNonSpatialFormats,
};
typedef QFlags<QgsVectorFileWriter::VectorFormatOption> VectorFormatOptions;
class FieldValueConverter
{
%Docstring(signature="appended")
Interface to convert raw field values to their user-friendly value.
.. versionadded:: 2.16
%End
%TypeHeaderCode
#include "qgsvectorfilewriter.h"
%End
public:
FieldValueConverter();
%Docstring
Constructor
%End
virtual ~FieldValueConverter();
virtual QgsField fieldDefinition( const QgsField &field );
%Docstring
Returns a possibly modified field definition. Default implementation will return provided field unmodified.
:param field: original field definition
:return: possibly modified field definition
%End
virtual QVariant convert( int fieldIdxInLayer, const QVariant &value );
%Docstring
Convert the provided value, for field fieldIdxInLayer. Default implementation will return provided value unmodified.
:param fieldIdxInLayer: field index
:param value: original raw value
:return: possibly modified value.
%End
virtual QgsVectorFileWriter::FieldValueConverter *clone() const /Factory/;
%Docstring
Creates a clone of the FieldValueConverter.
%End
};
enum EditionCapability
{
//! Flag to indicate that a new layer can be added to the dataset
CanAddNewLayer,
//! Flag to indicate that new features can be added to an existing layer
CanAppendToExistingLayer,
//! Flag to indicate that new fields can be added to an existing layer. Imply CanAppendToExistingLayer
CanAddNewFieldsToExistingLayer,
//! Flag to indicate that an existing layer can be deleted
CanDeleteLayer
};
typedef QFlags<QgsVectorFileWriter::EditionCapability> EditionCapabilities;
enum ActionOnExistingFile
{
//! Create or overwrite file
CreateOrOverwriteFile,
//! Create or overwrite layer
CreateOrOverwriteLayer,
//! Append features to existing layer, but do not create new fields
AppendToLayerNoNewFields,
//! Append features to existing layer, and create new fields if needed
AppendToLayerAddFields
};
static QgsVectorFileWriter::WriterError writeAsVectorFormat( QgsVectorLayer *layer,
const QString &fileName,
const QString &fileEncoding,
const QgsCoordinateReferenceSystem &destCRS = QgsCoordinateReferenceSystem(),
const QString &driverName = "GPKG",
bool onlySelected = false,
QString *errorMessage /Out/ = 0,
const QStringList &datasourceOptions = QStringList(),
const QStringList &layerOptions = QStringList(),
bool skipAttributeCreation = false,
QString *newFilename = 0,
QgsVectorFileWriter::SymbologyExport symbologyExport = QgsVectorFileWriter::NoSymbology,
double symbologyScale = 1.0,
const QgsRectangle *filterExtent = 0,
QgsWkbTypes::Type overrideGeometryType = QgsWkbTypes::Unknown,
bool forceMulti = false,
bool includeZ = false,
const QgsAttributeList &attributes = QgsAttributeList(),
QgsVectorFileWriter::FieldValueConverter *fieldValueConverter = 0
) /Deprecated/;
%Docstring
Write contents of vector layer to an (OGR supported) vector format
:param layer: layer to write
:param fileName: file name to write to
:param fileEncoding: encoding to use
:param destCRS: CRS to reproject exported geometries to, or invalid CRS for no reprojection
:param driverName: OGR driver to use
:param onlySelected: write only selected features of layer
:param errorMessage: will be set to the error message text, if an error occurs while writing the layer
:param datasourceOptions: list of OGR data source creation options
:param layerOptions: list of OGR layer creation options
:param skipAttributeCreation: only write geometries
:param newFilename: QString pointer which will contain the new file name created (in case it is different to fileName).
:param symbologyExport: symbology to export
:param symbologyScale: scale of symbology
:param filterExtent: if not ``None``, only features intersecting the extent will be saved (added in QGIS 2.4)
:param overrideGeometryType: set to a valid geometry type to override the default geometry type for the layer. This parameter
allows for conversion of geometryless tables to null geometries, etc (added in QGIS 2.14)
:param forceMulti: set to ``True`` to force creation of multi* geometries (added in QGIS 2.14)
:param includeZ: set to ``True`` to include z dimension in output. This option is only valid if overrideGeometryType is set. (added in QGIS 2.14)
:param attributes: attributes to export (empty means all unless skipAttributeCreation is set)
:param fieldValueConverter: field value converter (added in QGIS 2.16)
.. deprecated::
Use :py:func:`~QgsVectorFileWriter.writeAsVectorFormatV2` instead.
%End
static QgsVectorFileWriter::WriterError writeAsVectorFormat( QgsVectorLayer *layer,
const QString &fileName,
const QString &fileEncoding,
const QgsCoordinateTransform &ct,
const QString &driverName = "GPKG",
bool onlySelected = false,
QString *errorMessage /Out/ = 0,
const QStringList &datasourceOptions = QStringList(),
const QStringList &layerOptions = QStringList(),
bool skipAttributeCreation = false,
QString *newFilename = 0,
QgsVectorFileWriter::SymbologyExport symbologyExport = QgsVectorFileWriter::NoSymbology,
double symbologyScale = 1.0,
const QgsRectangle *filterExtent = 0,
QgsWkbTypes::Type overrideGeometryType = QgsWkbTypes::Unknown,
bool forceMulti = false,
bool includeZ = false,
const QgsAttributeList &attributes = QgsAttributeList(),
QgsVectorFileWriter::FieldValueConverter *fieldValueConverter = 0
) /Deprecated/;
%Docstring
Writes a layer out to a vector file.
:param layer: layer to write
:param fileName: file name to write to
:param fileEncoding: encoding to use
:param ct: coordinate transform to reproject exported geometries with, or invalid transform
for no transformation
:param driverName: OGR driver to use
:param onlySelected: write only selected features of layer
:param errorMessage: will be set to the error message text, if an error occurs while writing the layer
:param datasourceOptions: list of OGR data source creation options
:param layerOptions: list of OGR layer creation options
:param skipAttributeCreation: only write geometries
:param newFilename: QString pointer which will contain the new file name created (in case it is different to fileName).
:param symbologyExport: symbology to export
:param symbologyScale: scale of symbology
:param filterExtent: if not ``None``, only features intersecting the extent will be saved (added in QGIS 2.4)
:param overrideGeometryType: set to a valid geometry type to override the default geometry type for the layer. This parameter
allows for conversion of geometryless tables to null geometries, etc (added in QGIS 2.14)
:param forceMulti: set to ``True`` to force creation of multi* geometries (added in QGIS 2.14)
:param includeZ: set to ``True`` to include z dimension in output. This option is only valid if overrideGeometryType is set. (added in QGIS 2.14)
:param attributes: attributes to export (empty means all unless skipAttributeCreation is set)
:param fieldValueConverter: field value converter (added in QGIS 2.16)
.. versionadded:: 2.2
.. deprecated::
Use :py:func:`~QgsVectorFileWriter.writeAsVectorFormatV2` instead.
%End
class SaveVectorOptions
{
%Docstring(signature="appended")
Options to pass to :py:func:`~QgsVectorFileWriter.writeAsVectorFormat`
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsvectorfilewriter.h"
%End
public:
SaveVectorOptions();
%Docstring
Constructor
%End
virtual ~SaveVectorOptions();
QString driverName;
QString layerName;
QgsVectorFileWriter::ActionOnExistingFile actionOnExistingFile;
QString fileEncoding;
QgsCoordinateTransform ct;
bool onlySelectedFeatures;
QStringList datasourceOptions;
QStringList layerOptions;
bool skipAttributeCreation;
QgsAttributeList attributes;
QgsVectorFileWriter::SymbologyExport symbologyExport;
double symbologyScale;
QgsRectangle filterExtent;
QgsWkbTypes::Type overrideGeometryType;
bool forceMulti;
bool includeZ;
QgsVectorFileWriter::FieldValueConverter *fieldValueConverter;
QgsFeedback *feedback;
FieldNameSource fieldNameSource;
};
static QgsVectorFileWriter::WriterError writeAsVectorFormat( QgsVectorLayer *layer,
const QString &fileName,
const QgsVectorFileWriter::SaveVectorOptions &options,
QString *newFilename = 0,
QString *errorMessage /Out/ = 0
) /Deprecated/;
%Docstring
Writes a layer out to a vector file.
:param layer: source layer to write
:param fileName: file name to write to
:param options: options.
:param newFilename: QString pointer which will contain the new file name created (in case it is different to fileName).
:param errorMessage: will be set to the error message text, if an error occurs while writing the layer
.. versionadded:: 3.0
.. deprecated::
Use :py:func:`~QgsVectorFileWriter.writeAsVectorFormatV2` instead.
%End
QgsVectorFileWriter( const QString &vectorFileName,
const QString &fileEncoding,
const QgsFields &fields,
QgsWkbTypes::Type geometryType,
const QgsCoordinateReferenceSystem &srs = QgsCoordinateReferenceSystem(),
const QString &driverName = "GPKG",
const QStringList &datasourceOptions = QStringList(),
const QStringList &layerOptions = QStringList(),
QString *newFilename = 0,
QgsVectorFileWriter::SymbologyExport symbologyExport = QgsVectorFileWriter::NoSymbology,
QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
) /Deprecated/;
static QgsVectorFileWriter *create( const QString &fileName,
const QgsFields &fields,
QgsWkbTypes::Type geometryType,
const QgsCoordinateReferenceSystem &srs,
const QgsCoordinateTransformContext &transformContext,
const QgsVectorFileWriter::SaveVectorOptions &options,
QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
QString *newFilename = 0,
QString *newLayer = 0 ) /Factory/;
%Docstring
Create a new vector file writer.
:param fileName: file name to write to
:param fields: fields to write
:param geometryType: geometry type of output file
:param srs: spatial reference system of output file
:param transformContext: coordinate transform context
:param options: save options
:param sinkFlags: feature sink flags
:param newFilename: potentially modified file name (output parameter)
:param newLayer: potentially modified layer name (output parameter)
.. versionadded:: 3.10.3
%End
static QgsVectorFileWriter::WriterError writeAsVectorFormatV2( QgsVectorLayer *layer,
const QString &fileName,
const QgsCoordinateTransformContext &transformContext,
const QgsVectorFileWriter::SaveVectorOptions &options,
QString *newFilename = 0,
QString *newLayer = 0,
QString *errorMessage /Out/ = 0 ) /Deprecated/;
%Docstring
Writes a layer out to a vector file.
:param layer: source layer to write
:param fileName: file name to write to
:param transformContext: coordinate transform context
:param options: save options
:param newFilename: potentially modified file name (output parameter)
:param newLayer: potentially modified layer name (output parameter)
:return: - Error message code, or QgsVectorFileWriter.NoError if the write operation was successful
- errorMessage: will be set to the error message text, if an error occurs while writing the layer
.. deprecated:: QGIS 3.20
use writeAsVectorFormatV3 instead
%End
static QgsVectorFileWriter::WriterError writeAsVectorFormatV3( QgsVectorLayer *layer,
const QString &fileName,
const QgsCoordinateTransformContext &transformContext,
const QgsVectorFileWriter::SaveVectorOptions &options,
QString *errorMessage /Out/ = 0,
QString *newFilename /Out/ = 0,
QString *newLayer /Out/ = 0 );
%Docstring
Writes a layer out to a vector file.
:param layer: source layer to write
:param fileName: file name to write to
:param transformContext: coordinate transform context
:param options: save options
:param newFilename: potentially modified file name (output parameter)
:param errorMessage: will be set to the error message text, if an error occurs while writing the layer
:return: - Error message code, or QgsVectorFileWriter.NoError if the write operation was successful
- newLayer: potentially modified layer name (output parameter)
.. versionadded:: 3.20
%End
struct FilterFormatDetails
{
QString driverName;
QString filterString;
QStringList globs;
};
static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
%Docstring
Returns a list or pairs, with format filter string as first element and OGR format key as second element.
The ``options`` argument can be used to control the sorting and filtering of
returned formats.
.. seealso:: :py:func:`supportedFormatExtensions`
%End
static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
%Docstring
Returns a list of file extensions for supported formats, e.g "shp", "gpkg".
The ``options`` argument can be used to control the sorting and filtering of
returned formats.
.. seealso:: :py:func:`supportedFiltersAndFormats`
.. versionadded:: 3.0
%End
static bool supportsFeatureStyles( const QString &driverName );
%Docstring
Returns ``True`` if the specified ``driverName`` supports feature styles.
The ``driverName`` argument must be a valid GDAL driver name.
.. versionadded:: 3.0
%End
struct DriverDetails
{
QString longName;
QString driverName;
};
static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
%Docstring
Returns the driver list that can be used for dialogs. It contains all OGR drivers
plus some additional internal QGIS driver names to distinguish between more
supported formats of the same OGR driver.
The returned list consists of structs containing the driver long name (e.g. user-friendly
display name for the format) and internal driver short name.
The ``options`` argument can be used to control the sorting and filtering of
returned drivers.
%End
static QString driverForExtension( const QString &extension );
%Docstring
Returns the OGR driver name for a specified file ``extension``. E.g. the
driver name for the ".shp" extension is "ESRI Shapefile".
If no suitable drivers are found then an empty string is returned.
.. versionadded:: 3.0
%End
static QString fileFilterString( VectorFormatOptions options = SortRecommended );
%Docstring
Returns filter string that can be used for dialogs.
The ``options`` argument can be used to control the sorting and filtering of
returned drivers.
%End
static QString filterForDriver( const QString &driverName );
%Docstring
Creates a filter for an OGR driver key
%End
static QString convertCodecNameForEncodingOption( const QString &codecName );
%Docstring
Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile
%End
QgsVectorFileWriter::WriterError hasError();
%Docstring
Checks whether there were any errors in constructor
%End
QString errorMessage();
%Docstring
Retrieves error message
%End
virtual bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() );
virtual bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() );
virtual QString lastError() const;
bool addFeatureWithStyle( QgsFeature &feature, QgsFeatureRenderer *renderer, QgsUnitTypes::DistanceUnit outputUnit = QgsUnitTypes::DistanceMeters );
%Docstring
Adds a ``feature`` to the currently opened data source, using the style from a specified ``renderer``.
.. versionadded:: 3.0
%End
~QgsVectorFileWriter();
static bool deleteShapeFile( const QString &fileName );
%Docstring
Delete a shapefile (and its accompanying shx / dbf / prj / qix / qpj / cpg / sbn / sbx / idm / ind)
:param fileName: /path/to/file.shp
:return: bool ``True`` if the file was deleted successfully
%End
QgsVectorFileWriter::SymbologyExport symbologyExport() const;
void setSymbologyExport( QgsVectorFileWriter::SymbologyExport symExport );
double symbologyScale() const;
%Docstring
Returns the reference scale for output.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
.. seealso:: :py:func:`setSymbologyScale`
.. versionadded:: 3.0
%End
void setSymbologyScale( double scale );
%Docstring
Set reference ``scale`` for output.
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
.. seealso:: :py:func:`symbologyScale`
.. versionadded:: 3.0
%End
static bool driverMetadata( const QString &driverName, MetaData &driverMetadata );
static QStringList defaultDatasetOptions( const QString &driverName );
%Docstring
Returns a list of the default dataset options for a specified driver.
:param driverName: name of OGR driver
.. seealso:: :py:func:`defaultLayerOptions`
.. versionadded:: 3.0
%End
static QStringList defaultLayerOptions( const QString &driverName );
%Docstring
Returns a list of the default layer options for a specified driver.
:param driverName: name of OGR driver
.. seealso:: :py:func:`defaultDatasetOptions`
.. versionadded:: 3.0
%End
static QgsVectorFileWriter::EditionCapabilities editionCapabilities( const QString &datasetName );
%Docstring
Returns edition capabilities for an existing dataset name.
.. versionadded:: 3.0
%End
static bool targetLayerExists( const QString &datasetName,
const QString &layerName );
%Docstring
Returns whether the target layer already exists.
.. versionadded:: 3.0
%End
static bool areThereNewFieldsToCreate( const QString &datasetName,
const QString &layerName,
QgsVectorLayer *layer,
const QgsAttributeList &attributes );
%Docstring
Returns whether there are among the attributes specified some that do not exist yet in the layer
.. versionadded:: 3.0
%End
protected:
private:
QgsVectorFileWriter( const QgsVectorFileWriter &rh );
};
QFlags<QgsVectorFileWriter::EditionCapability> operator|(QgsVectorFileWriter::EditionCapability f1, QFlags<QgsVectorFileWriter::EditionCapability> f2);
QFlags<QgsVectorFileWriter::VectorFormatOption> operator|(QgsVectorFileWriter::VectorFormatOption f1, QFlags<QgsVectorFileWriter::VectorFormatOption> f2);
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsvectorfilewriter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/