Skip to content

Commit ae492ab

Browse files
committedMay 16, 2017
Split qgscoordinatetransform_p into .h/cpp
1 parent 59c9743 commit ae492ab

File tree

3 files changed

+328
-284
lines changed

3 files changed

+328
-284
lines changed
 

‎src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ SET(QGIS_CORE_SRCS
128128
qgscontexthelp.cpp
129129
qgscoordinatereferencesystem.cpp
130130
qgscoordinatetransform.cpp
131+
qgscoordinatetransform_p.cpp
131132
qgscoordinateutils.cpp
132133
qgscredentials.cpp
133134
qgscrscache.cpp

‎src/core/qgscoordinatetransform_p.cpp

Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
/***************************************************************************
2+
qgscoordinatetransform_p.cpp
3+
----------------------------
4+
begin : May 2017
5+
copyright : (C) 2017 Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgscoordinatetransform_p.h"
19+
#include "qgslogger.h"
20+
#include "qgsapplication.h"
21+
22+
extern "C"
23+
{
24+
#include <proj_api.h>
25+
}
26+
#include <sqlite3.h>
27+
28+
#include <QStringList>
29+
30+
/// @cond PRIVATE
31+
32+
QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate()
33+
: mIsValid( false )
34+
, mShortCircuit( false )
35+
, mSourceProjection( nullptr )
36+
, mDestinationProjection( nullptr )
37+
, mSourceDatumTransform( -1 )
38+
, mDestinationDatumTransform( -1 )
39+
{
40+
setFinder();
41+
}
42+
43+
QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination )
44+
: mIsValid( false )
45+
, mShortCircuit( false )
46+
, mSourceCRS( source )
47+
, mDestCRS( destination )
48+
, mSourceProjection( nullptr )
49+
, mDestinationProjection( nullptr )
50+
, mSourceDatumTransform( -1 )
51+
, mDestinationDatumTransform( -1 )
52+
{
53+
setFinder();
54+
initialize();
55+
}
56+
57+
QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinateTransformPrivate &other )
58+
: QSharedData( other )
59+
, mIsValid( other.mIsValid )
60+
, mShortCircuit( other.mShortCircuit )
61+
, mSourceCRS( other.mSourceCRS )
62+
, mDestCRS( other.mDestCRS )
63+
, mSourceProjection( nullptr )
64+
, mDestinationProjection( nullptr )
65+
, mSourceDatumTransform( other.mSourceDatumTransform )
66+
, mDestinationDatumTransform( other.mDestinationDatumTransform )
67+
{
68+
//must reinitialize to setup mSourceProjection and mDestinationProjection
69+
initialize();
70+
}
71+
72+
QgsCoordinateTransformPrivate::~QgsCoordinateTransformPrivate()
73+
{
74+
// free the proj objects
75+
if ( mSourceProjection )
76+
{
77+
pj_free( mSourceProjection );
78+
}
79+
if ( mDestinationProjection )
80+
{
81+
pj_free( mDestinationProjection );
82+
}
83+
}
84+
85+
bool QgsCoordinateTransformPrivate::initialize()
86+
{
87+
mShortCircuit = true;
88+
mIsValid = false;
89+
90+
if ( !mSourceCRS.isValid() )
91+
{
92+
// Pass through with no projection since we have no idea what the layer
93+
// coordinates are and projecting them may not be appropriate
94+
QgsDebugMsgLevel( "Source CRS is invalid!", 4 );
95+
return false;
96+
}
97+
98+
if ( !mDestCRS.isValid() )
99+
{
100+
//No destination projection is set so we set the default output projection to
101+
//be the same as input proj.
102+
mDestCRS = mSourceCRS;
103+
QgsDebugMsgLevel( "Destination CRS is invalid!", 4 );
104+
return false;
105+
}
106+
107+
mIsValid = true;
108+
109+
bool useDefaultDatumTransform = ( mSourceDatumTransform == - 1 && mDestinationDatumTransform == -1 );
110+
111+
// init the projections (destination and source)
112+
113+
pj_free( mSourceProjection );
114+
QString sourceProjString = mSourceCRS.toProj4();
115+
if ( !useDefaultDatumTransform )
116+
{
117+
sourceProjString = stripDatumTransform( sourceProjString );
118+
}
119+
if ( mSourceDatumTransform != -1 )
120+
{
121+
sourceProjString += ( ' ' + datumTransformString( mSourceDatumTransform ) );
122+
}
123+
124+
pj_free( mDestinationProjection );
125+
QString destProjString = mDestCRS.toProj4();
126+
if ( !useDefaultDatumTransform )
127+
{
128+
destProjString = stripDatumTransform( destProjString );
129+
}
130+
if ( mDestinationDatumTransform != -1 )
131+
{
132+
destProjString += ( ' ' + datumTransformString( mDestinationDatumTransform ) );
133+
}
134+
135+
if ( !useDefaultDatumTransform )
136+
{
137+
addNullGridShifts( sourceProjString, destProjString );
138+
}
139+
140+
mSourceProjection = pj_init_plus( sourceProjString.toUtf8() );
141+
mDestinationProjection = pj_init_plus( destProjString.toUtf8() );
142+
143+
#ifdef COORDINATE_TRANSFORM_VERBOSE
144+
QgsDebugMsg( "From proj : " + mSourceCRS.toProj4() );
145+
QgsDebugMsg( "To proj : " + mDestCRS.toProj4() );
146+
#endif
147+
148+
if ( !mDestinationProjection || !mSourceProjection )
149+
{
150+
mIsValid = false;
151+
}
152+
153+
#ifdef COORDINATE_TRANSFORM_VERBOSE
154+
if ( mIsValid )
155+
{
156+
QgsDebugMsg( "------------------------------------------------------------" );
157+
QgsDebugMsg( "The OGR Coordinate transformation for this layer was set to" );
158+
QgsLogger::debug<QgsCoordinateReferenceSystem>( "Input", mSourceCRS, __FILE__, __FUNCTION__, __LINE__ );
159+
QgsLogger::debug<QgsCoordinateReferenceSystem>( "Output", mDestCRS, __FILE__, __FUNCTION__, __LINE__ );
160+
QgsDebugMsg( "------------------------------------------------------------" );
161+
}
162+
else
163+
{
164+
QgsDebugMsg( "------------------------------------------------------------" );
165+
QgsDebugMsg( "The OGR Coordinate transformation FAILED TO INITIALIZE!" );
166+
QgsDebugMsg( "------------------------------------------------------------" );
167+
}
168+
#else
169+
if ( !mIsValid )
170+
{
171+
QgsDebugMsg( "Coordinate transformation failed to initialize!" );
172+
}
173+
#endif
174+
175+
//XXX todo overload == operator for QgsCoordinateReferenceSystem
176+
//at the moment srs.parameters contains the whole proj def...soon it won't...
177+
//if (mSourceCRS->toProj4() == mDestCRS->toProj4())
178+
if ( mSourceCRS == mDestCRS )
179+
{
180+
// If the source and destination projection are the same, set the short
181+
// circuit flag (no transform takes place)
182+
mShortCircuit = true;
183+
QgsDebugMsgLevel( "Source/Dest CRS equal, shortcircuit is set.", 3 );
184+
}
185+
else
186+
{
187+
// Transform must take place
188+
mShortCircuit = false;
189+
QgsDebugMsgLevel( "Source/Dest CRS not equal, shortcircuit is not set.", 3 );
190+
}
191+
return mIsValid;
192+
}
193+
194+
QString QgsCoordinateTransformPrivate::stripDatumTransform( const QString &proj4 ) const
195+
{
196+
QStringList parameterSplit = proj4.split( '+', QString::SkipEmptyParts );
197+
QString currentParameter;
198+
QString newProjString;
199+
200+
for ( int i = 0; i < parameterSplit.size(); ++i )
201+
{
202+
currentParameter = parameterSplit.at( i );
203+
if ( !currentParameter.startsWith( QLatin1String( "towgs84" ), Qt::CaseInsensitive )
204+
&& !currentParameter.startsWith( QLatin1String( "nadgrids" ), Qt::CaseInsensitive ) )
205+
{
206+
newProjString.append( '+' );
207+
newProjString.append( currentParameter );
208+
newProjString.append( ' ' );
209+
}
210+
}
211+
return newProjString;
212+
}
213+
214+
QString QgsCoordinateTransformPrivate::datumTransformString( int datumTransform )
215+
{
216+
QString transformString;
217+
218+
sqlite3 *db = nullptr;
219+
int openResult = sqlite3_open_v2( QgsApplication::srsDatabaseFilePath().toUtf8().constData(), &db, SQLITE_OPEN_READONLY, 0 );
220+
if ( openResult != SQLITE_OK )
221+
{
222+
sqlite3_close( db );
223+
return transformString;
224+
}
225+
226+
sqlite3_stmt *stmt = nullptr;
227+
QString sql = QStringLiteral( "SELECT coord_op_method_code,p1,p2,p3,p4,p5,p6,p7 FROM tbl_datum_transform WHERE coord_op_code=%1" ).arg( datumTransform );
228+
int prepareRes = sqlite3_prepare( db, sql.toLatin1(), sql.size(), &stmt, nullptr );
229+
if ( prepareRes != SQLITE_OK )
230+
{
231+
sqlite3_finalize( stmt );
232+
sqlite3_close( db );
233+
return transformString;
234+
}
235+
236+
if ( sqlite3_step( stmt ) == SQLITE_ROW )
237+
{
238+
//coord_op_methode_code
239+
int methodCode = sqlite3_column_int( stmt, 0 );
240+
if ( methodCode == 9615 ) //ntv2
241+
{
242+
transformString = "+nadgrids=" + QString( reinterpret_cast< const char * >( sqlite3_column_text( stmt, 1 ) ) );
243+
}
244+
else if ( methodCode == 9603 || methodCode == 9606 || methodCode == 9607 )
245+
{
246+
transformString += QLatin1String( "+towgs84=" );
247+
double p1 = sqlite3_column_double( stmt, 1 );
248+
double p2 = sqlite3_column_double( stmt, 2 );
249+
double p3 = sqlite3_column_double( stmt, 3 );
250+
double p4 = sqlite3_column_double( stmt, 4 );
251+
double p5 = sqlite3_column_double( stmt, 5 );
252+
double p6 = sqlite3_column_double( stmt, 6 );
253+
double p7 = sqlite3_column_double( stmt, 7 );
254+
if ( methodCode == 9603 ) //3 parameter transformation
255+
{
256+
transformString += QStringLiteral( "%1,%2,%3" ).arg( p1 ).arg( p2 ).arg( p3 );
257+
}
258+
else //7 parameter transformation
259+
{
260+
transformString += QStringLiteral( "%1,%2,%3,%4,%5,%6,%7" ).arg( p1 ).arg( p2 ).arg( p3 ).arg( p4 ).arg( p5 ).arg( p6 ).arg( p7 );
261+
}
262+
}
263+
}
264+
265+
sqlite3_finalize( stmt );
266+
sqlite3_close( db );
267+
return transformString;
268+
}
269+
270+
void QgsCoordinateTransformPrivate::addNullGridShifts( QString &srcProjString, QString &destProjString ) const
271+
{
272+
//if one transformation uses ntv2, the other one needs to be null grid shift
273+
if ( mDestinationDatumTransform == -1 && srcProjString.contains( QLatin1String( "+nadgrids" ) ) ) //add null grid if source transformation is ntv2
274+
{
275+
destProjString += QLatin1String( " +nadgrids=@null" );
276+
return;
277+
}
278+
if ( mSourceDatumTransform == -1 && destProjString.contains( QLatin1String( "+nadgrids" ) ) )
279+
{
280+
srcProjString += QLatin1String( " +nadgrids=@null" );
281+
return;
282+
}
283+
284+
//add null shift grid for google mercator
285+
//(see e.g. http://trac.osgeo.org/proj/wiki/FAQ#ChangingEllipsoidWhycantIconvertfromWGS84toGoogleEarthVirtualGlobeMercator)
286+
if ( mSourceCRS.authid().compare( QLatin1String( "EPSG:3857" ), Qt::CaseInsensitive ) == 0 && mSourceDatumTransform == -1 )
287+
{
288+
srcProjString += QLatin1String( " +nadgrids=@null" );
289+
}
290+
if ( mDestCRS.authid().compare( QLatin1String( "EPSG:3857" ), Qt::CaseInsensitive ) == 0 && mDestinationDatumTransform == -1 )
291+
{
292+
destProjString += QLatin1String( " +nadgrids=@null" );
293+
}
294+
}
295+
296+
void QgsCoordinateTransformPrivate::setFinder()
297+
{
298+
#if 0
299+
// Attention! It should be possible to set PROJ_LIB
300+
// but it can happen that it was previously set by installer
301+
// (version 0.7) and the old installation was deleted
302+
303+
// Another problem: PROJ checks if pj_finder was set before
304+
// PROJ_LIB environment variable. pj_finder is probably set in
305+
// GRASS gproj library when plugin is loaded, consequently
306+
// PROJ_LIB is ignored
307+
308+
pj_set_finder( finder );
309+
#endif
310+
}
311+
312+
///@endcond

‎src/core/qgscoordinatetransform_p.h

Lines changed: 15 additions & 284 deletions
Original file line numberDiff line numberDiff line change
@@ -30,289 +30,24 @@
3030

3131
#include <QSharedData>
3232
#include "qgscoordinatereferencesystem.h"
33-
#include "qgslogger.h"
34-
#include "qgsapplication.h"
3533

36-
extern "C"
37-
{
38-
#include <proj_api.h>
39-
}
40-
#include <sqlite3.h>
41-
42-
#include <QStringList>
34+
typedef void *projPJ;
4335

4436
class QgsCoordinateTransformPrivate : public QSharedData
4537
{
4638

4739
public:
4840

49-
explicit QgsCoordinateTransformPrivate()
50-
: mIsValid( false )
51-
, mShortCircuit( false )
52-
, mSourceProjection( nullptr )
53-
, mDestinationProjection( nullptr )
54-
, mSourceDatumTransform( -1 )
55-
, mDestinationDatumTransform( -1 )
56-
{
57-
setFinder();
58-
}
41+
explicit QgsCoordinateTransformPrivate();
5942

6043
QgsCoordinateTransformPrivate( const QgsCoordinateReferenceSystem &source,
61-
const QgsCoordinateReferenceSystem &destination )
62-
: mIsValid( false )
63-
, mShortCircuit( false )
64-
, mSourceCRS( source )
65-
, mDestCRS( destination )
66-
, mSourceProjection( nullptr )
67-
, mDestinationProjection( nullptr )
68-
, mSourceDatumTransform( -1 )
69-
, mDestinationDatumTransform( -1 )
70-
{
71-
setFinder();
72-
initialize();
73-
}
74-
75-
QgsCoordinateTransformPrivate( const QgsCoordinateTransformPrivate &other )
76-
: QSharedData( other )
77-
, mIsValid( other.mIsValid )
78-
, mShortCircuit( other.mShortCircuit )
79-
, mSourceCRS( other.mSourceCRS )
80-
, mDestCRS( other.mDestCRS )
81-
, mSourceProjection( nullptr )
82-
, mDestinationProjection( nullptr )
83-
, mSourceDatumTransform( other.mSourceDatumTransform )
84-
, mDestinationDatumTransform( other.mDestinationDatumTransform )
85-
{
86-
//must reinitialize to setup mSourceProjection and mDestinationProjection
87-
initialize();
88-
}
89-
90-
~QgsCoordinateTransformPrivate()
91-
{
92-
// free the proj objects
93-
if ( mSourceProjection )
94-
{
95-
pj_free( mSourceProjection );
96-
}
97-
if ( mDestinationProjection )
98-
{
99-
pj_free( mDestinationProjection );
100-
}
101-
}
102-
103-
bool initialize()
104-
{
105-
mShortCircuit = true;
106-
mIsValid = false;
107-
108-
if ( !mSourceCRS.isValid() )
109-
{
110-
// Pass through with no projection since we have no idea what the layer
111-
// coordinates are and projecting them may not be appropriate
112-
QgsDebugMsgLevel( "Source CRS is invalid!", 4 );
113-
return false;
114-
}
115-
116-
if ( !mDestCRS.isValid() )
117-
{
118-
//No destination projection is set so we set the default output projection to
119-
//be the same as input proj.
120-
mDestCRS = mSourceCRS;
121-
QgsDebugMsgLevel( "Destination CRS is invalid!", 4 );
122-
return false;
123-
}
124-
125-
mIsValid = true;
44+
const QgsCoordinateReferenceSystem &destination );
12645

127-
bool useDefaultDatumTransform = ( mSourceDatumTransform == - 1 && mDestinationDatumTransform == -1 );
46+
QgsCoordinateTransformPrivate( const QgsCoordinateTransformPrivate &other );
12847

129-
// init the projections (destination and source)
130-
131-
pj_free( mSourceProjection );
132-
QString sourceProjString = mSourceCRS.toProj4();
133-
if ( !useDefaultDatumTransform )
134-
{
135-
sourceProjString = stripDatumTransform( sourceProjString );
136-
}
137-
if ( mSourceDatumTransform != -1 )
138-
{
139-
sourceProjString += ( ' ' + datumTransformString( mSourceDatumTransform ) );
140-
}
141-
142-
pj_free( mDestinationProjection );
143-
QString destProjString = mDestCRS.toProj4();
144-
if ( !useDefaultDatumTransform )
145-
{
146-
destProjString = stripDatumTransform( destProjString );
147-
}
148-
if ( mDestinationDatumTransform != -1 )
149-
{
150-
destProjString += ( ' ' + datumTransformString( mDestinationDatumTransform ) );
151-
}
152-
153-
if ( !useDefaultDatumTransform )
154-
{
155-
addNullGridShifts( sourceProjString, destProjString );
156-
}
157-
158-
mSourceProjection = pj_init_plus( sourceProjString.toUtf8() );
159-
mDestinationProjection = pj_init_plus( destProjString.toUtf8() );
160-
161-
#ifdef COORDINATE_TRANSFORM_VERBOSE
162-
QgsDebugMsg( "From proj : " + mSourceCRS.toProj4() );
163-
QgsDebugMsg( "To proj : " + mDestCRS.toProj4() );
164-
#endif
165-
166-
if ( !mDestinationProjection || !mSourceProjection )
167-
{
168-
mIsValid = false;
169-
}
170-
171-
#ifdef COORDINATE_TRANSFORM_VERBOSE
172-
if ( mIsValid )
173-
{
174-
QgsDebugMsg( "------------------------------------------------------------" );
175-
QgsDebugMsg( "The OGR Coordinate transformation for this layer was set to" );
176-
QgsLogger::debug<QgsCoordinateReferenceSystem>( "Input", mSourceCRS, __FILE__, __FUNCTION__, __LINE__ );
177-
QgsLogger::debug<QgsCoordinateReferenceSystem>( "Output", mDestCRS, __FILE__, __FUNCTION__, __LINE__ );
178-
QgsDebugMsg( "------------------------------------------------------------" );
179-
}
180-
else
181-
{
182-
QgsDebugMsg( "------------------------------------------------------------" );
183-
QgsDebugMsg( "The OGR Coordinate transformation FAILED TO INITIALIZE!" );
184-
QgsDebugMsg( "------------------------------------------------------------" );
185-
}
186-
#else
187-
if ( !mIsValid )
188-
{
189-
QgsDebugMsg( "Coordinate transformation failed to initialize!" );
190-
}
191-
#endif
192-
193-
//XXX todo overload == operator for QgsCoordinateReferenceSystem
194-
//at the moment srs.parameters contains the whole proj def...soon it won't...
195-
//if (mSourceCRS->toProj4() == mDestCRS->toProj4())
196-
if ( mSourceCRS == mDestCRS )
197-
{
198-
// If the source and destination projection are the same, set the short
199-
// circuit flag (no transform takes place)
200-
mShortCircuit = true;
201-
QgsDebugMsgLevel( "Source/Dest CRS equal, shortcircuit is set.", 3 );
202-
}
203-
else
204-
{
205-
// Transform must take place
206-
mShortCircuit = false;
207-
QgsDebugMsgLevel( "Source/Dest CRS not equal, shortcircuit is not set.", 3 );
208-
}
209-
return mIsValid;
210-
}
211-
212-
//! Removes +nadgrids and +towgs84 from proj4 string
213-
QString stripDatumTransform( const QString &proj4 ) const
214-
{
215-
QStringList parameterSplit = proj4.split( '+', QString::SkipEmptyParts );
216-
QString currentParameter;
217-
QString newProjString;
218-
219-
for ( int i = 0; i < parameterSplit.size(); ++i )
220-
{
221-
currentParameter = parameterSplit.at( i );
222-
if ( !currentParameter.startsWith( QLatin1String( "towgs84" ), Qt::CaseInsensitive )
223-
&& !currentParameter.startsWith( QLatin1String( "nadgrids" ), Qt::CaseInsensitive ) )
224-
{
225-
newProjString.append( '+' );
226-
newProjString.append( currentParameter );
227-
newProjString.append( ' ' );
228-
}
229-
}
230-
return newProjString;
231-
}
232-
233-
static QString datumTransformString( int datumTransform )
234-
{
235-
QString transformString;
236-
237-
sqlite3 *db = nullptr;
238-
int openResult = sqlite3_open_v2( QgsApplication::srsDatabaseFilePath().toUtf8().constData(), &db, SQLITE_OPEN_READONLY, 0 );
239-
if ( openResult != SQLITE_OK )
240-
{
241-
sqlite3_close( db );
242-
return transformString;
243-
}
244-
245-
sqlite3_stmt *stmt = nullptr;
246-
QString sql = QStringLiteral( "SELECT coord_op_method_code,p1,p2,p3,p4,p5,p6,p7 FROM tbl_datum_transform WHERE coord_op_code=%1" ).arg( datumTransform );
247-
int prepareRes = sqlite3_prepare( db, sql.toLatin1(), sql.size(), &stmt, nullptr );
248-
if ( prepareRes != SQLITE_OK )
249-
{
250-
sqlite3_finalize( stmt );
251-
sqlite3_close( db );
252-
return transformString;
253-
}
254-
255-
if ( sqlite3_step( stmt ) == SQLITE_ROW )
256-
{
257-
//coord_op_methode_code
258-
int methodCode = sqlite3_column_int( stmt, 0 );
259-
if ( methodCode == 9615 ) //ntv2
260-
{
261-
transformString = "+nadgrids=" + QString( reinterpret_cast< const char * >( sqlite3_column_text( stmt, 1 ) ) );
262-
}
263-
else if ( methodCode == 9603 || methodCode == 9606 || methodCode == 9607 )
264-
{
265-
transformString += QLatin1String( "+towgs84=" );
266-
double p1 = sqlite3_column_double( stmt, 1 );
267-
double p2 = sqlite3_column_double( stmt, 2 );
268-
double p3 = sqlite3_column_double( stmt, 3 );
269-
double p4 = sqlite3_column_double( stmt, 4 );
270-
double p5 = sqlite3_column_double( stmt, 5 );
271-
double p6 = sqlite3_column_double( stmt, 6 );
272-
double p7 = sqlite3_column_double( stmt, 7 );
273-
if ( methodCode == 9603 ) //3 parameter transformation
274-
{
275-
transformString += QStringLiteral( "%1,%2,%3" ).arg( p1 ).arg( p2 ).arg( p3 );
276-
}
277-
else //7 parameter transformation
278-
{
279-
transformString += QStringLiteral( "%1,%2,%3,%4,%5,%6,%7" ).arg( p1 ).arg( p2 ).arg( p3 ).arg( p4 ).arg( p5 ).arg( p6 ).arg( p7 );
280-
}
281-
}
282-
}
283-
284-
sqlite3_finalize( stmt );
285-
sqlite3_close( db );
286-
return transformString;
287-
}
288-
289-
//! In certain situations, null grid shifts have to be added to src / dst proj string
290-
void addNullGridShifts( QString &srcProjString, QString &destProjString ) const
291-
{
292-
//if one transformation uses ntv2, the other one needs to be null grid shift
293-
if ( mDestinationDatumTransform == -1 && srcProjString.contains( QLatin1String( "+nadgrids" ) ) ) //add null grid if source transformation is ntv2
294-
{
295-
destProjString += QLatin1String( " +nadgrids=@null" );
296-
return;
297-
}
298-
if ( mSourceDatumTransform == -1 && destProjString.contains( QLatin1String( "+nadgrids" ) ) )
299-
{
300-
srcProjString += QLatin1String( " +nadgrids=@null" );
301-
return;
302-
}
303-
304-
//add null shift grid for google mercator
305-
//(see e.g. http://trac.osgeo.org/proj/wiki/FAQ#ChangingEllipsoidWhycantIconvertfromWGS84toGoogleEarthVirtualGlobeMercator)
306-
if ( mSourceCRS.authid().compare( QLatin1String( "EPSG:3857" ), Qt::CaseInsensitive ) == 0 && mSourceDatumTransform == -1 )
307-
{
308-
srcProjString += QLatin1String( " +nadgrids=@null" );
309-
}
310-
if ( mDestCRS.authid().compare( QLatin1String( "EPSG:3857" ), Qt::CaseInsensitive ) == 0 && mDestinationDatumTransform == -1 )
311-
{
312-
destProjString += QLatin1String( " +nadgrids=@null" );
313-
}
314-
}
48+
~QgsCoordinateTransformPrivate();
31549

50+
bool initialize();
31651

31752
//! Flag to indicate whether the transform is valid (ie has a valid
31853
//! source and destination crs)
@@ -339,21 +74,17 @@ class QgsCoordinateTransformPrivate : public QSharedData
33974
int mSourceDatumTransform;
34075
int mDestinationDatumTransform;
34176

342-
void setFinder()
343-
{
344-
#if 0
345-
// Attention! It should be possible to set PROJ_LIB
346-
// but it can happen that it was previously set by installer
347-
// (version 0.7) and the old installation was deleted
77+
static QString datumTransformString( int datumTransform );
78+
79+
private:
34880

349-
// Another problem: PROJ checks if pj_finder was set before
350-
// PROJ_LIB environment variable. pj_finder is probably set in
351-
// GRASS gproj library when plugin is loaded, consequently
352-
// PROJ_LIB is ignored
81+
//! Removes +nadgrids and +towgs84 from proj4 string
82+
QString stripDatumTransform( const QString &proj4 ) const;
83+
84+
//! In certain situations, null grid shifts have to be added to src / dst proj string
85+
void addNullGridShifts( QString &srcProjString, QString &destProjString ) const;
35386

354-
pj_set_finder( finder );
355-
#endif
356-
}
87+
void setFinder();
35788
};
35889

35990
/// @endcond

0 commit comments

Comments
 (0)
Please sign in to comment.