|
49 | 49 | #include <ogr_srs_api.h>
|
50 | 50 | #include <cpl_error.h>
|
51 | 51 | #include <cpl_conv.h>
|
| 52 | +#include <cpl_string.h> |
52 | 53 | #include <gdal.h>
|
53 | 54 |
|
54 | 55 | QgsVectorFileWriter::FieldValueConverter::FieldValueConverter()
|
@@ -2749,21 +2750,27 @@ QString QgsVectorFileWriter::driverForExtension( const QString &extension )
|
2749 | 2750 | QString ext = extension.trimmed();
|
2750 | 2751 | if ( ext.isEmpty() )
|
2751 | 2752 | 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(); |
2754 | 2759 |
|
2755 | 2760 | for ( int i = 0; i < drvCount; ++i )
|
2756 | 2761 | {
|
2757 |
| - OGRSFDriverH drv = OGRGetDriver( i ); |
| 2762 | + GDALDriverH drv = GDALGetDriver( i ); |
2758 | 2763 | if ( drv )
|
2759 | 2764 | {
|
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 ) ) |
2762 | 2767 | {
|
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 ) |
2765 | 2772 | {
|
2766 |
| - if ( metadata.glob.contains( ext, Qt::CaseInsensitive ) ) |
| 2773 | + if ( driver.compare( ext, Qt::CaseInsensitive ) == 0 ) |
2767 | 2774 | return drvName;
|
2768 | 2775 | }
|
2769 | 2776 | }
|
|
0 commit comments