@@ -189,7 +189,7 @@ void QgsOgrProvider::loadFields()
189
189
case OFTReal: varType = QVariant::Double; break ;
190
190
// unsupported in OGR 1.3
191
191
// case OFTDateTime: varType = QVariant::DateTime; break;
192
- #if GDAL_VERSION_NUM >= 1400
192
+ #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1400
193
193
case OFTString: varType = QVariant::String; break ;
194
194
#endif
195
195
default : varType = QVariant::String; // other unsupported, leave it as a string
@@ -578,31 +578,31 @@ bool QgsOgrProvider::addAttributes( const QgsNewAttributesMap & attributes )
578
578
579
579
for ( QgsNewAttributesMap::const_iterator iter = attributes.begin (); iter != attributes.end (); ++iter )
580
580
{
581
- OGRFieldDefnH fielddefn =
582
- OGR_Fld_Create ( mEncoding ->fromUnicode ( iter.key () ).data (), OFTInteger );
581
+ OGRFieldDefnH fielddefn = OGR_Fld_Create ( mEncoding ->fromUnicode ( iter.key () ).data (), OFTInteger );
583
582
584
- if ( *iter == " OFTInteger " )
583
+ if ( *iter == " Integer " )
585
584
{
586
585
OGR_Fld_SetType ( fielddefn, OFTInteger );
586
+ OGR_Fld_SetWidth ( fielddefn, 10 );
587
587
}
588
- else if ( *iter == " OFTReal " )
588
+ else if ( *iter == " Real " )
589
589
{
590
590
OGR_Fld_SetType ( fielddefn, OFTReal );
591
591
}
592
- else if ( *iter == " OFTString " )
592
+ else if ( *iter == " String " )
593
593
{
594
594
OGR_Fld_SetType ( fielddefn, OFTString );
595
595
}
596
596
else
597
597
{
598
- QgsLogger::warning ( " QgsOgrProvider::addAttributes, type not found" );
598
+ QgsLogger::warning ( QString ( " QgsOgrProvider::addAttributes, type %1 not found" ). arg ( *iter ) );
599
599
returnvalue = false ;
600
600
continue ;
601
601
}
602
602
603
603
if ( OGR_L_CreateField ( ogrLayer, fielddefn, TRUE ) != OGRERR_NONE )
604
604
{
605
- QgsLogger::warning ( " QgsOgrProvider.cpp: writing of OFTInteger field failed" );
605
+ QgsLogger::warning ( " QgsOgrProvider.cpp: writing of field failed" );
606
606
returnvalue = false ;
607
607
}
608
608
OGR_Fld_Destroy ( fielddefn );
@@ -727,7 +727,7 @@ bool QgsOgrProvider::createSpatialIndex()
727
727
QString sql = QString ( " CREATE SPATIAL INDEX ON %1" ).arg ( quotedIdentifier ( fi.completeBaseName () ) ); // quote the layer name so spaces are handled
728
728
OGR_DS_ExecuteSQL ( ogrDataSource, mEncoding ->fromUnicode ( sql ).data (), OGR_L_GetSpatialFilter ( ogrLayer ), " " );
729
729
// find out, if the .qix file is there
730
- QFile indexfile ( fi.path ().append ( " /" ).append ( fi.completeBaseName () ).append ( " .qix" ) );
730
+ QFile indexfile ( fi.path ().append ( " /" ).append ( fi.completeBaseName () ).append ( " .qix" ) );
731
731
if ( indexfile.exists () )
732
732
{
733
733
return true ;
@@ -749,7 +749,7 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
749
749
}
750
750
}
751
751
752
- OGR_L_SyncToDisk ( ogrLayer );
752
+ OGR_L_SyncToDisk ( ogrLayer );
753
753
QFileInfo fi ( dataSourceUri () ); // to get the base name
754
754
QString sql = QString ( " REPACK %1" ).arg ( fi.completeBaseName () ); // don't quote the layer name as it works with spaces in the name and won't work if the name is quoted
755
755
OGR_DS_ExecuteSQL ( ogrDataSource, mEncoding ->fromUnicode ( sql ).data (), NULL , NULL );
@@ -852,9 +852,17 @@ int QgsOgrProvider::capabilities() const
852
852
{
853
853
// Ideally this should test for Shapefile type and GDAL >= 1.2.6
854
854
// In reality, createSpatialIndex() looks after itself.
855
- ability |= QgsVectorDataProvider:: CreateSpatialIndex;
855
+ ability |= CreateSpatialIndex;
856
856
}
857
857
858
+ #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1600
859
+ // adding attributes was added in GDAL 1.6
860
+ if ( ogrDriverName.startsWith ( " ESRI" ) )
861
+ {
862
+ ability |= AddAttributes;
863
+ }
864
+ #endif
865
+
858
866
// OGR doesn't handle shapefiles without attributes, ie. missing DBFs well, fixes #803
859
867
if ( ogrDriverName.startsWith ( " ESRI" ) && mAttributeFields .size () == 0 )
860
868
{
@@ -1216,7 +1224,7 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,
1216
1224
OGR_DS_Destroy ( dataSource );
1217
1225
1218
1226
QgsDebugMsg ( QString ( " GDAL Version number %1" ).arg ( GDAL_VERSION_NUM ) );
1219
- #if GDAL_VERSION_NUM >= 1310
1227
+ #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1310
1220
1228
if ( reference )
1221
1229
{
1222
1230
OSRRelease ( reference );
0 commit comments