Skip to content
Permalink
Browse files
set PROJ_LIB on Windows
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5428 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed May 8, 2006
1 parent 602f30a commit 9b03b9fc25e18e4a054fef003dcbb9c15a0e364e
Showing with 54 additions and 0 deletions.
  1. +48 −0 src/gui/qgscoordinatetransform.cpp
  2. +6 −0 src/gui/qgscoordinatetransform.h
@@ -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();
@@ -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
@@ -55,6 +62,7 @@ QgsCoordinateTransform::QgsCoordinateTransform(long theSourceSrid,
QString theDestWKT,
QgsSpatialRefSys::SRS_TYPE theSourceSRSType): QObject()
{
setEnvironment();

mSourceSRS.createFromId(theSourceSrid, theSourceSRSType);
mDestSRS.createFromWkt(theDestWKT);
@@ -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
}
@@ -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

0 comments on commit 9b03b9f

Please sign in to comment.