Skip to content
Permalink
Browse files

[FEATURE]: set default datumstransformation for server with environme…

…nt variable
  • Loading branch information...
mhugent committed Apr 12, 2016
1 parent 601e430 commit 70863ecaf0ccfcb538e3892af4b528304b21a0a2
Showing with 66 additions and 0 deletions.
  1. +27 −0 src/core/qgsmaprenderer.cpp
  2. +5 −0 src/core/qgsmaprenderer.h
  3. +25 −0 src/server/qgsserver.cpp
  4. +9 −0 src/server/qgsserver.h
@@ -61,6 +61,7 @@ QgsMapRenderer::QgsMapRenderer()
mFullExtent.setMinimal();

mLabelingEngine = nullptr;
readDefaultDatumTransformations();
}

QgsMapRenderer::~QgsMapRenderer()
@@ -1110,6 +1111,12 @@ const QgsCoordinateTransform *QgsMapRenderer::transformation( const QgsMapLayer
}
else
{
//is there a defined datum transformation?
QHash< QPair< QString, QString >, QPair< int, int > >::const_iterator it = mDefaultDatumTransformations.find( qMakePair( layer->crs().authid(), mDestCRS->authid() ) );
if ( it != mDefaultDatumTransformations.constEnd() )
{
return QgsCoordinateTransformCache::instance()->transform( it.key().first, it.key().second, it.value().first, it.value().second );
}
emit datumTransformInfoRequested( layer, layer->crs().authid(), mDestCRS->authid() );
}

@@ -1275,4 +1282,24 @@ void QgsMapRenderer::clearLayerCoordinateTransforms()
mLayerCoordinateTransformInfo.clear();
}

void QgsMapRenderer::readDefaultDatumTransformations()
{
const char* envChar = getenv( "DEFAULT_DATUM_TRANSFORM" );
if ( envChar )
{
QString envString( envChar );
QStringList transformSplit = envString.split( ";" );
for ( int i = 0; i < transformSplit.size(); ++i )
{
QStringList slashSplit = transformSplit.at( i ).split( "/" );
if ( slashSplit.size() < 4 )
{
continue;
}

mDefaultDatumTransformations.insert( qMakePair( slashSplit.at( 0 ), slashSplit.at( 1 ) ), qMakePair( slashSplit.at( 2 ).toInt(), slashSplit.at( 3 ).toInt() ) );
}
}
}

bool QgsMapRenderer::mDrawing = false;
@@ -456,6 +456,11 @@ class CORE_EXPORT QgsMapRenderer : public QObject
QgsMapSettings mMapSettings;

QHash< QString, QgsLayerCoordinateTransform > mLayerCoordinateTransformInfo;

QHash< QPair< QString, QString >, QPair< int, int > > mDefaultDatumTransformations;

private:
void readDefaultDatumTransformations();
};

#endif
@@ -78,12 +78,14 @@ bool QgsServer::sCaptureOutput = false;
QgsServer::QgsServer( int &argc, char **argv )
{
init( argc, argv );
saveEnvVars();
}


QgsServer::QgsServer()
{
init();
saveEnvVars();
}


@@ -454,6 +456,12 @@ void QgsServer::putenv( const QString &var, const QString &val )
*/
QPair<QByteArray, QByteArray> QgsServer::handleRequest( const QString& queryString )
{
//apply environment variables
QHash< QString, QString >::const_iterator envIt = mEnvironmentVariables.constBegin();
for ( ; envIt != mEnvironmentVariables.constEnd(); ++envIt )
{
putenv( envIt.key(), envIt.value() );
}

/*
* This is mainly for python bindings, passing QUERY_STRING
@@ -657,3 +665,20 @@ QPair<QByteArray, QByteArray> QgsServer::testQPair( QPair<QByteArray, QByteArray
}
#endif

void QgsServer::saveEnvVars()
{
saveEnvVar( "MAX_CACHE_LAYERS" );
saveEnvVar( "DEFAULT_DATUM_TRANSFORM" );
}

void QgsServer::saveEnvVar( const QString& variableName )
{
const char* env = getenv( variableName.toLocal8Bit() );
if ( !env )
{
return;
}

mEnvironmentVariables.insert( variableName, QString::fromLocal8Bit( env ) );
}

@@ -93,6 +93,12 @@ class SERVER_EXPORT QgsServer
#endif

private:

void saveEnvVars();

/** Saves environment variable into mEnvironmentVariables if defined*/
void saveEnvVar( const QString& variableName );

// All functions that where previously in the main file are now
// static methods of this class
static QString configPath( const QString& defaultConfigPath,
@@ -128,6 +134,9 @@ class SERVER_EXPORT QgsServer
static int sArgc;
static QgsApplication* sQgsApplication;
static bool sCaptureOutput;

/** Pass important environment variables to the fcgi processes*/
QHash< QString, QString > mEnvironmentVariables;
};
#endif // QGSSERVER_H

0 comments on commit 70863ec

Please sign in to comment.
You can’t perform that action at this time.