Skip to content

Commit

Permalink
changed to pj_set_finder
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@5429 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed May 8, 2006
1 parent d211ce9 commit a1f990b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 35 deletions.
48 changes: 16 additions & 32 deletions src/gui/qgscoordinatetransform.cpp
Expand Up @@ -25,20 +25,17 @@
// Qt4-only includes to go here
#include <QTextOStream>
#include <QApplication>
#include <QFile>

bool QgsCoordinateTransform::environmentSet = false;

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

{
setEnvironment();
setFinder();
}

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

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

mSourceSRS.createFromId(theSourceSrid, theSourceSRSType);
mDestSRS.createFromWkt(theDestWKT);
Expand Down Expand Up @@ -536,42 +533,29 @@ bool QgsCoordinateTransform::writeXML( QDomNode & theNode, QDomDocument & theDoc
return true;
}

void QgsCoordinateTransform::setEnvironment()
const char *finder( const char *name )
{
QString proj;
#ifdef WIN32
if ( environmentSet ) return;

bool set = false;
proj = QApplication::applicationDirPath()
+ "/share/proj/" + QString(name);
#endif
return proj.ascii();
}

QString proj = getenv("PROJ_LIB");

void QgsCoordinateTransform::setFinder()
{
#ifdef WIN32
// 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;
pj_set_finder( finder );
#endif
}

5 changes: 2 additions & 3 deletions src/gui/qgscoordinatetransform.h
Expand Up @@ -252,10 +252,9 @@ class QgsCoordinateTransform: public QObject
projPJ mDestinationProjection;

/*!
* Set enviroment variable PROJ_LIB on Windows if not set.
* Finder for PROJ grid files.
*/
void setEnvironment();
static bool environmentSet;
void setFinder();
};

//! Output stream operator
Expand Down

0 comments on commit a1f990b

Please sign in to comment.