Skip to content
Permalink
Browse files

Improve crs comparison operators

and fallback to wkt comparison if both are user defined
  • Loading branch information
m-kuhn authored and nyalldawson committed Mar 31, 2021
1 parent 39e9046 commit ba1a41176c91a74aa61dbd4e41688f6974b177a0
Showing with 54 additions and 4 deletions.
  1. +54 −4 src/core/qgscoordinatereferencesystem.cpp
@@ -2585,19 +2585,69 @@ void QgsCoordinateReferenceSystem::invalidateCache( bool disableCache )
sCrsStringLock()->unlock();
}

// invalid < regular < user
bool operator> ( const QgsCoordinateReferenceSystem &c1, const QgsCoordinateReferenceSystem &c2 )
{
return c1.d->mSrsId > c2.d->mSrsId;
if ( c1.d == c2.d )
return false;

if ( !c1.d->mIsValid && !c2.d->mIsValid )
return false;

if ( !c1.d->mIsValid && c2.d->mIsValid )
return false;

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

const bool c1IsUser = c1.d->mSrsId >= USER_CRS_START_ID;
const bool c2IsUser = c2.d->mSrsId >= USER_CRS_START_ID;

if ( c1IsUser && !c2IsUser )
return true;

if ( !c1IsUser && c2IsUser )
return false;

if ( !c1IsUser && !c2IsUser )
return c1.d->mAuthId > c2.d->mAuthId;

return c1.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED ) > c2.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED );
}

bool operator< ( const QgsCoordinateReferenceSystem &c1, const QgsCoordinateReferenceSystem &c2 )
{
return c1.d->mSrsId < c2.d->mSrsId;
if ( c1.d == c2.d )
return false;

if ( !c1.d->mIsValid && !c2.d->mIsValid )
return false;

if ( c1.d->mIsValid && !c2.d->mIsValid )
return false;

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

const bool c1IsUser = c1.d->mSrsId >= USER_CRS_START_ID;
const bool c2IsUser = c2.d->mSrsId >= USER_CRS_START_ID;

if ( !c1IsUser && c2IsUser )
return true;

if ( c1IsUser && !c2IsUser )
return false;

if ( !c1IsUser && !c2IsUser )
return c1.d->mAuthId < c2.d->mAuthId;

return c1.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED ) < c2.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED );
}
bool operator>= ( const QgsCoordinateReferenceSystem &c1, const QgsCoordinateReferenceSystem &c2 )
{
return c1.d->mSrsId >= c2.d->mSrsId;
return !( c1 < c2 );
}
bool operator<= ( const QgsCoordinateReferenceSystem &c1, const QgsCoordinateReferenceSystem &c2 )
{
return c1.d->mSrsId <= c2.d->mSrsId;
return !( c1 > c2 );
}

0 comments on commit ba1a411

Please sign in to comment.