Skip to content

Commit 36c894c

Browse files
author
jef
committed
fix #2933
git-svn-id: http://svn.osgeo.org/qgis/trunk@14066 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent be37487 commit 36c894c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/core/qgsvectorfilewriter.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ QgsVectorFileWriter::QgsVectorFileWriter(
185185
return;
186186
}
187187

188+
OGRFeatureDefnH defn = OGR_L_GetLayerDefn( mLayer );
189+
188190
QgsDebugMsg( "created layer" );
189191

190192
// create the fields
@@ -193,7 +195,6 @@ QgsVectorFileWriter::QgsVectorFileWriter(
193195
mFields = fields;
194196
mAttrIdxToOgrIdx.clear();
195197

196-
int ogrIdx = 0;
197198
QgsFieldMap::const_iterator fldIt;
198199
for ( fldIt = fields.begin(); fldIt != fields.end(); ++fldIt )
199200
{
@@ -261,7 +262,18 @@ QgsVectorFileWriter::QgsVectorFileWriter(
261262
return;
262263
}
263264

264-
mAttrIdxToOgrIdx.insert( fldIt.key(), ogrIdx++ );
265+
int ogrIdx = OGR_FD_GetFieldIndex( defn, mCodec->fromUnicode( attrField.name() ) );
266+
if ( ogrIdx < 0 )
267+
{
268+
QgsDebugMsg( "error creating field " + attrField.name() );
269+
mErrorMessage = QObject::tr( "created field %1 not found (OGR error: %2)" )
270+
.arg( attrField.name() )
271+
.arg( QString::fromUtf8( CPLGetLastErrorMsg() ) );
272+
mError = ErrAttributeCreationFailed;
273+
return;
274+
}
275+
276+
mAttrIdxToOgrIdx.insert( fldIt.key(), ogrIdx );
265277
}
266278

267279
QgsDebugMsg( "Done creating fields" );

0 commit comments

Comments
 (0)