Skip to content

Commit 9caf1be

Browse files
author
jef
committed
apply #1446
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9982 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d4627b6 commit 9caf1be

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/providers/ogr/qgsogrprovider.cpp

+20-12
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void QgsOgrProvider::loadFields()
189189
case OFTReal: varType = QVariant::Double; break;
190190
// unsupported in OGR 1.3
191191
//case OFTDateTime: varType = QVariant::DateTime; break;
192-
#if GDAL_VERSION_NUM >= 1400
192+
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1400
193193
case OFTString: varType = QVariant::String; break;
194194
#endif
195195
default: varType = QVariant::String; // other unsupported, leave it as a string
@@ -578,31 +578,31 @@ bool QgsOgrProvider::addAttributes( const QgsNewAttributesMap & attributes )
578578

579579
for ( QgsNewAttributesMap::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter )
580580
{
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 );
583582

584-
if ( *iter == "OFTInteger" )
583+
if ( *iter == "Integer" )
585584
{
586585
OGR_Fld_SetType( fielddefn, OFTInteger );
586+
OGR_Fld_SetWidth( fielddefn, 10 );
587587
}
588-
else if ( *iter == "OFTReal" )
588+
else if ( *iter == "Real" )
589589
{
590590
OGR_Fld_SetType( fielddefn, OFTReal );
591591
}
592-
else if ( *iter == "OFTString" )
592+
else if ( *iter == "String" )
593593
{
594594
OGR_Fld_SetType( fielddefn, OFTString );
595595
}
596596
else
597597
{
598-
QgsLogger::warning( "QgsOgrProvider::addAttributes, type not found" );
598+
QgsLogger::warning( QString( "QgsOgrProvider::addAttributes, type %1 not found" ).arg( *iter ) );
599599
returnvalue = false;
600600
continue;
601601
}
602602

603603
if ( OGR_L_CreateField( ogrLayer, fielddefn, TRUE ) != OGRERR_NONE )
604604
{
605-
QgsLogger::warning( "QgsOgrProvider.cpp: writing of OFTInteger field failed" );
605+
QgsLogger::warning( "QgsOgrProvider.cpp: writing of field failed" );
606606
returnvalue = false;
607607
}
608608
OGR_Fld_Destroy( fielddefn );
@@ -727,7 +727,7 @@ bool QgsOgrProvider::createSpatialIndex()
727727
QString sql = QString( "CREATE SPATIAL INDEX ON %1" ).arg( quotedIdentifier( fi.completeBaseName() ) ); // quote the layer name so spaces are handled
728728
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), OGR_L_GetSpatialFilter( ogrLayer ), "" );
729729
//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" ) );
731731
if ( indexfile.exists() )
732732
{
733733
return true;
@@ -749,7 +749,7 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
749749
}
750750
}
751751

752-
OGR_L_SyncToDisk( ogrLayer );
752+
OGR_L_SyncToDisk( ogrLayer );
753753
QFileInfo fi( dataSourceUri() ); // to get the base name
754754
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
755755
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, NULL );
@@ -852,9 +852,17 @@ int QgsOgrProvider::capabilities() const
852852
{
853853
// Ideally this should test for Shapefile type and GDAL >= 1.2.6
854854
// In reality, createSpatialIndex() looks after itself.
855-
ability |= QgsVectorDataProvider::CreateSpatialIndex;
855+
ability |= CreateSpatialIndex;
856856
}
857857

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+
858866
// OGR doesn't handle shapefiles without attributes, ie. missing DBFs well, fixes #803
859867
if ( ogrDriverName.startsWith( "ESRI" ) && mAttributeFields.size() == 0 )
860868
{
@@ -1216,7 +1224,7 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,
12161224
OGR_DS_Destroy( dataSource );
12171225

12181226
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
12201228
if ( reference )
12211229
{
12221230
OSRRelease( reference );

src/providers/ogr/qgsogrprovider.h

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class QgsOgrProvider : public QgsVectorDataProvider
247247

248248
//! Selection rectangle
249249
OGRGeometryH mSelectionRectangle;
250+
250251
/**Adds one feature*/
251252
bool addFeature( QgsFeature& f );
252253
/**Deletes one feature*/

0 commit comments

Comments
 (0)