Skip to content
Permalink
Browse files

Fix equality check for CRS objects which don't have an auth id

(cherry picked from commit d4363b1)
  • Loading branch information
nyalldawson committed Jan 22, 2020
1 parent 3ef030e commit b4e5fa468f6336c56606cdfe042016c09bed5748
Showing with 30 additions and 2 deletions.
  1. +14 −2 src/core/qgscoordinatereferencesystem.cpp
  2. +16 −0 tests/src/core/testqgscoordinatereferencesystem.cpp
@@ -1863,8 +1863,20 @@ long QgsCoordinateReferenceSystem::findMatchingProj()

bool QgsCoordinateReferenceSystem::operator==( const QgsCoordinateReferenceSystem &srs ) const
{
return ( !d->mIsValid && !srs.d->mIsValid ) ||
( d->mIsValid && srs.d->mIsValid && srs.authid() == authid() );
// shortcut
if ( d == srs.d )
return true;

if ( !d->mIsValid && !srs.d->mIsValid )
return true;

if ( !d->mIsValid || !srs.d->mIsValid )
return false;

if ( !d->mAuthId.isEmpty() && d->mAuthId == srs.d->mAuthId )
return true;

return toWkt( WKT2_2018 ) == srs.toWkt( WKT2_2018 );
}

bool QgsCoordinateReferenceSystem::operator!=( const QgsCoordinateReferenceSystem &srs ) const
@@ -863,13 +863,29 @@ void TestQgsCoordinateReferenceSystem::equality()
{
QgsCoordinateReferenceSystem myCrs( QStringLiteral( "EPSG:4326" ) );
QgsCoordinateReferenceSystem myCrs2( QStringLiteral( "EPSG:4326" ) );
QgsCoordinateReferenceSystem myCrs3 = myCrs2;
QVERIFY( myCrs == myCrs2 );
QVERIFY( myCrs3 == myCrs2 );
QVERIFY( QgsCoordinateReferenceSystem() == QgsCoordinateReferenceSystem() );

// custom crs, no authid
myCrs.createFromWkt( QStringLiteral( "PROJCS[\"unnamed\",GEOGCS[\"unnamed\",DATUM[\"Geocentric_Datum_of_Australia_2020\",SPHEROID[\"GRS 80\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",147],PARAMETER[\"scale_factor\",0.1996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]" ) );
myCrs2.createFromWkt( QStringLiteral( "PROJCS[\"unnamed\",GEOGCS[\"unnamed\",DATUM[\"Geocentric_Datum_of_Australia_2020\",SPHEROID[\"GRS 80\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",147],PARAMETER[\"scale_factor\",0.1996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]" ) );
QVERIFY( myCrs == myCrs2 );
}
void TestQgsCoordinateReferenceSystem::noEquality()
{
QgsCoordinateReferenceSystem myCrs( QStringLiteral( "EPSG:4326" ) );
QgsCoordinateReferenceSystem myCrs2( QStringLiteral( "EPSG:4327" ) );
QVERIFY( myCrs != myCrs2 );
QVERIFY( myCrs != QgsCoordinateReferenceSystem() );
QVERIFY( QgsCoordinateReferenceSystem() != myCrs );

// custom crs, no authid
myCrs.createFromWkt( QStringLiteral( "PROJCS[\"unnamed\",GEOGCS[\"unnamed\",DATUM[\"Geocentric_Datum_of_Australia_2020\",SPHEROID[\"GRS 80\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",147],PARAMETER[\"scale_factor\",0.1996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]" ) );
myCrs2.createFromWkt( QStringLiteral( "PROJCS[\"unnamed\",GEOGCS[\"unnamed\",DATUM[\"Geocentric_Datum_of_Australia_2020\",SPHEROID[\"GRS 80\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",147],PARAMETER[\"scale_factor\",0.2996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]" ) );
QVERIFY( myCrs != myCrs2 );

}

void TestQgsCoordinateReferenceSystem::equalityInvalid()

0 comments on commit b4e5fa4

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