Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
set PROJ_LIB on Windows
git-svn-id: http://svn.osgeo.org/qgis/trunk@5428 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed May 8, 2006
1 parent f60bad1 commit d211ce9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/gui/qgscoordinatetransform.cpp
Expand Up @@ -24,15 +24,21 @@

// Qt4-only includes to go here
#include <QTextOStream>
#include <QApplication>
#include <QFile>

bool QgsCoordinateTransform::environmentSet = false;

QgsCoordinateTransform::QgsCoordinateTransform( ) : QObject(), mSourceSRS(), mDestSRS()

{
setEnvironment();
}

QgsCoordinateTransform::QgsCoordinateTransform(const QgsSpatialRefSys& source,
const QgsSpatialRefSys& dest)
{
setEnvironment();
mSourceSRS = source;
mDestSRS = dest;
initialise();
Expand All @@ -42,6 +48,7 @@ QgsCoordinateTransform::QgsCoordinateTransform(const QgsSpatialRefSys& source,
QgsCoordinateTransform::QgsCoordinateTransform( QString theSourceSRS, QString theDestSRS ) : QObject()

{
setEnvironment();
mSourceSRS.createFromWkt(theSourceSRS);
mDestSRS.createFromWkt(theDestSRS);
// initialize the coordinate system data structures
Expand All @@ -55,6 +62,7 @@ QgsCoordinateTransform::QgsCoordinateTransform(long theSourceSrid,
QString theDestWKT,
QgsSpatialRefSys::SRS_TYPE theSourceSRSType): QObject()
{
setEnvironment();

mSourceSRS.createFromId(theSourceSrid, theSourceSRSType);
mDestSRS.createFromWkt(theDestWKT);
Expand Down Expand Up @@ -527,3 +535,43 @@ bool QgsCoordinateTransform::writeXML( QDomNode & theNode, QDomDocument & theDoc

return true;
}

void QgsCoordinateTransform::setEnvironment()
{
#ifdef WIN32
if ( environmentSet ) return;

bool set = false;

QString proj = getenv("PROJ_LIB");

// Attention! It should be possible to set PROJ_LIB
// but it can happen that it was previously set by installer
// (version 0.7) and the old installation was deleted
// => test also if the directory exist

// Another problem: PROJ checks if pj_finder was set before
// PROJ_LIB enviroment variable. pj_finder is probably set in
// GRASS gproj library when plugin is loaded, consequently
// PROJ_LIB is ignored

QString proj_lib = getenv("PROJ_LIB");
if ( proj_lib.length() > 0 )
{
if ( QFile::exists ( proj_lib ) )
{
set = true;
}
}

if ( !set )
{
QString var = "PROJ_LIB=" + QApplication::applicationDirPath() + "/share/proj/";
char *varChar = new char[var.length()+1];
strcpy ( varChar, const_cast<char *>(var.ascii()) );
putenv( varChar );
}

environmentSet = true;
#endif
}
6 changes: 6 additions & 0 deletions src/gui/qgscoordinatetransform.h
Expand Up @@ -250,6 +250,12 @@ class QgsCoordinateTransform: public QObject
* Proj4 data structure of the destination projection (map canvas coordinate system)
*/
projPJ mDestinationProjection;

/*!
* Set enviroment variable PROJ_LIB on Windows if not set.
*/
void setEnvironment();
static bool environmentSet;
};

//! Output stream operator
Expand Down

0 comments on commit d211ce9

Please sign in to comment.