Quantum GIS API Documentation
1.7.4
|
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 /* $Id$ */ 00019 00020 #ifndef _QGSVECTORFILEWRITER_H_ 00021 #define _QGSVECTORFILEWRITER_H_ 00022 00023 #include "qgsvectorlayer.h" 00024 #include "qgsfield.h" 00025 00026 #include <QPair> 00027 00028 typedef void *OGRDataSourceH; 00029 typedef void *OGRLayerH; 00030 typedef void *OGRGeometryH; 00031 00032 class QTextCodec; 00033 00043 class CORE_EXPORT QgsVectorFileWriter 00044 { 00045 public: 00046 00047 enum WriterError 00048 { 00049 NoError = 0, 00050 ErrDriverNotFound, 00051 ErrCreateDataSource, 00052 ErrCreateLayer, 00053 ErrAttributeTypeUnsupported, 00054 ErrAttributeCreationFailed, 00055 ErrProjection, // added in 1.5 00056 ErrFeatureWriteFailed, // added in 1.6 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 ); 00084 00086 QgsVectorFileWriter( const QString& vectorFileName, 00087 const QString& fileEncoding, 00088 const QgsFieldMap& fields, 00089 QGis::WkbType geometryType, 00090 const QgsCoordinateReferenceSystem* srs, 00091 const QString& driverName = "ESRI Shapefile", 00092 const QStringList &datasourceOptions = QStringList(), // added in 1.6 00093 const QStringList &layerOptions = QStringList() // added in 1.6 00094 ); 00095 00097 static QMap< QString, QString> supportedFiltersAndFormats(); 00098 00100 static QMap< QString, QString> ogrDriverList(); 00101 00103 static QString fileFilterString(); 00104 00106 static QString filterForDriver( const QString& driverName ); 00107 00109 WriterError hasError(); 00110 00114 QString errorMessage(); 00115 00117 bool addFeature( QgsFeature& feature ); 00118 00120 ~QgsVectorFileWriter(); 00121 00126 static bool deleteShapeFile( QString theFileName ); 00127 00128 protected: 00129 00130 OGRGeometryH createEmptyGeometry( QGis::WkbType wkbType ); 00131 00132 OGRDataSourceH mDS; 00133 OGRLayerH mLayer; 00134 OGRGeometryH mGeom; 00135 00136 QgsFieldMap mFields; 00137 00139 WriterError mError; 00140 QString mErrorMessage; 00141 00142 QTextCodec *mCodec; 00143 00145 QGis::WkbType mWkbType; 00146 00148 QMap<int, int> mAttrIdxToOgrIdx; 00149 00150 private: 00151 static bool driverMetadata( QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext ); 00152 }; 00153 00154 #endif