24
24
25
25
// Qt4-only includes to go here
26
26
#include < QTextOStream>
27
+ #include < QApplication>
28
+ #include < QFile>
29
+
30
+ bool QgsCoordinateTransform::environmentSet = false ;
27
31
28
32
QgsCoordinateTransform::QgsCoordinateTransform ( ) : QObject(), mSourceSRS(), mDestSRS()
29
33
30
34
{
35
+ setEnvironment ();
31
36
}
32
37
33
38
QgsCoordinateTransform::QgsCoordinateTransform (const QgsSpatialRefSys& source,
34
39
const QgsSpatialRefSys& dest)
35
40
{
41
+ setEnvironment ();
36
42
mSourceSRS = source;
37
43
mDestSRS = dest;
38
44
initialise ();
@@ -42,6 +48,7 @@ QgsCoordinateTransform::QgsCoordinateTransform(const QgsSpatialRefSys& source,
42
48
QgsCoordinateTransform::QgsCoordinateTransform ( QString theSourceSRS, QString theDestSRS ) : QObject()
43
49
44
50
{
51
+ setEnvironment ();
45
52
mSourceSRS .createFromWkt (theSourceSRS);
46
53
mDestSRS .createFromWkt (theDestSRS);
47
54
// initialize the coordinate system data structures
@@ -55,6 +62,7 @@ QgsCoordinateTransform::QgsCoordinateTransform(long theSourceSrid,
55
62
QString theDestWKT,
56
63
QgsSpatialRefSys::SRS_TYPE theSourceSRSType): QObject()
57
64
{
65
+ setEnvironment ();
58
66
59
67
mSourceSRS .createFromId (theSourceSrid, theSourceSRSType);
60
68
mDestSRS .createFromWkt (theDestWKT);
@@ -527,3 +535,43 @@ bool QgsCoordinateTransform::writeXML( QDomNode & theNode, QDomDocument & theDoc
527
535
528
536
return true ;
529
537
}
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
+ }
0 commit comments