2525// Qt4-only includes to go here
2626#include < QTextOStream>
2727#include < QApplication>
28- #include < QFile>
29-
30- bool QgsCoordinateTransform::environmentSet = false ;
3128
3229QgsCoordinateTransform::QgsCoordinateTransform ( ) : QObject(), mSourceSRS(), mDestSRS()
3330
3431{
35- setEnvironment ();
32+ setFinder ();
3633}
3734
3835QgsCoordinateTransform::QgsCoordinateTransform (const QgsSpatialRefSys& source,
3936 const QgsSpatialRefSys& dest)
4037{
41- setEnvironment ();
38+ setFinder ();
4239 mSourceSRS = source;
4340 mDestSRS = dest;
4441 initialise ();
@@ -48,7 +45,7 @@ QgsCoordinateTransform::QgsCoordinateTransform(const QgsSpatialRefSys& source,
4845QgsCoordinateTransform::QgsCoordinateTransform ( QString theSourceSRS, QString theDestSRS ) : QObject()
4946
5047{
51- setEnvironment ();
48+ setFinder ();
5249 mSourceSRS .createFromWkt (theSourceSRS);
5350 mDestSRS .createFromWkt (theDestSRS);
5451 // initialize the coordinate system data structures
@@ -62,7 +59,7 @@ QgsCoordinateTransform::QgsCoordinateTransform(long theSourceSrid,
6259 QString theDestWKT,
6360 QgsSpatialRefSys::SRS_TYPE theSourceSRSType): QObject()
6461{
65- setEnvironment ();
62+ setFinder ();
6663
6764 mSourceSRS .createFromId (theSourceSrid, theSourceSRSType);
6865 mDestSRS .createFromWkt (theDestWKT);
@@ -536,42 +533,29 @@ bool QgsCoordinateTransform::writeXML( QDomNode & theNode, QDomDocument & theDoc
536533 return true ;
537534}
538535
539- void QgsCoordinateTransform::setEnvironment ( )
536+ const char * finder ( const char *name )
540537{
538+ QString proj;
541539#ifdef WIN32
542- if ( environmentSet ) return ;
543-
544- bool set = false ;
540+ proj = QApplication::applicationDirPath ()
541+ + " /share/proj/" + QString (name);
542+ #endif
543+ return proj.ascii ();
544+ }
545545
546- QString proj = getenv (" PROJ_LIB" );
547-
546+ void QgsCoordinateTransform::setFinder ()
547+ {
548+ #ifdef WIN32
548549 // Attention! It should be possible to set PROJ_LIB
549550 // but it can happen that it was previously set by installer
550551 // (version 0.7) and the old installation was deleted
551- // => test also if the directory exist
552552
553553 // Another problem: PROJ checks if pj_finder was set before
554554 // PROJ_LIB enviroment variable. pj_finder is probably set in
555555 // GRASS gproj library when plugin is loaded, consequently
556556 // 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- }
574557
575- environmentSet = true ;
558+ pj_set_finder ( finder );
576559#endif
577560}
561+
0 commit comments