Skip to content

Commit

Permalink
Added a wrapper for ogr register all so that it cant be called twice …
Browse files Browse the repository at this point in the history
…(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@9195 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Aug 27, 2008
1 parent 4ea563b commit efc21da
Show file tree
Hide file tree
Showing 8 changed files with 722 additions and 680 deletions.
8 changes: 8 additions & 0 deletions python/core/qgsapplication.sip
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,13 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
* application instance useful for debugging mainly.*/
static QString showSettings();

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

};

10 changes: 9 additions & 1 deletion src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <netinet/in.h>
#endif

#include <ogr_api.h>

QString QgsApplication::mPrefixPath;
QString QgsApplication::mPluginPath;
QString QgsApplication::mPkgDataPath;
Expand Down Expand Up @@ -314,4 +316,10 @@ QString QgsApplication::reportStyleSheet()
return myStyle;
}


void QgsApplication::registerOgrDrivers()
{
if ( 0 >= OGRGetDriverCount() )
{
OGRRegisterAll();
}
}
8 changes: 8 additions & 0 deletions src/core/qgsapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ class CORE_EXPORT QgsApplication: public QApplication
/** Convenience function to get a summary of the paths used in this
* application instance useful for debugging mainly.*/
static QString showSettings();
/** Register OGR drivers ensuring this only happens once.
* This is a workaround for an issue with older gdal versions that
* caused duplicate driver name entries to appear in the list
* of registered drivers when QgsApplication::registerOgrDrivers was called multiple
* times.
*/
static void registerOgrDrivers();

private:
static QString mPrefixPath;
static QString mPluginPath;
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
***************************************************************************/
/* $Id$ */

#include "qgsapplication.h"
#include "qgsfield.h"
#include "qgsfeature.h"
#include "qgsgeometry.h"
Expand Down Expand Up @@ -48,7 +49,7 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& shapefileName,

// find driver in OGR
OGRSFDriverH poDriver;
OGRRegisterAll();
QgsApplication::registerOgrDrivers();
poDriver = OGRGetDriverByName( driverName.toLocal8Bit().data() );

if ( poDriver == NULL )
Expand Down

0 comments on commit efc21da

Please sign in to comment.