Skip to content

Commit d810ee0

Browse files
author
timlinux
committed
Added a wrapper for ogr register all so that it cant be called twice (on suggestion of M. Loskot).
Fixes issues where drivers appear to be registered more than once. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9195 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent df47953 commit d810ee0

File tree

8 files changed

+722
-680
lines changed

8 files changed

+722
-680
lines changed

python/core/qgsapplication.sip

+8
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,13 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
191191
* application instance useful for debugging mainly.*/
192192
static QString showSettings();
193193

194+
/** Register OGR drivers ensuring this only happens once.
195+
* This is a workaround for an issue with older gdal versions that
196+
* caused duplicate driver name entries to appear in the list
197+
* of registered drivers when QgsApplication::registerOgrDrivers was called multiple
198+
* times.
199+
*/
200+
static void registerOgrDrivers();
201+
194202
};
195203

src/core/qgsapplication.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <netinet/in.h>
3333
#endif
3434

35+
#include <ogr_api.h>
36+
3537
QString QgsApplication::mPrefixPath;
3638
QString QgsApplication::mPluginPath;
3739
QString QgsApplication::mPkgDataPath;
@@ -314,4 +316,10 @@ QString QgsApplication::reportStyleSheet()
314316
return myStyle;
315317
}
316318

317-
319+
void QgsApplication::registerOgrDrivers()
320+
{
321+
if ( 0 >= OGRGetDriverCount() )
322+
{
323+
OGRRegisterAll();
324+
}
325+
}

src/core/qgsapplication.h

+8
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ class CORE_EXPORT QgsApplication: public QApplication
139139
/** Convenience function to get a summary of the paths used in this
140140
* application instance useful for debugging mainly.*/
141141
static QString showSettings();
142+
/** Register OGR drivers ensuring this only happens once.
143+
* This is a workaround for an issue with older gdal versions that
144+
* caused duplicate driver name entries to appear in the list
145+
* of registered drivers when QgsApplication::registerOgrDrivers was called multiple
146+
* times.
147+
*/
148+
static void registerOgrDrivers();
149+
142150
private:
143151
static QString mPrefixPath;
144152
static QString mPluginPath;

src/core/qgsvectorfilewriter.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
***************************************************************************/
1818
/* $Id$ */
1919

20+
#include "qgsapplication.h"
2021
#include "qgsfield.h"
2122
#include "qgsfeature.h"
2223
#include "qgsgeometry.h"
@@ -48,7 +49,7 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& shapefileName,
4849

4950
// find driver in OGR
5051
OGRSFDriverH poDriver;
51-
OGRRegisterAll();
52+
QgsApplication::registerOgrDrivers();
5253
poDriver = OGRGetDriverByName( driverName.toLocal8Bit().data() );
5354

5455
if ( poDriver == NULL )

0 commit comments

Comments
 (0)