Skip to content

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
 

‎src/gui/qgscoordinatetransform.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@
2424

2525
// Qt4-only includes to go here
2626
#include <QTextOStream>
27+
#include <QApplication>
28+
#include <QFile>
29+
30+
bool QgsCoordinateTransform::environmentSet = false;
2731

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

3034
{
35+
setEnvironment();
3136
}
3237

3338
QgsCoordinateTransform::QgsCoordinateTransform(const QgsSpatialRefSys& source,
3439
const QgsSpatialRefSys& dest)
3540
{
41+
setEnvironment();
3642
mSourceSRS = source;
3743
mDestSRS = dest;
3844
initialise();
@@ -42,6 +48,7 @@ QgsCoordinateTransform::QgsCoordinateTransform(const QgsSpatialRefSys& source,
4248
QgsCoordinateTransform::QgsCoordinateTransform( QString theSourceSRS, QString theDestSRS ) : QObject()
4349

4450
{
51+
setEnvironment();
4552
mSourceSRS.createFromWkt(theSourceSRS);
4653
mDestSRS.createFromWkt(theDestSRS);
4754
// initialize the coordinate system data structures
@@ -55,6 +62,7 @@ QgsCoordinateTransform::QgsCoordinateTransform(long theSourceSrid,
5562
QString theDestWKT,
5663
QgsSpatialRefSys::SRS_TYPE theSourceSRSType): QObject()
5764
{
65+
setEnvironment();
5866

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

528536
return true;
529537
}
538+
539+
void QgsCoordinateTransform::setEnvironment()
540+
{
541+
#ifdef WIN32
542+
if ( environmentSet ) return;
543+
544+
bool set = false;
545+
546+
QString proj = getenv("PROJ_LIB");
547+
548+
// Attention! It should be possible to set PROJ_LIB
549+
// but it can happen that it was previously set by installer
550+
// (version 0.7) and the old installation was deleted
551+
// => test also if the directory exist
552+
553+
// Another problem: PROJ checks if pj_finder was set before
554+
// PROJ_LIB enviroment variable. pj_finder is probably set in
555+
// GRASS gproj library when plugin is loaded, consequently
556+
// PROJ_LIB is ignored
557+
558+
QString proj_lib = getenv("PROJ_LIB");
559+
if ( proj_lib.length() > 0 )
560+
{
561+
if ( QFile::exists ( proj_lib ) )
562+
{
563+
set = true;
564+
}
565+
}
566+
567+
if ( !set )
568+
{
569+
QString var = "PROJ_LIB=" + QApplication::applicationDirPath() + "/share/proj/";
570+
char *varChar = new char[var.length()+1];
571+
strcpy ( varChar, const_cast<char *>(var.ascii()) );
572+
putenv( varChar );
573+
}
574+
575+
environmentSet = true;
576+
#endif
577+
}

‎src/gui/qgscoordinatetransform.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ class QgsCoordinateTransform: public QObject
250250
* Proj4 data structure of the destination projection (map canvas coordinate system)
251251
*/
252252
projPJ mDestinationProjection;
253+
254+
/*!
255+
* Set enviroment variable PROJ_LIB on Windows if not set.
256+
*/
257+
void setEnvironment();
258+
static bool environmentSet;
253259
};
254260

255261
//! Output stream operator

0 commit comments

Comments
 (0)
Please sign in to comment.