Skip to content

Commit 949b2f0

Browse files
committedMar 16, 2012
WMS 1.3: better detection of inverted axis
1 parent 9151fd5 commit 949b2f0

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed
 

‎src/core/qgscoordinatereferencesystem.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ QgsCoordinateReferenceSystem& QgsCoordinateReferenceSystem::operator=( const Qgs
166166
mProjectionAcronym = srs.mProjectionAcronym;
167167
mEllipsoidAcronym = srs.mEllipsoidAcronym;
168168
mGeoFlag = srs.mGeoFlag;
169+
mAxisInverted = srs.mAxisInverted;
169170
mMapUnits = srs.mMapUnits;
170171
mSRID = srs.mSRID;
171172
mAuthId = srs.mAuthId;
@@ -264,6 +265,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
264265
mSRID = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 5 ) ).toLong();
265266
mAuthId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 6 ) );
266267
mGeoFlag = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 7 ) ).toInt() != 0;
268+
mAxisInverted = -1;
267269

268270
if ( mSrsId >= USER_CRS_START_ID && mAuthId.isEmpty() )
269271
{
@@ -291,6 +293,21 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
291293
return mIsValidFlag;
292294
}
293295

296+
bool QgsCoordinateReferenceSystem::axisInverted() const
297+
{
298+
if ( mAxisInverted == -1 )
299+
{
300+
OGRAxisOrientation orientation;
301+
const char *axis0 = OSRGetAxis( mCRS, mGeoFlag ? "GEOGCS" : "PROJCS", 0, &orientation );
302+
mAxisInverted = mGeoFlag
303+
? (orientation == OAO_East || orientation == OAO_West || orientation == OAO_Other )
304+
: (orientation == OAO_North || orientation == OAO_South );
305+
QgsDebugMsg( QString( "srid:%1 axis0:%2 orientation:%3 inverted:%4" ).arg( mSRID ).arg( axis0 ).arg( OSRAxisEnumToName( orientation ) ).arg( mAxisInverted ) );
306+
}
307+
308+
return mAxisInverted != 0;
309+
}
310+
294311
bool QgsCoordinateReferenceSystem::createFromWkt( QString theWkt )
295312
{
296313
mIsValidFlag = false;

‎src/core/qgscoordinatereferencesystem.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
308308
*/
309309
bool geographicFlag() const;
310310

311+
/*! return if axis is inverted (eg. for WMS 1.3)
312+
* @return bool Whether this is crs axis is inverted
313+
* @note added in 1.9.90
314+
*/
315+
bool axisInverted() const;
316+
311317
/*! Get the units that the projection is in
312318
* @return QGis::UnitType that gives the units for the coordinate system
313319
*/
@@ -434,6 +440,9 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
434440
QString mValidationHint;
435441
mutable QString mWkt;
436442

443+
//!Whether this is a coordinate system has inverted axis
444+
mutable int mAxisInverted;
445+
437446
static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
438447
};
439448

‎src/mapserver/qgsconfigparser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,11 @@ QgsComposition* QgsConfigParser::createPrintComposition( const QString& composer
444444
c->removeItem( currentMap ); delete currentMap; continue;
445445
}
446446

447-
//Change x- and y- of extent for WMS 1.3.0 and geographic coordinate systems
447+
//Change x- and y- of extent for WMS 1.3.0 if axis inverted
448448
QString version = parameterMap.value( "VERSION" );
449449
if ( !version.isEmpty() )
450450
{
451-
if ( mapRenderer && version == "1.3.0" && mapRenderer->destinationCrs().geographicFlag() )
451+
if ( mapRenderer && version == "1.3.0" && mapRenderer->destinationCrs().axisInverted() )
452452
{
453453
//switch coordinates of extent
454454
double tmp;

‎src/mapserver/qgswmsserver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,9 +1120,9 @@ int QgsWMSServer::configureMapRender( const QPaintDevice* paintDevice ) const
11201120
}
11211121
mMapRenderer->setMapUnits( mapUnits );
11221122

1123-
// Change x- and y- of BBOX for WMS 1.3.0 and geographic coordinate systems
1123+
// Change x- and y- of BBOX for WMS 1.3.0 if axis inverted
11241124
QString version = mParameterMap.value( "VERSION", "1.3.0" );
1125-
if ( version == "1.3.0" && outputCRS.geographicFlag() )
1125+
if ( version == "1.3.0" && outputCRS.axisInverted() )
11261126
{
11271127
//switch coordinates of extent
11281128
double tmp;

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,13 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
415415
cacheReply = 0;
416416
}
417417

418-
//according to the WMS spec for 1.3, the order of x - and y - coordinates is inverted for geographical CRS
418+
//according to the WMS spec for 1.3, some CRS have inverted axis
419419
bool changeXY = false;
420420
if ( mCapabilities.version == "1.3.0" || mCapabilities.version == "1.3" )
421421
{
422422
//create CRS from string
423423
QgsCoordinateReferenceSystem theSrs;
424-
if ( theSrs.createFromOgcWmsCrs( imageCrs ) && theSrs.geographicFlag() )
424+
if ( theSrs.createFromOgcWmsCrs( imageCrs ) && theSrs.axisInverted() )
425425
{
426426
changeXY = true;
427427
}
@@ -2908,7 +2908,7 @@ QStringList QgsWmsProvider::identifyAs( const QgsPoint& point, QString format )
29082908
{
29092909
//create CRS from string
29102910
QgsCoordinateReferenceSystem theSrs;
2911-
if ( theSrs.createFromOgcWmsCrs( imageCrs ) && theSrs.geographicFlag() )
2911+
if ( theSrs.createFromOgcWmsCrs( imageCrs ) && theSrs.axisInverted() )
29122912
{
29132913
changeXY = true;
29142914
}

0 commit comments

Comments
 (0)
Please sign in to comment.