File tree 1 file changed +14
-2
lines changed
1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,8 @@ QgsVectorFileWriter::QgsVectorFileWriter(
185
185
return ;
186
186
}
187
187
188
+ OGRFeatureDefnH defn = OGR_L_GetLayerDefn ( mLayer );
189
+
188
190
QgsDebugMsg ( " created layer" );
189
191
190
192
// create the fields
@@ -193,7 +195,6 @@ QgsVectorFileWriter::QgsVectorFileWriter(
193
195
mFields = fields;
194
196
mAttrIdxToOgrIdx .clear ();
195
197
196
- int ogrIdx = 0 ;
197
198
QgsFieldMap::const_iterator fldIt;
198
199
for ( fldIt = fields.begin (); fldIt != fields.end (); ++fldIt )
199
200
{
@@ -261,7 +262,18 @@ QgsVectorFileWriter::QgsVectorFileWriter(
261
262
return ;
262
263
}
263
264
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 );
265
277
}
266
278
267
279
QgsDebugMsg ( " Done creating fields" );
You can’t perform that action at this time.
0 commit comments