Skip to content

Commit

Permalink
deprecated QgsCoordinateReferenceSystem::equals: as it might return f…
Browse files Browse the repository at this point in the history
…alse

eventhough the proj.4 string is equal. PROJ.4 string isn't unique to
CRSes.
  • Loading branch information
jef-n committed Apr 22, 2012
1 parent 991c7ba commit 71d0e4d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion python/core/qgscoordinatereferencesystem.sip
Expand Up @@ -169,7 +169,7 @@ class QgsCoordinateReferenceSystem
* Additionally logic may also be applied if the result from the OGR methods
* is inconclusive.
*/
bool equals(QString theProj4String);
bool equals(QString theProj4String) /Deprecated/;

/*! Restores state from the given Dom node.
* @param theNode The node from which state will be restored
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgis.cpp
Expand Up @@ -40,7 +40,7 @@ const int QGis::QGIS_VERSION_INT = VERSION_INT;
// Release name
const char* QGis::QGIS_RELEASE_NAME = RELEASE_NAME;

#if GDAL_VERSION_NUM > 1800
#if GDAL_VERSION_NUM >= 1800
const QString GEOPROJ4 = "+proj=longlat +datum=WGS84 +no_defs";
#else
const QString GEOPROJ4 = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -950,7 +950,7 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
{
QString mySrsId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) );
QString myProj4String = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 1 ) );
if ( equals( myProj4String ) )
if ( toProj4() == myProj4String.trimmed() )
{
QgsDebugMsg( "-------> MATCH FOUND in srs.db srsid: " + mySrsId );
// close the sqlite3 statement
Expand Down Expand Up @@ -989,7 +989,7 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
{
QString mySrsId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) );
QString myProj4String = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 1 ) );
if ( equals( myProj4String ) )
if ( toProj4() == myProj4String.trimmed() )
{
QgsDebugMsg( "-------> MATCH FOUND in user qgis.db srsid: " + mySrsId );
// close the sqlite3 statement
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgscoordinatereferencesystem.h
Expand Up @@ -210,8 +210,9 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* Internally it will use OGR isSameCRS() or isSameGeoCRS() methods as appropriate.
* Additionally logic may also be applied if the result from the OGR methods
* is inconclusive.
* @deprecated in 1.8 as the same proj.4 string not necessarily means the same CRS
*/
bool equals( QString theProj4String );
Q_DECL_DEPRECATED bool equals( QString theProj4String );

/*! Restores state from the given Dom node.
* @param theNode The node from which state will be restored
Expand Down
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspgtablemodel.cpp
Expand Up @@ -332,7 +332,7 @@ bool QgsPgTableModel::setData( const QModelIndex &idx, const QVariant &value, in

bool ok = geomType != QGis::WKBUnknown;

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

QStringList pkCols = idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 1 ).toStringList();
Expand Down
32 changes: 12 additions & 20 deletions tests/src/core/testqgscoordinatereferencesystem.cpp
Expand Up @@ -46,7 +46,6 @@ class TestQgsCoordinateReferenceSystem: public QObject
void validate();
void equality();
void noEquality();
void equals();
void readXML();
void writeXML();
void setCustomSrsValidation();
Expand All @@ -71,6 +70,10 @@ void TestQgsCoordinateReferenceSystem::initTestCase()
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::showSettings();
qDebug() << "GEOPROJ4 constant: " << GEOPROJ4;
qDebug() << "GDAL version (build): " << GDAL_RELEASE_NAME;
qDebug() << "GDAL version (runtime): " << GDALVersionInfo("RELEASE_NAME");
qDebug() << "PROJ.4 version: " << PJ_VERSION;
}

void TestQgsCoordinateReferenceSystem::wktCtor()
Expand Down Expand Up @@ -177,15 +180,6 @@ void TestQgsCoordinateReferenceSystem::noEquality()
debugPrint( myCrs );
QVERIFY( myCrs != myCrs2 );
}
void TestQgsCoordinateReferenceSystem::equals()
{
QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrid( GEOSRID );
debugPrint( myCrs );
//Note: OSRImportFromProj4 (used internally by equals)
//drops the TOWGS from the WKT which causes this test to fail
QVERIFY( myCrs.equals( GEOPROJ4 ) );
}
void TestQgsCoordinateReferenceSystem::readXML()
{
//QgsCoordinateReferenceSystem myCrs;
Expand Down Expand Up @@ -235,23 +229,24 @@ void TestQgsCoordinateReferenceSystem::toWkt()
myCrs.createFromSrid( GEOSRID );
QString myWkt = myCrs.toWkt();
debugPrint( myCrs );
#if GDAL_VERSION_NUM >= 1800
//Note: this is not the same as GEOWKT as OGR strips off the TOWGS clause...
QString myStrippedWkt( "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID"
"[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],"
"AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY"
"[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY"
"[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]" );
// for GDAL 1.7
QString myAltStrippedWkt( "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID"
#else
// for GDAL <1.8
QString myStrippedWkt( "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID"
"[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],"
"AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY"
"[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY"
"[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]" );
qDebug() << "myWkt:\n";
qDebug() << myWkt;
qDebug() << "myStrippedWkt:\n";
qDebug() << myStrippedWkt;
QVERIFY( myWkt == myStrippedWkt || myWkt == myAltStrippedWkt );
#endif
qDebug() << "wkt: " << myWkt;
qDebug() << "stripped: " << myStrippedWkt;
QVERIFY( myWkt == myStrippedWkt );
}
void TestQgsCoordinateReferenceSystem::toProj4()
{
Expand Down Expand Up @@ -308,9 +303,6 @@ void TestQgsCoordinateReferenceSystem::debugPrint(
{
QgsDebugMsg( "* Units : degrees" );
}

QgsDebugMsg( QString( "** GDAL version: %1" ).arg( GDAL_RELEASE_NAME ) );
QgsDebugMsg( QString( "** PROJ.4 version: %1" ).arg( PJ_VERSION ) );
}

QTEST_MAIN( TestQgsCoordinateReferenceSystem )
Expand Down

2 comments on commit 71d0e4d

@timlinux
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good solution thanks!

@etiennesky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.