Skip to content

Commit 71d0e4d

Browse files
committedApr 22, 2012
deprecated QgsCoordinateReferenceSystem::equals: as it might return false
eventhough the proj.4 string is equal. PROJ.4 string isn't unique to CRSes.
1 parent 991c7ba commit 71d0e4d

File tree

6 files changed

+19
-26
lines changed

6 files changed

+19
-26
lines changed
 

‎python/core/qgscoordinatereferencesystem.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class QgsCoordinateReferenceSystem
169169
* Additionally logic may also be applied if the result from the OGR methods
170170
* is inconclusive.
171171
*/
172-
bool equals(QString theProj4String);
172+
bool equals(QString theProj4String) /Deprecated/;
173173

174174
/*! Restores state from the given Dom node.
175175
* @param theNode The node from which state will be restored

‎src/core/qgis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const int QGis::QGIS_VERSION_INT = VERSION_INT;
4040
// Release name
4141
const char* QGis::QGIS_RELEASE_NAME = RELEASE_NAME;
4242

43-
#if GDAL_VERSION_NUM > 1800
43+
#if GDAL_VERSION_NUM >= 1800
4444
const QString GEOPROJ4 = "+proj=longlat +datum=WGS84 +no_defs";
4545
#else
4646
const QString GEOPROJ4 = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";

‎src/core/qgscoordinatereferencesystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
950950
{
951951
QString mySrsId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) );
952952
QString myProj4String = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 1 ) );
953-
if ( equals( myProj4String ) )
953+
if ( toProj4() == myProj4String.trimmed() )
954954
{
955955
QgsDebugMsg( "-------> MATCH FOUND in srs.db srsid: " + mySrsId );
956956
// close the sqlite3 statement
@@ -989,7 +989,7 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
989989
{
990990
QString mySrsId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) );
991991
QString myProj4String = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 1 ) );
992-
if ( equals( myProj4String ) )
992+
if ( toProj4() == myProj4String.trimmed() )
993993
{
994994
QgsDebugMsg( "-------> MATCH FOUND in user qgis.db srsid: " + mySrsId );
995995
// close the sqlite3 statement

‎src/core/qgscoordinatereferencesystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
210210
* Internally it will use OGR isSameCRS() or isSameGeoCRS() methods as appropriate.
211211
* Additionally logic may also be applied if the result from the OGR methods
212212
* is inconclusive.
213+
* @deprecated in 1.8 as the same proj.4 string not necessarily means the same CRS
213214
*/
214-
bool equals( QString theProj4String );
215+
Q_DECL_DEPRECATED bool equals( QString theProj4String );
215216

216217
/*! Restores state from the given Dom node.
217218
* @param theNode The node from which state will be restored

‎src/providers/postgres/qgspgtablemodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ bool QgsPgTableModel::setData( const QModelIndex &idx, const QVariant &value, in
332332

333333
bool ok = geomType != QGis::WKBUnknown;
334334

335-
if ( ok && geomType != QGis::NoGeometry )
335+
if ( ok && geomType != QGis::WKBNoGeometry )
336336
idx.sibling( idx.row(), dbtmSrid ).data().toInt( &ok );
337337

338338
QStringList pkCols = idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 1 ).toStringList();

‎tests/src/core/testqgscoordinatereferencesystem.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class TestQgsCoordinateReferenceSystem: public QObject
4646
void validate();
4747
void equality();
4848
void noEquality();
49-
void equals();
5049
void readXML();
5150
void writeXML();
5251
void setCustomSrsValidation();
@@ -71,6 +70,10 @@ void TestQgsCoordinateReferenceSystem::initTestCase()
7170
// init QGIS's paths - true means that all path will be inited from prefix
7271
QgsApplication::init();
7372
QgsApplication::showSettings();
73+
qDebug() << "GEOPROJ4 constant: " << GEOPROJ4;
74+
qDebug() << "GDAL version (build): " << GDAL_RELEASE_NAME;
75+
qDebug() << "GDAL version (runtime): " << GDALVersionInfo("RELEASE_NAME");
76+
qDebug() << "PROJ.4 version: " << PJ_VERSION;
7477
}
7578

7679
void TestQgsCoordinateReferenceSystem::wktCtor()
@@ -177,15 +180,6 @@ void TestQgsCoordinateReferenceSystem::noEquality()
177180
debugPrint( myCrs );
178181
QVERIFY( myCrs != myCrs2 );
179182
}
180-
void TestQgsCoordinateReferenceSystem::equals()
181-
{
182-
QgsCoordinateReferenceSystem myCrs;
183-
myCrs.createFromSrid( GEOSRID );
184-
debugPrint( myCrs );
185-
//Note: OSRImportFromProj4 (used internally by equals)
186-
//drops the TOWGS from the WKT which causes this test to fail
187-
QVERIFY( myCrs.equals( GEOPROJ4 ) );
188-
}
189183
void TestQgsCoordinateReferenceSystem::readXML()
190184
{
191185
//QgsCoordinateReferenceSystem myCrs;
@@ -235,23 +229,24 @@ void TestQgsCoordinateReferenceSystem::toWkt()
235229
myCrs.createFromSrid( GEOSRID );
236230
QString myWkt = myCrs.toWkt();
237231
debugPrint( myCrs );
232+
#if GDAL_VERSION_NUM >= 1800
238233
//Note: this is not the same as GEOWKT as OGR strips off the TOWGS clause...
239234
QString myStrippedWkt( "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID"
240235
"[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],"
241236
"AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY"
242237
"[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY"
243238
"[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]" );
244-
// for GDAL 1.7
245-
QString myAltStrippedWkt( "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID"
239+
#else
240+
// for GDAL <1.8
241+
QString myStrippedWkt( "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID"
246242
"[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],"
247243
"AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY"
248244
"[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY"
249245
"[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]" );
250-
qDebug() << "myWkt:\n";
251-
qDebug() << myWkt;
252-
qDebug() << "myStrippedWkt:\n";
253-
qDebug() << myStrippedWkt;
254-
QVERIFY( myWkt == myStrippedWkt || myWkt == myAltStrippedWkt );
246+
#endif
247+
qDebug() << "wkt: " << myWkt;
248+
qDebug() << "stripped: " << myStrippedWkt;
249+
QVERIFY( myWkt == myStrippedWkt );
255250
}
256251
void TestQgsCoordinateReferenceSystem::toProj4()
257252
{
@@ -308,9 +303,6 @@ void TestQgsCoordinateReferenceSystem::debugPrint(
308303
{
309304
QgsDebugMsg( "* Units : degrees" );
310305
}
311-
312-
QgsDebugMsg( QString( "** GDAL version: %1" ).arg( GDAL_RELEASE_NAME ) );
313-
QgsDebugMsg( QString( "** PROJ.4 version: %1" ).arg( PJ_VERSION ) );
314306
}
315307

316308
QTEST_MAIN( TestQgsCoordinateReferenceSystem )

2 commit comments

Comments
 (2)

timlinux commented on Apr 23, 2012

@timlinux
Member

Ah good solution thanks!

etiennesky commented on Apr 24, 2012

@etiennesky
Contributor

perhaps you could use OGRSpatialReference::IsSame () ???

Please sign in to comment.