Skip to content

Commit

Permalink
QgsCoordinateReferenceSystem::createFromOgcWmsCrs(): use QgsOgcCrsUti…
Browse files Browse the repository at this point in the history
…ls::parseCrsName()
  • Loading branch information
rouault committed Sep 27, 2022
1 parent 9f4a7a2 commit f3cd819
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions src/core/proj/qgscoordinatereferencesystem.cpp
Expand Up @@ -40,6 +40,7 @@
#include "qgssettings.h"
#include "qgsogrutils.h"
#include "qgsdatums.h"
#include "qgsogcutils.h"
#include "qgsprojectionfactors.h"
#include "qgsprojoperation.h"

Expand Down Expand Up @@ -402,33 +403,27 @@ bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( const QString &crs )

QString wmsCrs = crs;

thread_local const QRegularExpression re_uri( QRegularExpression::anchoredPattern( QStringLiteral( "http://www\\.opengis\\.net/def/crs/([^/]+).+/([^/]+)" ) ), QRegularExpression::CaseInsensitiveOption );
QRegularExpressionMatch match = re_uri.match( wmsCrs );
if ( match.hasMatch() )
QString authority;
QString code;
const QgsOgcCrsUtils::CRSFlavor crsFlavor = QgsOgcCrsUtils::parseCrsName( crs, authority, code );
const QString authorityLower = authority.toLower();
if ( crsFlavor == QgsOgcCrsUtils::CRSFlavor::AUTH_CODE &&
( authorityLower == QLatin1String( "user" ) ||
authorityLower == QLatin1String( "custom" ) ||
authorityLower == QLatin1String( "qgis" ) ) )
{
wmsCrs = match.captured( 1 ) + ':' + match.captured( 2 );
}
else
{
thread_local const QRegularExpression re_urn( QRegularExpression::anchoredPattern( QStringLiteral( "urn:ogc:def:crs:([^:]+).+(?<=:)([^:]+)" ) ), QRegularExpression::CaseInsensitiveOption );
match = re_urn.match( wmsCrs );
if ( match.hasMatch() )
{
wmsCrs = match.captured( 1 ) + ':' + match.captured( 2 );
}
else
if ( createFromSrsId( code.toInt() ) )
{
thread_local const QRegularExpression re_urn_custom( QRegularExpression::anchoredPattern( QStringLiteral( "(user|custom|qgis):(\\d+)" ) ), QRegularExpression::CaseInsensitiveOption );
match = re_urn_custom.match( wmsCrs );
if ( match.hasMatch() && createFromSrsId( match.captured( 2 ).toInt() ) )
{
locker.changeMode( QgsReadWriteLocker::Write );
if ( !sDisableOgcCache )
sOgcCache()->insert( crs, *this );
return d->mIsValid;
}
locker.changeMode( QgsReadWriteLocker::Write );
if ( !sDisableOgcCache )
sOgcCache()->insert( crs, *this );
return d->mIsValid;
}
}
else if ( crsFlavor != QgsOgcCrsUtils::CRSFlavor::UNKNOWN )
{
wmsCrs = authority + ':' + code;
}

// first chance for proj 6 - scan through legacy systems and try to use authid directly
const QString legacyKey = wmsCrs.toLower();
Expand Down

0 comments on commit f3cd819

Please sign in to comment.