Quantum GIS API Documentation
1.8
|
00001 /*************************************************************************** 00002 qgsvectorfilewriter.h 00003 generic vector file writer 00004 ------------------- 00005 begin : Jun 6 2004 00006 copyright : (C) 2004 by Tim Sutton 00007 email : tim at linfiniti.com 00008 ***************************************************************************/ 00009 00010 /*************************************************************************** 00011 * * 00012 * This program is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU General Public License as published by * 00014 * the Free Software Foundation; either version 2 of the License, or * 00015 * (at your option) any later version. * 00016 * * 00017 ***************************************************************************/ 00018 00019 #ifndef _QGSVECTORFILEWRITER_H_ 00020 #define _QGSVECTORFILEWRITER_H_ 00021 00022 #include "qgsvectorlayer.h" 00023 #include "qgsfield.h" 00024 00025 #include <QPair> 00026 00027 typedef void *OGRDataSourceH; 00028 typedef void *OGRLayerH; 00029 typedef void *OGRGeometryH; 00030 00031 class QTextCodec; 00032 00042 class CORE_EXPORT QgsVectorFileWriter 00043 { 00044 public: 00045 00046 enum WriterError 00047 { 00048 NoError = 0, 00049 ErrDriverNotFound, 00050 ErrCreateDataSource, 00051 ErrCreateLayer, 00052 ErrAttributeTypeUnsupported, 00053 ErrAttributeCreationFailed, 00054 ErrProjection, // added in 1.5 00055 ErrFeatureWriteFailed, // added in 1.6 00056 ErrInvalidLayer, // added in 2.0 00057 }; 00058 00061 Q_DECL_DEPRECATED static WriterError writeAsShapefile( QgsVectorLayer* layer, 00062 const QString& shapefileName, 00063 const QString& fileEncoding, 00064 const QgsCoordinateReferenceSystem *destCRS, 00065 bool onlySelected = false, 00066 QString *errorMessage = 0, 00067 const QStringList &datasourceOptions = QStringList(), // added in 1.6 00068 const QStringList &layerOptions = QStringList() // added in 1.6 00069 ); 00070 00073 static WriterError writeAsVectorFormat( QgsVectorLayer* layer, 00074 const QString& fileName, 00075 const QString& fileEncoding, 00076 const QgsCoordinateReferenceSystem *destCRS, 00077 const QString& driverName = "ESRI Shapefile", 00078 bool onlySelected = false, 00079 QString *errorMessage = 0, 00080 const QStringList &datasourceOptions = QStringList(), // added in 1.6 00081 const QStringList &layerOptions = QStringList(), // added in 1.6 00082 bool skipAttributeCreation = false, // added in 1.6 00083 QString *newFilename = 0 // added in 1.9 00084 ); 00085 00087 QgsVectorFileWriter( const QString& vectorFileName, 00088 const QString& fileEncoding, 00089 const QgsFieldMap& fields, 00090 QGis::WkbType geometryType, 00091 const QgsCoordinateReferenceSystem* srs, 00092 const QString& driverName = "ESRI Shapefile", 00093 const QStringList &datasourceOptions = QStringList(), // added in 1.6 00094 const QStringList &layerOptions = QStringList(), // added in 1.6 00095 QString *newFilename = 0 // added in 1.9 00096 ); 00097 00099 static QMap< QString, QString> supportedFiltersAndFormats(); 00100 00102 static QMap< QString, QString> ogrDriverList(); 00103 00105 static QString fileFilterString(); 00106 00108 static QString filterForDriver( const QString& driverName ); 00109 00111 WriterError hasError(); 00112 00116 QString errorMessage(); 00117 00119 bool addFeature( QgsFeature& feature ); 00120 00121 QMap<int, int> attrIdxToOgrIdx() { return mAttrIdxToOgrIdx; } 00122 00124 ~QgsVectorFileWriter(); 00125 00130 static bool deleteShapeFile( QString theFileName ); 00131 00132 protected: 00133 00134 OGRGeometryH createEmptyGeometry( QGis::WkbType wkbType ); 00135 00136 OGRDataSourceH mDS; 00137 OGRLayerH mLayer; 00138 OGRGeometryH mGeom; 00139 00140 QgsFieldMap mFields; 00141 00143 WriterError mError; 00144 QString mErrorMessage; 00145 00146 QTextCodec *mCodec; 00147 00149 QGis::WkbType mWkbType; 00150 00152 QMap<int, int> mAttrIdxToOgrIdx; 00153 00154 private: 00155 static bool driverMetadata( QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext ); 00156 }; 00157 00158 #endif