Skip to content

Commit 03dd26e

Browse files
committedMay 3, 2017
Adapt to GDAL 2.0 API
1 parent ce4f93b commit 03dd26e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed
 

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <ogr_srs_api.h>
5050
#include <cpl_error.h>
5151
#include <cpl_conv.h>
52+
#include <cpl_string.h>
5253
#include <gdal.h>
5354

5455
QgsVectorFileWriter::FieldValueConverter::FieldValueConverter()
@@ -2749,21 +2750,27 @@ QString QgsVectorFileWriter::driverForExtension( const QString &extension )
27492750
QString ext = extension.trimmed();
27502751
if ( ext.isEmpty() )
27512752
return QString();
2752-
QgsApplication::registerOgrDrivers();
2753-
int const drvCount = OGRGetDriverCount();
2753+
2754+
if ( ext.startsWith( '.' ) )
2755+
ext.remove( 0, 1 );
2756+
2757+
GDALAllRegister();
2758+
int const drvCount = GDALGetDriverCount();
27542759

27552760
for ( int i = 0; i < drvCount; ++i )
27562761
{
2757-
OGRSFDriverH drv = OGRGetDriver( i );
2762+
GDALDriverH drv = GDALGetDriver( i );
27582763
if ( drv )
27592764
{
2760-
QString drvName = OGR_Dr_GetName( drv );
2761-
if ( OGR_Dr_TestCapability( drv, "CreateDataSource" ) != 0 )
2765+
char **driverMetadata = GDALGetMetadata( drv, nullptr );
2766+
if ( CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, false ) && CSLFetchBoolean( driverMetadata, GDAL_DCAP_VECTOR, false ) )
27622767
{
2763-
MetaData metadata;
2764-
if ( driverMetadata( drvName, metadata ) )
2768+
QString drvName = GDALGetDriverShortName( drv );
2769+
QStringList driverExtensions = QString( GDALGetMetadataItem( drv, GDAL_DMD_EXTENSIONS, nullptr ) ).split( ' ' );
2770+
2771+
Q_FOREACH ( const QString &driver, driverExtensions )
27652772
{
2766-
if ( metadata.glob.contains( ext, Qt::CaseInsensitive ) )
2773+
if ( driver.compare( ext, Qt::CaseInsensitive ) == 0 )
27672774
return drvName;
27682775
}
27692776
}

0 commit comments

Comments
 (0)