Skip to content
Permalink
Browse files
WMS 1.3: better detection of inverted axis
  • Loading branch information
jef-n committed Mar 16, 2012
1 parent 9151fd5 commit 949b2f0179f7d4fd1ef61856fd8ed9dc366a87ae
@@ -166,6 +166,7 @@ QgsCoordinateReferenceSystem& QgsCoordinateReferenceSystem::operator=( const Qgs
mProjectionAcronym = srs.mProjectionAcronym;
mEllipsoidAcronym = srs.mEllipsoidAcronym;
mGeoFlag = srs.mGeoFlag;
mAxisInverted = srs.mAxisInverted;
mMapUnits = srs.mMapUnits;
mSRID = srs.mSRID;
mAuthId = srs.mAuthId;
@@ -264,6 +265,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
mSRID = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 5 ) ).toLong();
mAuthId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 6 ) );
mGeoFlag = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 7 ) ).toInt() != 0;
mAxisInverted = -1;

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

bool QgsCoordinateReferenceSystem::axisInverted() const
{
if ( mAxisInverted == -1 )
{
OGRAxisOrientation orientation;
const char *axis0 = OSRGetAxis( mCRS, mGeoFlag ? "GEOGCS" : "PROJCS", 0, &orientation );
mAxisInverted = mGeoFlag
? (orientation == OAO_East || orientation == OAO_West || orientation == OAO_Other )
: (orientation == OAO_North || orientation == OAO_South );
QgsDebugMsg( QString( "srid:%1 axis0:%2 orientation:%3 inverted:%4" ).arg( mSRID ).arg( axis0 ).arg( OSRAxisEnumToName( orientation ) ).arg( mAxisInverted ) );
}

return mAxisInverted != 0;
}

bool QgsCoordinateReferenceSystem::createFromWkt( QString theWkt )
{
mIsValidFlag = false;
@@ -308,6 +308,12 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*/
bool geographicFlag() const;

/*! return if axis is inverted (eg. for WMS 1.3)
* @return bool Whether this is crs axis is inverted
* @note added in 1.9.90
*/
bool axisInverted() const;

/*! Get the units that the projection is in
* @return QGis::UnitType that gives the units for the coordinate system
*/
@@ -434,6 +440,9 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
QString mValidationHint;
mutable QString mWkt;

//!Whether this is a coordinate system has inverted axis
mutable int mAxisInverted;

static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
};

@@ -444,11 +444,11 @@ QgsComposition* QgsConfigParser::createPrintComposition( const QString& composer
c->removeItem( currentMap ); delete currentMap; continue;
}

//Change x- and y- of extent for WMS 1.3.0 and geographic coordinate systems
//Change x- and y- of extent for WMS 1.3.0 if axis inverted
QString version = parameterMap.value( "VERSION" );
if ( !version.isEmpty() )
{
if ( mapRenderer && version == "1.3.0" && mapRenderer->destinationCrs().geographicFlag() )
if ( mapRenderer && version == "1.3.0" && mapRenderer->destinationCrs().axisInverted() )
{
//switch coordinates of extent
double tmp;
@@ -1120,9 +1120,9 @@ int QgsWMSServer::configureMapRender( const QPaintDevice* paintDevice ) const
}
mMapRenderer->setMapUnits( mapUnits );

// Change x- and y- of BBOX for WMS 1.3.0 and geographic coordinate systems
// Change x- and y- of BBOX for WMS 1.3.0 if axis inverted
QString version = mParameterMap.value( "VERSION", "1.3.0" );
if ( version == "1.3.0" && outputCRS.geographicFlag() )
if ( version == "1.3.0" && outputCRS.axisInverted() )
{
//switch coordinates of extent
double tmp;
@@ -415,13 +415,13 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
cacheReply = 0;
}

//according to the WMS spec for 1.3, the order of x - and y - coordinates is inverted for geographical CRS
//according to the WMS spec for 1.3, some CRS have inverted axis
bool changeXY = false;
if ( mCapabilities.version == "1.3.0" || mCapabilities.version == "1.3" )
{
//create CRS from string
QgsCoordinateReferenceSystem theSrs;
if ( theSrs.createFromOgcWmsCrs( imageCrs ) && theSrs.geographicFlag() )
if ( theSrs.createFromOgcWmsCrs( imageCrs ) && theSrs.axisInverted() )
{
changeXY = true;
}
@@ -2908,7 +2908,7 @@ QStringList QgsWmsProvider::identifyAs( const QgsPoint& point, QString format )
{
//create CRS from string
QgsCoordinateReferenceSystem theSrs;
if ( theSrs.createFromOgcWmsCrs( imageCrs ) && theSrs.geographicFlag() )
if ( theSrs.createFromOgcWmsCrs( imageCrs ) && theSrs.axisInverted() )
{
changeXY = true;
}

0 comments on commit 949b2f0

Please sign in to comment.