@@ -53,10 +53,10 @@ QgsVectorFileWriter::QgsVectorFileWriter(
53
53
const QStringList &datasourceOptions,
54
54
const QStringList &layerOptions
55
55
)
56
- : mDS( NULL )
57
- , mLayer( NULL )
58
- , mGeom( NULL )
59
- , mError( NoError )
56
+ : mDS( NULL )
57
+ , mLayer( NULL )
58
+ , mGeom( NULL )
59
+ , mError( NoError )
60
60
{
61
61
QString vectorFileName = theVectorFileName;
62
62
QString fileEncoding = theFileEncoding;
@@ -66,7 +66,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
66
66
QgsApplication::registerOgrDrivers ();
67
67
poDriver = OGRGetDriverByName ( driverName.toLocal8Bit ().data () );
68
68
69
- if ( poDriver == NULL )
69
+ if ( poDriver == NULL )
70
70
{
71
71
mErrorMessage = QObject::tr ( " OGR driver for '%1' not found (OGR error: %2)" )
72
72
.arg ( driverName )
@@ -75,20 +75,20 @@ QgsVectorFileWriter::QgsVectorFileWriter(
75
75
return ;
76
76
}
77
77
78
- if ( driverName == " ESRI Shapefile" )
78
+ if ( driverName == " ESRI Shapefile" )
79
79
{
80
- if ( !vectorFileName.endsWith ( " .shp" , Qt::CaseInsensitive ) )
80
+ if ( !vectorFileName.endsWith ( " .shp" , Qt::CaseInsensitive ) )
81
81
{
82
82
vectorFileName += " .shp" ;
83
83
}
84
84
85
85
// check for unique fieldnames
86
86
QSet<QString> fieldNames;
87
87
QgsFieldMap::const_iterator fldIt;
88
- for ( fldIt = fields.begin (); fldIt != fields.end (); ++fldIt )
88
+ for ( fldIt = fields.begin (); fldIt != fields.end (); ++fldIt )
89
89
{
90
90
QString name = fldIt.value ().name ().left ( 10 );
91
- if ( fieldNames.contains ( name ) )
91
+ if ( fieldNames.contains ( name ) )
92
92
{
93
93
mErrorMessage = QObject::tr ( " trimming attribute name '%1' to ten significant characters produces duplicate column name." )
94
94
.arg ( fldIt.value ().name () );
@@ -100,14 +100,14 @@ QgsVectorFileWriter::QgsVectorFileWriter(
100
100
101
101
deleteShapeFile ( vectorFileName );
102
102
}
103
- else if ( driverName == " KML" )
103
+ else if ( driverName == " KML" )
104
104
{
105
- if ( !vectorFileName.endsWith ( " .kml" , Qt::CaseInsensitive ) )
105
+ if ( !vectorFileName.endsWith ( " .kml" , Qt::CaseInsensitive ) )
106
106
{
107
107
vectorFileName += " .kml" ;
108
108
}
109
109
110
- if ( fileEncoding.compare ( " UTF-8" , Qt::CaseInsensitive ) != 0 )
110
+ if ( fileEncoding.compare ( " UTF-8" , Qt::CaseInsensitive ) != 0 )
111
111
{
112
112
QgsDebugMsg ( " forced UTF-8 encoding for KML" );
113
113
fileEncoding = " UTF-8" ;
@@ -121,10 +121,10 @@ QgsVectorFileWriter::QgsVectorFileWriter(
121
121
}
122
122
123
123
char **options = NULL ;
124
- if ( !datasourceOptions.isEmpty () )
124
+ if ( !datasourceOptions.isEmpty () )
125
125
{
126
126
options = new char *[ datasourceOptions.size ()+1 ];
127
- for ( int i = 0 ; i < datasourceOptions.size (); i++ )
127
+ for ( int i = 0 ; i < datasourceOptions.size (); i++ )
128
128
{
129
129
options[i] = CPLStrdup ( datasourceOptions[i].toLocal8Bit ().data () );
130
130
}
@@ -134,15 +134,15 @@ QgsVectorFileWriter::QgsVectorFileWriter(
134
134
// create the data source
135
135
mDS = OGR_Dr_CreateDataSource ( poDriver, vectorFileName.toLocal8Bit ().data (), options );
136
136
137
- if ( options )
137
+ if ( options )
138
138
{
139
- for ( int i = 0 ; i < datasourceOptions.size (); i++ )
139
+ for ( int i = 0 ; i < datasourceOptions.size (); i++ )
140
140
CPLFree ( options[i] );
141
141
delete [] options;
142
142
options = NULL ;
143
143
}
144
144
145
- if ( mDS == NULL )
145
+ if ( mDS == NULL )
146
146
{
147
147
mError = ErrCreateDataSource;
148
148
mErrorMessage = QObject::tr ( " creation of data source failed (OGR error:%1)" )
@@ -154,13 +154,13 @@ QgsVectorFileWriter::QgsVectorFileWriter(
154
154
155
155
// use appropriate codec
156
156
mCodec = QTextCodec::codecForName ( fileEncoding.toLocal8Bit ().data () );
157
- if ( !mCodec )
157
+ if ( !mCodec )
158
158
{
159
159
QSettings settings;
160
160
QString enc = settings.value ( " /UI/encoding" , QString ( " System" ) ).toString ();
161
161
QgsDebugMsg ( " error finding QTextCodec for " + fileEncoding );
162
162
mCodec = QTextCodec::codecForName ( enc.toLocal8Bit ().data () );
163
- if ( !mCodec )
163
+ if ( !mCodec )
164
164
{
165
165
QgsDebugMsg ( " error finding QTextCodec for " + enc );
166
166
mCodec = QTextCodec::codecForLocale ();
@@ -169,7 +169,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
169
169
170
170
// consider spatial reference system of the layer
171
171
OGRSpatialReferenceH ogrRef = NULL ;
172
- if ( srs )
172
+ if ( srs )
173
173
{
174
174
QString srsWkt = srs->toWkt ();
175
175
QgsDebugMsg ( " WKT to save as is " + srsWkt );
@@ -180,10 +180,10 @@ QgsVectorFileWriter::QgsVectorFileWriter(
180
180
QString layerName = QFileInfo ( vectorFileName ).baseName ();
181
181
OGRwkbGeometryType wkbType = static_cast <OGRwkbGeometryType>( geometryType );
182
182
183
- if ( !layerOptions.isEmpty () )
183
+ if ( !layerOptions.isEmpty () )
184
184
{
185
185
options = new char *[ layerOptions.size ()+1 ];
186
- for ( int i = 0 ; i < layerOptions.size (); i++ )
186
+ for ( int i = 0 ; i < layerOptions.size (); i++ )
187
187
{
188
188
options[i] = CPLStrdup ( layerOptions[i].toLocal8Bit ().data () );
189
189
}
@@ -192,21 +192,21 @@ QgsVectorFileWriter::QgsVectorFileWriter(
192
192
193
193
mLayer = OGR_DS_CreateLayer ( mDS , QFile::encodeName ( layerName ).data (), ogrRef, wkbType, options );
194
194
195
- if ( options )
195
+ if ( options )
196
196
{
197
- for ( int i = 0 ; i < layerOptions.size (); i++ )
197
+ for ( int i = 0 ; i < layerOptions.size (); i++ )
198
198
CPLFree ( options[i] );
199
199
delete [] options;
200
200
options = NULL ;
201
201
}
202
202
203
- if ( srs )
203
+ if ( srs )
204
204
{
205
- if ( driverName == " ESRI Shapefile" )
205
+ if ( driverName == " ESRI Shapefile" )
206
206
{
207
207
QString layerName = vectorFileName.left ( vectorFileName.indexOf ( " .shp" , Qt::CaseInsensitive ) );
208
208
QFile prjFile ( layerName + " .qpj" );
209
- if ( prjFile.open ( QIODevice::WriteOnly ) )
209
+ if ( prjFile.open ( QIODevice::WriteOnly ) )
210
210
{
211
211
QTextStream prjStream ( &prjFile );
212
212
prjStream << srs->toWkt ().toLocal8Bit ().data () << endl;
@@ -221,7 +221,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
221
221
OSRDestroySpatialReference ( ogrRef );
222
222
}
223
223
224
- if ( mLayer == NULL )
224
+ if ( mLayer == NULL )
225
225
{
226
226
mErrorMessage = QObject::tr ( " creation of layer failed (OGR error:%1)" )
227
227
.arg ( QString::fromUtf8 ( CPLGetLastErrorMsg () ) );
@@ -240,14 +240,14 @@ QgsVectorFileWriter::QgsVectorFileWriter(
240
240
mAttrIdxToOgrIdx .clear ();
241
241
242
242
QgsFieldMap::const_iterator fldIt;
243
- for ( fldIt = fields.begin (); fldIt != fields.end (); ++fldIt )
243
+ for ( fldIt = fields.begin (); fldIt != fields.end (); ++fldIt )
244
244
{
245
245
const QgsField& attrField = fldIt.value ();
246
246
247
247
OGRFieldType ogrType = OFTString; // default to string
248
248
int ogrWidth = fldIt->length ();
249
249
int ogrPrecision = fldIt->precision ();
250
- switch ( attrField.type () )
250
+ switch ( attrField.type () )
251
251
{
252
252
case QVariant::LongLong:
253
253
ogrType = OFTString;
@@ -257,7 +257,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
257
257
258
258
case QVariant::String:
259
259
ogrType = OFTString;
260
- if ( ogrWidth < 0 || ogrWidth > 255 )
260
+ if ( ogrWidth < 0 || ogrWidth > 255 )
261
261
ogrWidth = 255 ;
262
262
break ;
263
263
@@ -281,12 +281,12 @@ QgsVectorFileWriter::QgsVectorFileWriter(
281
281
282
282
// create field definition
283
283
OGRFieldDefnH fld = OGR_Fld_Create ( mCodec ->fromUnicode ( attrField.name () ), ogrType );
284
- if ( ogrWidth > 0 )
284
+ if ( ogrWidth > 0 )
285
285
{
286
286
OGR_Fld_SetWidth ( fld, ogrWidth );
287
287
}
288
288
289
- if ( ogrPrecision >= 0 )
289
+ if ( ogrPrecision >= 0 )
290
290
{
291
291
OGR_Fld_SetPrecision ( fld, ogrPrecision );
292
292
}
@@ -296,7 +296,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
296
296
" type " + QString ( QVariant::typeToName ( attrField.type () ) ) +
297
297
" width " + QString::number ( ogrWidth ) +
298
298
" precision " + QString::number ( ogrPrecision ) );
299
- if ( OGR_L_CreateField ( mLayer , fld, true ) != OGRERR_NONE )
299
+ if ( OGR_L_CreateField ( mLayer , fld, true ) != OGRERR_NONE )
300
300
{
301
301
QgsDebugMsg ( " error creating field " + attrField.name () );
302
302
mErrorMessage = QObject::tr ( " creation of field %1 failed (OGR error: %2)" )
@@ -307,24 +307,24 @@ QgsVectorFileWriter::QgsVectorFileWriter(
307
307
}
308
308
309
309
int ogrIdx = OGR_FD_GetFieldIndex ( defn, mCodec ->fromUnicode ( attrField.name () ) );
310
- if ( ogrIdx < 0 )
310
+ if ( ogrIdx < 0 )
311
311
{
312
312
// if we didn't find our new column, assume it's name was truncated and
313
313
// it was the last one added (like for shape files)
314
314
int fieldCount = OGR_FD_GetFieldCount ( defn );
315
315
316
316
OGRFieldDefnH fdefn = OGR_FD_GetFieldDefn ( defn, fieldCount - 1 );
317
- if ( fdefn )
317
+ if ( fdefn )
318
318
{
319
319
const char *fieldName = OGR_Fld_GetNameRef ( fdefn );
320
320
321
- if ( attrField.name ().left ( strlen ( fieldName ) ) == fieldName )
321
+ if ( attrField.name ().left ( strlen ( fieldName ) ) == fieldName )
322
322
{
323
323
ogrIdx = fieldCount - 1 ;
324
324
}
325
325
}
326
326
327
- if ( ogrIdx < 0 )
327
+ if ( ogrIdx < 0 )
328
328
{
329
329
QgsDebugMsg ( " error creating field " + attrField.name () );
330
330
mErrorMessage = QObject::tr ( " created field %1 not found (OGR error: %2)" )
@@ -370,15 +370,15 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
370
370
371
371
// attribute handling
372
372
QgsFieldMap::const_iterator fldIt;
373
- for ( fldIt = mFields .begin (); fldIt != mFields .end (); ++fldIt )
373
+ for ( fldIt = mFields .begin (); fldIt != mFields .end (); ++fldIt )
374
374
{
375
- if ( !feature.attributeMap ().contains ( fldIt.key () ) )
375
+ if ( !feature.attributeMap ().contains ( fldIt.key () ) )
376
376
{
377
377
QgsDebugMsg ( QString ( " no attribute for field %1" ).arg ( fldIt.key () ) );
378
378
continue ;
379
379
}
380
380
381
- if ( !mAttrIdxToOgrIdx .contains ( fldIt.key () ) )
381
+ if ( !mAttrIdxToOgrIdx .contains ( fldIt.key () ) )
382
382
{
383
383
QgsDebugMsg ( QString ( " no ogr field for field %1" ).arg ( fldIt.key () ) );
384
384
continue ;
@@ -387,7 +387,7 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
387
387
const QVariant& attrValue = feature.attributeMap ()[ fldIt.key ()];
388
388
int ogrField = mAttrIdxToOgrIdx [ fldIt.key ()];
389
389
390
- switch ( attrValue.type () )
390
+ switch ( attrValue.type () )
391
391
{
392
392
case QVariant::Int:
393
393
OGR_F_SetFieldInteger ( poFeature, ogrField, attrValue.toInt () );
@@ -413,16 +413,7 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
413
413
414
414
// build geometry from WKB
415
415
QgsGeometry *geom = feature.geometry ();
416
- if ( !geom )
417
- {
418
- QgsDebugMsg ( " invalid geometry" );
419
- mErrorMessage = QObject::tr ( " Invalid feature geometry" );
420
- mError = ErrFeatureWriteFailed;
421
- OGR_F_Destroy ( poFeature );
422
- return false ;
423
- }
424
-
425
- if ( geom->wkbType () != mWkbType )
416
+ if ( geom && geom->wkbType () != mWkbType )
426
417
{
427
418
// there's a problem when layer type is set as wkbtype Polygon
428
419
// although there are also features of type MultiPolygon
@@ -435,7 +426,7 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
435
426
436
427
OGRGeometryH mGeom2 = createEmptyGeometry ( geom->wkbType () );
437
428
438
- if ( !mGeom2 )
429
+ if ( !mGeom2 )
439
430
{
440
431
QgsDebugMsg ( QString ( " Failed to create empty geometry for type %1 (OGR error: %2)" ).arg ( geom->wkbType () ).arg ( CPLGetLastErrorMsg () ) );
441
432
mErrorMessage = QObject::tr ( " Feature geometry not imported (OGR error: %1)" )
@@ -446,7 +437,7 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
446
437
}
447
438
448
439
OGRErr err = OGR_G_ImportFromWkb ( mGeom2 , geom->asWkb (), geom->wkbSize () );
449
- if ( err != OGRERR_NONE )
440
+ if ( err != OGRERR_NONE )
450
441
{
451
442
QgsDebugMsg ( QString ( " Failed to import geometry from WKB: %1 (OGR error: %2)" ).arg ( err ).arg ( CPLGetLastErrorMsg () ) );
452
443
mErrorMessage = QObject::tr ( " Feature geometry not imported (OGR error: %1)" )
@@ -459,10 +450,10 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
459
450
// pass ownership to geometry
460
451
OGR_F_SetGeometryDirectly ( poFeature, mGeom2 );
461
452
}
462
- else
453
+ else if ( geom )
463
454
{
464
455
OGRErr err = OGR_G_ImportFromWkb ( mGeom , geom->asWkb (), geom->wkbSize () );
465
- if ( err != OGRERR_NONE )
456
+ if ( err != OGRERR_NONE )
466
457
{
467
458
QgsDebugMsg ( QString ( " Failed to import geometry from WKB: %1 (OGR error: %2)" ).arg ( err ).arg ( CPLGetLastErrorMsg () ) );
468
459
mErrorMessage = QObject::tr ( " Feature geometry not imported (OGR error: %1)" )
@@ -477,7 +468,7 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
477
468
}
478
469
479
470
// put the created feature to layer
480
- if ( OGR_L_CreateFeature ( mLayer , poFeature ) != OGRERR_NONE )
471
+ if ( OGR_L_CreateFeature ( mLayer , poFeature ) != OGRERR_NONE )
481
472
{
482
473
mErrorMessage = QObject::tr ( " Feature creation error (OGR error: %1)" ).arg ( QString::fromUtf8 ( CPLGetLastErrorMsg () ) );
483
474
mError = ErrFeatureWriteFailed;
@@ -494,12 +485,12 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
494
485
495
486
QgsVectorFileWriter::~QgsVectorFileWriter ()
496
487
{
497
- if ( mGeom )
488
+ if ( mGeom )
498
489
{
499
490
OGR_G_DestroyGeometry ( mGeom );
500
491
}
501
492
502
- if ( mDS )
493
+ if ( mDS )
503
494
{
504
495
OGR_DS_Destroy ( mDS );
505
496
}
@@ -537,7 +528,7 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
537
528
QgsCoordinateTransform* ct = 0 ;
538
529
int shallTransform = false ;
539
530
540
- if ( destCRS && destCRS->isValid () )
531
+ if ( destCRS && destCRS->isValid () )
541
532
{
542
533
// This means we should transform
543
534
outputCRS = destCRS;
@@ -553,15 +544,15 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
553
544
554
545
// check whether file creation was successful
555
546
WriterError err = writer->hasError ();
556
- if ( err != NoError )
547
+ if ( err != NoError )
557
548
{
558
- if ( errorMessage )
549
+ if ( errorMessage )
559
550
*errorMessage = writer->errorMessage ();
560
551
delete writer;
561
552
return err;
562
553
}
563
554
564
- if ( errorMessage )
555
+ if ( errorMessage )
565
556
{
566
557
errorMessage->clear ();
567
558
}
@@ -574,68 +565,68 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
574
565
const QgsFeatureIds& ids = layer->selectedFeaturesIds ();
575
566
576
567
// Create our transform
577
- if ( destCRS )
568
+ if ( destCRS )
578
569
{
579
570
ct = new QgsCoordinateTransform ( layer->srs (), *destCRS );
580
571
}
581
572
582
573
// Check for failure
583
- if ( ct == NULL )
574
+ if ( ct == NULL )
584
575
{
585
576
shallTransform = false ;
586
577
}
587
578
588
579
int n = 0 , errors = 0 ;
589
580
590
581
// write all features
591
- while ( layer->nextFeature ( fet ) )
582
+ while ( layer->nextFeature ( fet ) )
592
583
{
593
- if ( onlySelected && !ids.contains ( fet.id () ) )
584
+ if ( onlySelected && !ids.contains ( fet.id () ) )
594
585
continue ;
595
586
596
- if ( shallTransform )
587
+ if ( shallTransform )
597
588
{
598
589
try
599
590
{
600
- if ( fet.geometry () )
591
+ if ( fet.geometry () )
601
592
{
602
593
fet.geometry ()->transform ( *ct );
603
594
}
604
595
}
605
- catch ( QgsCsException &e )
596
+ catch ( QgsCsException &e )
606
597
{
607
598
delete ct;
608
599
delete writer;
609
600
610
601
QString msg = QObject::tr ( " Failed to transform a point while drawing a feature of type '%1'. Writing stopped. (Exception: %2)" )
611
602
.arg ( fet.typeName () ).arg ( e.what () );
612
603
QgsLogger::warning ( msg );
613
- if ( errorMessage )
604
+ if ( errorMessage )
614
605
*errorMessage = msg;
615
606
616
607
return ErrProjection;
617
608
}
618
609
}
619
- if ( skipAttributeCreation )
610
+ if ( skipAttributeCreation )
620
611
{
621
612
fet.clearAttributeMap ();
622
613
}
623
- if ( !writer->addFeature ( fet ) )
614
+ if ( !writer->addFeature ( fet ) )
624
615
{
625
616
WriterError err = writer->hasError ();
626
- if ( err != NoError && errorMessage )
617
+ if ( err != NoError && errorMessage )
627
618
{
628
- if ( errorMessage->isEmpty () )
619
+ if ( errorMessage->isEmpty () )
629
620
{
630
621
*errorMessage = QObject::tr ( " Feature write errors:" );
631
622
}
632
623
*errorMessage += " \n " + writer->errorMessage ();
633
624
}
634
625
errors++;
635
626
636
- if ( errors > 1000 )
627
+ if ( errors > 1000 )
637
628
{
638
- if ( errorMessage )
629
+ if ( errorMessage )
639
630
{
640
631
*errorMessage += QObject::tr ( " Stopping after %1 errors" ).arg ( errors );
641
632
}
@@ -649,12 +640,12 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
649
640
650
641
delete writer;
651
642
652
- if ( shallTransform )
643
+ if ( shallTransform )
653
644
{
654
645
delete ct;
655
646
}
656
647
657
- if ( errors > 0 && errorMessage && n > 0 )
648
+ if ( errors > 0 && errorMessage && n > 0 )
658
649
{
659
650
*errorMessage += QObject::tr ( " \n Only %1 of %2 features written." ).arg ( n - errors ).arg ( n );
660
651
}
@@ -670,15 +661,15 @@ bool QgsVectorFileWriter::deleteShapeFile( QString theFileName )
670
661
671
662
QStringList filter;
672
663
const char *suffixes[] = { " .shp" , " .shx" , " .dbf" , " .prj" , " .qix" , " .qpj" };
673
- for ( std::size_t i = 0 ; i < sizeof ( suffixes ) / sizeof ( *suffixes ); i++ )
664
+ for ( std::size_t i = 0 ; i < sizeof ( suffixes ) / sizeof ( *suffixes ); i++ )
674
665
{
675
666
filter << fi.completeBaseName () + suffixes[i];
676
667
}
677
668
678
669
bool ok = true ;
679
670
foreach ( QString file, dir.entryList ( filter ) )
680
671
{
681
- if ( !QFile::remove ( dir.canonicalPath () + " /" + file ) )
672
+ if ( !QFile::remove ( dir.canonicalPath () + " /" + file ) )
682
673
{
683
674
QgsDebugMsg ( " Removing file failed : " + file );
684
675
ok = false ;
@@ -695,16 +686,16 @@ QMap< QString, QString> QgsVectorFileWriter::supportedFiltersAndFormats()
695
686
QgsApplication::registerOgrDrivers ();
696
687
int const drvCount = OGRGetDriverCount ();
697
688
698
- for ( int i = 0 ; i < drvCount; ++i )
689
+ for ( int i = 0 ; i < drvCount; ++i )
699
690
{
700
691
OGRSFDriverH drv = OGRGetDriver ( i );
701
- if ( drv )
692
+ if ( drv )
702
693
{
703
694
QString drvName = OGR_Dr_GetName ( drv );
704
- if ( OGR_Dr_TestCapability ( drv, " CreateDataSource" ) != 0 )
695
+ if ( OGR_Dr_TestCapability ( drv, " CreateDataSource" ) != 0 )
705
696
{
706
697
QString filterString = filterForDriver ( drvName );
707
- if ( filterString.isEmpty () )
698
+ if ( filterString.isEmpty () )
708
699
continue ;
709
700
710
701
resultMap.insert ( filterString, drvName );
@@ -722,16 +713,16 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
722
713
QgsApplication::registerOgrDrivers ();
723
714
int const drvCount = OGRGetDriverCount ();
724
715
725
- for ( int i = 0 ; i < drvCount; ++i )
716
+ for ( int i = 0 ; i < drvCount; ++i )
726
717
{
727
718
OGRSFDriverH drv = OGRGetDriver ( i );
728
- if ( drv )
719
+ if ( drv )
729
720
{
730
721
QString drvName = OGR_Dr_GetName ( drv );
731
- if ( OGR_Dr_TestCapability ( drv, " CreateDataSource" ) != 0 )
722
+ if ( OGR_Dr_TestCapability ( drv, " CreateDataSource" ) != 0 )
732
723
{
733
724
QPair<QString, QString> p = nameAndGlob ( drvName );
734
- if ( p.first .isEmpty () )
725
+ if ( p.first .isEmpty () )
735
726
continue ;
736
727
737
728
resultMap.insert ( p.first , drvName );
@@ -747,9 +738,9 @@ QString QgsVectorFileWriter::fileFilterString()
747
738
QString filterString;
748
739
QMap< QString, QString> driverFormatMap = supportedFiltersAndFormats ();
749
740
QMap< QString, QString>::const_iterator it = driverFormatMap.constBegin ();
750
- for ( ; it != driverFormatMap.constEnd (); ++it )
741
+ for ( ; it != driverFormatMap.constEnd (); ++it )
751
742
{
752
- if ( filterString.isEmpty () )
743
+ if ( filterString.isEmpty () )
753
744
filterString += " ;;" ;
754
745
755
746
filterString += it.key ();
@@ -761,7 +752,7 @@ QString QgsVectorFileWriter::filterForDriver( const QString& driverName )
761
752
{
762
753
QPair<QString, QString> p = nameAndGlob ( driverName );
763
754
764
- if ( p.first .isEmpty () || p.second .isEmpty () )
755
+ if ( p.first .isEmpty () || p.second .isEmpty () )
765
756
return " " ;
766
757
767
758
return " [OGR] " + p.first + " (" + p.second .toLower () + " " + p.second .toUpper () + " )" ;
@@ -772,102 +763,102 @@ QPair<QString, QString> QgsVectorFileWriter::nameAndGlob( QString driverName )
772
763
QString longName;
773
764
QString glob;
774
765
775
- if ( driverName.startsWith ( " AVCE00" ) )
766
+ if ( driverName.startsWith ( " AVCE00" ) )
776
767
{
777
768
longName = " Arc/Info ASCII Coverage" ;
778
769
glob = " *.e00" ;
779
770
}
780
- else if ( driverName.startsWith ( " BNA" ) )
771
+ else if ( driverName.startsWith ( " BNA" ) )
781
772
{
782
773
longName = " Atlas BNA" ;
783
774
glob = " *.bna" ;
784
775
}
785
- else if ( driverName.startsWith ( " CSV" ) )
776
+ else if ( driverName.startsWith ( " CSV" ) )
786
777
{
787
778
longName = " Comma Separated Value" ;
788
779
glob = " *.csv" ;
789
780
}
790
- else if ( driverName.startsWith ( " ESRI" ) )
781
+ else if ( driverName.startsWith ( " ESRI" ) )
791
782
{
792
783
longName = " ESRI Shapefile" ;
793
784
glob = " *.shp" ;
794
785
}
795
- else if ( driverName.startsWith ( " FMEObjects Gateway" ) )
786
+ else if ( driverName.startsWith ( " FMEObjects Gateway" ) )
796
787
{
797
788
longName = " FMEObjects Gateway" ;
798
789
glob = " *.fdd" ;
799
790
}
800
- else if ( driverName.startsWith ( " GeoJSON" ) )
791
+ else if ( driverName.startsWith ( " GeoJSON" ) )
801
792
{
802
793
longName = " GeoJSON" ;
803
794
glob = " *.geojson" ;
804
795
}
805
- else if ( driverName.startsWith ( " GeoRSS" ) )
796
+ else if ( driverName.startsWith ( " GeoRSS" ) )
806
797
{
807
798
longName = " GeoRSS" ;
808
799
glob = " *.xml" ;
809
800
}
810
- else if ( driverName.startsWith ( " GML" ) )
801
+ else if ( driverName.startsWith ( " GML" ) )
811
802
{
812
803
longName = " Geography Markup Language (GML)" ;
813
804
glob = " *.gml" ;
814
805
}
815
- else if ( driverName.startsWith ( " GMT" ) )
806
+ else if ( driverName.startsWith ( " GMT" ) )
816
807
{
817
808
longName = " Generic Mapping Tools (GMT)" ;
818
809
glob = " *.gmt" ;
819
810
}
820
- else if ( driverName.startsWith ( " GPX" ) )
811
+ else if ( driverName.startsWith ( " GPX" ) )
821
812
{
822
813
longName = " GPS eXchange Format" ;
823
814
glob = " *.gpx" ;
824
815
}
825
- else if ( driverName.startsWith ( " Interlis 1" ) )
816
+ else if ( driverName.startsWith ( " Interlis 1" ) )
826
817
{
827
818
longName = " INTERLIS 1" ;
828
819
glob = " *.itf *.xml *.ili" ;
829
820
}
830
- else if ( driverName.startsWith ( " Interlis 2" ) )
821
+ else if ( driverName.startsWith ( " Interlis 2" ) )
831
822
{
832
823
longName = " INTERLIS 2" ;
833
824
glob = " *.itf *.xml *.ili" ;
834
825
}
835
- else if ( driverName.startsWith ( " KML" ) )
826
+ else if ( driverName.startsWith ( " KML" ) )
836
827
{
837
828
longName = " Keyhole Markup Language (KML)" ;
838
829
glob = " *.kml" ;
839
830
}
840
- else if ( driverName.startsWith ( " MapInfo File" ) )
831
+ else if ( driverName.startsWith ( " MapInfo File" ) )
841
832
{
842
833
longName = " Mapinfo File" ;
843
834
glob = " *.mif *.tab" ;
844
835
}
845
- else if ( driverName.startsWith ( " DGN" ) )
836
+ else if ( driverName.startsWith ( " DGN" ) )
846
837
{
847
838
longName = " Microstation DGN" ;
848
839
glob = " *.dgn" ;
849
840
}
850
- else if ( driverName.startsWith ( " S57" ) )
841
+ else if ( driverName.startsWith ( " S57" ) )
851
842
{
852
843
longName = " S-57 Base file" ;
853
844
glob = " *.000" ;
854
845
}
855
- else if ( driverName.startsWith ( " SDTS" ) )
846
+ else if ( driverName.startsWith ( " SDTS" ) )
856
847
{
857
848
longName = " Spatial Data Transfer Standard (SDTS)" ;
858
849
glob = " *catd.ddf" ;
859
850
}
860
- else if ( driverName.startsWith ( " SQLite" ) )
851
+ else if ( driverName.startsWith ( " SQLite" ) )
861
852
{
862
853
longName = " SQLite" ;
863
854
glob = " *.sqlite" ;
864
855
}
865
- else if ( driverName.startsWith ( " DXF" ) )
856
+ else if ( driverName.startsWith ( " DXF" ) )
866
857
{
867
858
longName = " AutoCAD DXF" ;
868
859
glob = " *.dxf" ;
869
860
}
870
- else if ( driverName.startsWith ( " Geoconcept" ) )
861
+ else if ( driverName.startsWith ( " Geoconcept" ) )
871
862
{
872
863
longName = " Geoconcept" ;
873
864
glob = " *.gxt *.txt" ;
0 commit comments