Skip to content

Commit

Permalink
fix #2933
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14066 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Aug 11, 2010
1 parent d483d22 commit e34de81
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ QgsVectorFileWriter::QgsVectorFileWriter(
return;
}

OGRFeatureDefnH defn = OGR_L_GetLayerDefn( mLayer );

QgsDebugMsg( "created layer" );

// create the fields
Expand All @@ -193,7 +195,6 @@ QgsVectorFileWriter::QgsVectorFileWriter(
mFields = fields;
mAttrIdxToOgrIdx.clear();

int ogrIdx = 0;
QgsFieldMap::const_iterator fldIt;
for ( fldIt = fields.begin(); fldIt != fields.end(); ++fldIt )
{
Expand Down Expand Up @@ -261,7 +262,18 @@ QgsVectorFileWriter::QgsVectorFileWriter(
return;
}

mAttrIdxToOgrIdx.insert( fldIt.key(), ogrIdx++ );
int ogrIdx = OGR_FD_GetFieldIndex( defn, mCodec->fromUnicode( attrField.name() ) );
if ( ogrIdx < 0 )
{
QgsDebugMsg( "error creating field " + attrField.name() );
mErrorMessage = QObject::tr( "created field %1 not found (OGR error: %2)" )
.arg( attrField.name() )
.arg( QString::fromUtf8( CPLGetLastErrorMsg() ) );
mError = ErrAttributeCreationFailed;
return;
}

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

QgsDebugMsg( "Done creating fields" );
Expand Down

0 comments on commit e34de81

Please sign in to comment.