Skip to content

Commit 2e9d3a8

Browse files
committedJan 17, 2014
CRS axis inversion retrieval update:
- back to OGRGetAxis() as OSREPSGTreatsAsNorthingEasting() was introduced with GDAL 1.10 (fixes builds with earlier GDALs; related to #9345) - keep using OSRImportFromEPSGA() as that's what retrieves the axis orientation (but only for EPSG codes)
1 parent e8b8e3a commit 2e9d3a8

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed
 

‎src/core/qgscoordinatereferencesystem.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -404,20 +404,23 @@ bool QgsCoordinateReferenceSystem::axisInverted() const
404404
{
405405
if ( mAxisInverted == -1 )
406406
{
407-
mAxisInverted = mGeoFlag ? OSREPSGTreatsAsLatLong( mCRS ) : OSREPSGTreatsAsNorthingEasting( mCRS );
407+
OGRAxisOrientation orientation;
408+
OSRGetAxis( mCRS, OSRIsGeographic( mCRS ) ? "GEOGCS" : "PROJCS", 0, &orientation );
408409

409-
// See GDAL-OGR: https://github.com/OSGeo/gdal/blob/trunk/gdal/ogr/ogrsf_frmts/gml/gmlutils.cpp#L322
410-
if ( !mAxisInverted )
410+
// If axis orientation is unknown, try again with OSRImportFromEPSGA for EPSG crs
411+
if( orientation == OAO_Other && mAuthId.startsWith( "EPSG:", Qt::CaseInsensitive ) )
411412
{
412413
OGRSpatialReferenceH crs = OSRNewSpatialReference( NULL );
413414

414-
if ( OSRImportFromEPSGA( crs, mSRID ) == OGRERR_NONE )
415+
if ( OSRImportFromEPSGA( crs, mAuthId.mid( 5 ).toInt() ) == OGRERR_NONE )
415416
{
416-
mAxisInverted = mGeoFlag ? OSREPSGTreatsAsLatLong( crs ) : OSREPSGTreatsAsNorthingEasting( crs );
417+
OSRGetAxis( crs, OSRIsGeographic( crs ) ? "GEOGCS" : "PROJCS", 0, &orientation );
417418
}
419+
418420
OSRDestroySpatialReference( crs );
419421
}
420-
QgsDebugMsg( QString( "srid:%1 inverted:%2" ).arg( mSRID ).arg( mAxisInverted ) );
422+
423+
mAxisInverted = orientation == OAO_North;
421424
}
422425

423426
return mAxisInverted != 0;
@@ -822,9 +825,7 @@ long QgsCoordinateReferenceSystem::srsid() const
822825

823826
long QgsCoordinateReferenceSystem::postgisSrid() const
824827
{
825-
826828
return mSRID;
827-
828829
}
829830

830831
QString QgsCoordinateReferenceSystem::authid() const
@@ -1731,9 +1732,7 @@ int QgsCoordinateReferenceSystem::syncDb()
17311732
char *psz = ba.data();
17321733
OGRErr ogrErr = OSRImportFromWkt( crs, &psz );
17331734
if ( ogrErr != OGRERR_NONE )
1734-
{
17351735
continue;
1736-
}
17371736

17381737
if ( OSRExportToProj4( crs, &psz ) != OGRERR_NONE )
17391738
continue;
@@ -1744,9 +1743,7 @@ int QgsCoordinateReferenceSystem::syncDb()
17441743
CPLFree( psz );
17451744

17461745
if ( proj4.isEmpty() )
1747-
{
17481746
continue;
1749-
}
17501747

17511748
sql = QString( "SELECT parameters,noupdate FROM tbl_srs WHERE auth_name='EPSG' AND auth_id='%1'" ).arg( it.key() );
17521749
if ( sqlite3_prepare( database, sql.toAscii(), sql.size(), &select, &tail ) != SQLITE_OK )

0 commit comments

Comments
 (0)
Please sign in to comment.