Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix #1941
git-svn-id: http://svn.osgeo.org/qgis/trunk@11698 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 21, 2009
1 parent 1728008 commit 5d5883b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -116,7 +116,9 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& shapefileName,
QgsDebugMsg( "creating " + QString::number( fields.size() ) + " fields" );

mFields = fields;
mAttrIdxToOgrIdx.clear();

int ogrIdx = 0;
QgsFieldMap::const_iterator fldIt;
for ( fldIt = fields.begin(); fldIt != fields.end(); ++fldIt )
{
Expand Down Expand Up @@ -178,6 +180,8 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& shapefileName,
mError = ErrAttributeCreationFailed;
return;
}

mAttrIdxToOgrIdx.insert( fldIt.key(), ogrIdx++ );
}

QgsDebugMsg( "Done creating fields" );
Expand Down Expand Up @@ -218,8 +222,14 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
continue;
}

int ogrField = fldIt.key();
const QVariant& attrValue = feature.attributeMap()[ ogrField ];
if ( !mAttrIdxToOgrIdx.contains( fldIt.key() ) )
{
QgsDebugMsg( QString( "no ogr field for field %1" ).arg( fldIt.key() ) );
continue;
}

const QVariant& attrValue = feature.attributeMap()[ fldIt.key()];
int ogrField = mAttrIdxToOgrIdx[ fldIt.key()];

switch ( attrValue.type() )
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectorfilewriter.h
Expand Up @@ -98,6 +98,9 @@ class CORE_EXPORT QgsVectorFileWriter

/** geometry type which is being used */
QGis::WkbType mWkbType;

/** map attribute indizes to OGR field indexes */
QMap<int, int> mAttrIdxToOgrIdx;
};

#endif

0 comments on commit 5d5883b

Please sign in to comment.