Skip to content

Commit 6d92ae6

Browse files
author
jef
committedSep 21, 2009

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed
 

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& shapefileName,
116116
QgsDebugMsg( "creating " + QString::number( fields.size() ) + " fields" );
117117

118118
mFields = fields;
119+
mAttrIdxToOgrIdx.clear();
119120

121+
int ogrIdx = 0;
120122
QgsFieldMap::const_iterator fldIt;
121123
for ( fldIt = fields.begin(); fldIt != fields.end(); ++fldIt )
122124
{
@@ -178,6 +180,8 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& shapefileName,
178180
mError = ErrAttributeCreationFailed;
179181
return;
180182
}
183+
184+
mAttrIdxToOgrIdx.insert( fldIt.key(), ogrIdx++ );
181185
}
182186

183187
QgsDebugMsg( "Done creating fields" );
@@ -218,8 +222,14 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
218222
continue;
219223
}
220224

221-
int ogrField = fldIt.key();
222-
const QVariant& attrValue = feature.attributeMap()[ ogrField ];
225+
if ( !mAttrIdxToOgrIdx.contains( fldIt.key() ) )
226+
{
227+
QgsDebugMsg( QString( "no ogr field for field %1" ).arg( fldIt.key() ) );
228+
continue;
229+
}
230+
231+
const QVariant& attrValue = feature.attributeMap()[ fldIt.key()];
232+
int ogrField = mAttrIdxToOgrIdx[ fldIt.key()];
223233

224234
switch ( attrValue.type() )
225235
{

‎src/core/qgsvectorfilewriter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class CORE_EXPORT QgsVectorFileWriter
9898

9999
/** geometry type which is being used */
100100
QGis::WkbType mWkbType;
101+
102+
/** map attribute indizes to OGR field indexes */
103+
QMap<int, int> mAttrIdxToOgrIdx;
101104
};
102105

103106
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.