git-svn-id: http://svn.osgeo.org/qgis/trunk@11698 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
jef 2009-09-21 19:48:38 +00:00
parent 17280084fb
commit 5d5883bc99
2 changed files with 15 additions and 2 deletions

View File

@ -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 )
{
@ -178,6 +180,8 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& shapefileName,
mError = ErrAttributeCreationFailed;
return;
}
mAttrIdxToOgrIdx.insert( fldIt.key(), ogrIdx++ );
}
QgsDebugMsg( "Done creating fields" );
@ -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() )
{

View File

@ -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