Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsvectorfilewriter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorfilewriter.h
3  generic vector file writer
4  -------------------
5  begin : Jun 6 2004
6  copyright : (C) 2004 by Tim Sutton
7  email : tim at linfiniti.com
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 /* $Id$ */
19 
20 #ifndef _QGSVECTORFILEWRITER_H_
21 #define _QGSVECTORFILEWRITER_H_
22 
23 #include "qgsvectorlayer.h"
24 #include "qgsfield.h"
25 
26 #include <QPair>
27 
28 typedef void *OGRDataSourceH;
29 typedef void *OGRLayerH;
30 typedef void *OGRGeometryH;
31 
32 class QTextCodec;
33 
43 class CORE_EXPORT QgsVectorFileWriter
44 {
45  public:
46 
48  {
49  NoError = 0,
55  ErrProjection, // added in 1.5
56  ErrFeatureWriteFailed, // added in 1.6
57  };
58 
61  Q_DECL_DEPRECATED static WriterError writeAsShapefile( QgsVectorLayer* layer,
62  const QString& shapefileName,
63  const QString& fileEncoding,
64  const QgsCoordinateReferenceSystem *destCRS,
65  bool onlySelected = false,
66  QString *errorMessage = 0,
67  const QStringList &datasourceOptions = QStringList(), // added in 1.6
68  const QStringList &layerOptions = QStringList() // added in 1.6
69  );
70 
73  static WriterError writeAsVectorFormat( QgsVectorLayer* layer,
74  const QString& fileName,
75  const QString& fileEncoding,
76  const QgsCoordinateReferenceSystem *destCRS,
77  const QString& driverName = "ESRI Shapefile",
78  bool onlySelected = false,
79  QString *errorMessage = 0,
80  const QStringList &datasourceOptions = QStringList(), // added in 1.6
81  const QStringList &layerOptions = QStringList(), // added in 1.6
82  bool skipAttributeCreation = false // added in 1.6
83  );
84 
86  QgsVectorFileWriter( const QString& vectorFileName,
87  const QString& fileEncoding,
88  const QgsFieldMap& fields,
89  QGis::WkbType geometryType,
91  const QString& driverName = "ESRI Shapefile",
92  const QStringList &datasourceOptions = QStringList(), // added in 1.6
93  const QStringList &layerOptions = QStringList() // added in 1.6
94  );
95 
97  static QMap< QString, QString> supportedFiltersAndFormats();
98 
100  static QMap< QString, QString> ogrDriverList();
101 
103  static QString fileFilterString();
104 
106  static QString filterForDriver( const QString& driverName );
107 
109  WriterError hasError();
110 
114  QString errorMessage();
115 
117  bool addFeature( QgsFeature& feature );
118 
121 
126  static bool deleteShapeFile( QString theFileName );
127 
128  protected:
129 
130  OGRGeometryH createEmptyGeometry( QGis::WkbType wkbType );
131 
135 
137 
140  QString mErrorMessage;
141 
142  QTextCodec *mCodec;
143 
146 
148  QMap<int, int> mAttrIdxToOgrIdx;
149 
150  private:
151  static bool driverMetadata( QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext );
152 };
153 
154 #endif