Skip to content

Commit 51006ce

Browse files
committed
Fix #9070
1 parent b21167c commit 51006ce

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/core/qgscoordinatetransform.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,10 @@ void QgsCoordinateTransform::initialise()
193193
{
194194
destProjString += ( " " + datumTransformString( mDestinationDatumTransform ) );
195195
}
196-
else if ( !useDefaultDatumTransform && sourceProjString.contains( "+nadgrids" ) ) //add null grid if source transformation is ntv2
197-
{
198-
destProjString += " +nadgrids=@null";
199-
}
200196

201-
if ( mSourceDatumTransform == -1 && !useDefaultDatumTransform && destProjString.contains( "+nadgrids" ) )
197+
if ( !useDefaultDatumTransform )
202198
{
203-
sourceProjString += " +nadgrids=@null";
199+
addNullGridShifts( sourceProjString, destProjString );
204200
}
205201

206202
mDestinationProjection = pj_init_plus( destProjString.toUtf8() );
@@ -931,3 +927,29 @@ QString QgsCoordinateTransform::datumTransformString( int datumTransform )
931927

932928
return transformString;
933929
}
930+
931+
void QgsCoordinateTransform::addNullGridShifts( QString& srcProjString, QString& destProjString )
932+
{
933+
//if one transformation uses ntv2, the other one needs to be null grid shift
934+
if ( mDestinationDatumTransform == -1 && srcProjString.contains( "+nadgrids" ) ) //add null grid if source transformation is ntv2
935+
{
936+
destProjString += " +nadgrids=@null";
937+
return;
938+
}
939+
if ( mSourceDatumTransform == -1 && destProjString.contains( "+nadgrids" ) )
940+
{
941+
srcProjString += " +nadgrids=@null";
942+
return;
943+
}
944+
945+
//add null shift grid for google mercator
946+
//(see e.g. http://trac.osgeo.org/proj/wiki/FAQ#ChangingEllipsoidWhycantIconvertfromWGS84toGoogleEarthVirtualGlobeMercator)
947+
if ( mSourceCRS.authid().compare( "EPSG:3857", Qt::CaseInsensitive ) == 0 && mSourceDatumTransform == -1 )
948+
{
949+
srcProjString += " +nadgrids=@null";
950+
}
951+
if ( mDestCRS.authid().compare( "EPSG:3857", Qt::CaseInsensitive ) == 0 && mDestinationDatumTransform == -1 )
952+
{
953+
destProjString += " +nadgrids=@null";
954+
}
955+
}

src/core/qgscoordinatetransform.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ class CORE_EXPORT QgsCoordinateTransform : public QObject
285285
/**Removes +nadgrids and +towgs84 from proj4 string*/
286286
static QString stripDatumTransform( const QString& proj4 );
287287
static void searchDatumTransform( const QString& sql, QList< int >& transforms );
288+
/**In certain situations, null grid shifts have to be added to src / dst proj string*/
289+
void addNullGridShifts( QString& srcProjString, QString& destProjString );
288290
};
289291

290292
//! Output stream operator

0 commit comments

Comments
 (0)