Skip to content

Commit

Permalink
Handle polar CRS with NE axis order
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik Sylve authored and nyalldawson committed Feb 13, 2025
1 parent 9e127a8 commit 4b9e1d6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/core/proj/qgsprojutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ bool QgsProjUtils::usesAngularUnit( const QString &projDef )
bool QgsProjUtils::axisOrderIsSwapped( const PJ *crs )
{
//ported from https://github.com/pramsey/postgis/blob/7ecf6839c57a838e2c8540001a3cd35b78a730db/liblwgeom/lwgeom_transform.c#L299
//and GDAL OGRSpatialReference::isNorthEastAxisOrder https://github.com/OSGeo/gdal/blob/release/3.10/ogr/ogrspatialreference.cpp#L419
if ( !crs )
return false;

Expand All @@ -129,19 +130,46 @@ bool QgsProjUtils::axisOrderIsSwapped( const PJ *crs )
const int axisCount = proj_cs_get_axis_count( context, pjCs.get() );
if ( axisCount > 0 )
{
const char *outDirection = nullptr;
// Read only first axis, see if it is degrees / north
const char *outDirection0 = nullptr;
const char *outDirection1 = nullptr;
const char *outName0 = nullptr;
const char *outName1 = nullptr;

proj_cs_get_axis_info( context, pjCs.get(), 0,
&outName0,
nullptr,
&outDirection0,
nullptr,
&outDirection,
nullptr,
nullptr,
nullptr
);

proj_cs_get_axis_info( context, pjCs.get(), 1,
&outName1,
nullptr,
&outDirection1,
nullptr,
nullptr,
nullptr,
nullptr
);
return QString( outDirection ).compare( QLatin1String( "north" ), Qt::CaseInsensitive ) == 0;

if ( QString( outDirection0 ).compare( QLatin1String( "north" ), Qt::CaseInsensitive ) == 0 &&
QString( outDirection1 ).compare( QLatin1String( "east" ), Qt::CaseInsensitive ) == 0 )
{
return true;
}

// Handle polar projections with NE-order
if ( ( QString( outDirection0 ).compare( QLatin1String( "north" ), Qt::CaseInsensitive ) == 0 &&
QString( outDirection1 ).compare( QLatin1String( "north" ), Qt::CaseInsensitive ) == 0 ) ||
( QString( outDirection0 ).compare( QLatin1String( "south" ), Qt::CaseInsensitive ) == 0 &&
QString( outDirection1 ).compare( QLatin1String( "south" ), Qt::CaseInsensitive ) == 0 ) )
{
return QString( outName0 ).startsWith( QLatin1String( "northing" ), Qt::CaseInsensitive ) &&
QString( outName1 ).startsWith( QLatin1String( "easting" ), Qt::CaseInsensitive ) ;
}
}
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/src/core/testqgsprojutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ void TestQgsProjUtils::axisOrderIsSwapped()
QVERIFY( QgsProjUtils::axisOrderIsSwapped( crs.get() ) );
crs.reset( proj_create( context, "urn:ogc:def:crs:EPSG::3903" ) );
QVERIFY( QgsProjUtils::axisOrderIsSwapped( crs.get() ) );
crs.reset( proj_create( context, "urn:ogc:def:crs:EPSG::32761" ) );
QVERIFY( QgsProjUtils::axisOrderIsSwapped( crs.get() ) );
crs.reset( proj_create( context, "urn:ogc:def:crs:EPSG::5482" ) );
QVERIFY( QgsProjUtils::axisOrderIsSwapped( crs.get() ) );
crs.reset( proj_create( context, "urn:ogc:def:crs:EPSG::32661" ) );
QVERIFY( QgsProjUtils::axisOrderIsSwapped( crs.get() ) );
}

void TestQgsProjUtils::searchPath()
Expand Down

0 comments on commit 4b9e1d6

Please sign in to comment.