File tree Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -309,12 +309,30 @@ QgsVectorFileWriter::QgsVectorFileWriter(
309
309
int ogrIdx = OGR_FD_GetFieldIndex ( defn, mCodec ->fromUnicode ( attrField.name () ) );
310
310
if ( ogrIdx < 0 )
311
311
{
312
- QgsDebugMsg ( " error creating field " + attrField.name () );
313
- mErrorMessage = QObject::tr ( " created field %1 not found (OGR error: %2)" )
314
- .arg ( attrField.name () )
315
- .arg ( QString::fromUtf8 ( CPLGetLastErrorMsg () ) );
316
- mError = ErrAttributeCreationFailed;
317
- return ;
312
+ // if we didn't find our new column, assume it's name was truncated and
313
+ // it was the last one added (like for shape files)
314
+ int fieldCount = OGR_FD_GetFieldCount ( defn );
315
+
316
+ OGRFieldDefnH fdefn = OGR_FD_GetFieldDefn ( defn, fieldCount - 1 );
317
+ if ( fdefn )
318
+ {
319
+ const char *fieldName = OGR_Fld_GetNameRef ( fdefn );
320
+
321
+ if ( attrField.name ().left ( strlen ( fieldName ) ) == fieldName )
322
+ {
323
+ ogrIdx = fieldCount - 1 ;
324
+ }
325
+ }
326
+
327
+ if ( ogrIdx < 0 )
328
+ {
329
+ QgsDebugMsg ( " error creating field " + attrField.name () );
330
+ mErrorMessage = QObject::tr ( " created field %1 not found (OGR error: %2)" )
331
+ .arg ( attrField.name () )
332
+ .arg ( QString::fromUtf8 ( CPLGetLastErrorMsg () ) );
333
+ mError = ErrAttributeCreationFailed;
334
+ return ;
335
+ }
318
336
}
319
337
320
338
mAttrIdxToOgrIdx .insert ( fldIt.key (), ogrIdx );
You can’t perform that action at this time.
0 commit comments