Skip to content

Commit

Permalink
Fix switched axes problem in WMS 1.3 with non-projected CRS
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Feb 15, 2014
1 parent 51afb50 commit b5897c7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
58 changes: 31 additions & 27 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -639,20 +639,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
mCacheReply = 0;
}

//according to the WMS spec for 1.3, some CRS have inverted axis
bool changeXY = false;
if ( !mIgnoreAxisOrientation && ( mCapabilities.version == "1.3.0" || mCapabilities.version == "1.3" ) )
{
//create CRS from string
QgsCoordinateReferenceSystem theSrs;
if ( theSrs.createFromOgcWmsCrs( mImageCrs ) && theSrs.axisInverted() )
{
changeXY = true;
}
}

if ( mInvertAxisOrientation )
changeXY = !changeXY;
bool changeXY = shouldInvertAxisOrientation( mImageCrs );

// compose the URL query string for the WMS server.
QString crsKey = "SRS"; //SRS in 1.1.1 and CRS in 1.3.0
Expand Down Expand Up @@ -2493,6 +2480,13 @@ void QgsWmsProvider::parseLayer( QDomElement const & e, QgsWmsLayerProperty& lay
else if ( e1.hasAttribute( "SRS" ) )
bbox.crs = e1.attribute( "SRS" );

if ( shouldInvertAxisOrientation( bbox.crs ) )
{
QgsRectangle invAxisBbox( bbox.box.yMinimum(), bbox.box.xMinimum(),
bbox.box.yMaximum(), bbox.box.xMaximum() );
bbox.box = invAxisBbox;
}

layerProperty.boundingBox.push_back( bbox );
}
else
Expand Down Expand Up @@ -4240,19 +4234,7 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs

// Collect which layers to query on
//according to the WMS spec for 1.3, the order of x - and y - coordinates is inverted for geographical CRS
bool changeXY = false;
if ( !mIgnoreAxisOrientation && ( mCapabilities.version == "1.3.0" || mCapabilities.version == "1.3" ) )
{
//create CRS from string
QgsCoordinateReferenceSystem theSrs;
if ( theSrs.createFromOgcWmsCrs( mImageCrs ) && theSrs.axisInverted() )
{
changeXY = true;
}
}

if ( mInvertAxisOrientation )
changeXY = !changeXY;
bool changeXY = shouldInvertAxisOrientation( mImageCrs );

// compose the URL query string for the WMS server.
QString crsKey = "SRS"; //SRS in 1.1.1 and CRS in 1.3.0
Expand Down Expand Up @@ -4962,6 +4944,28 @@ void QgsWmsProvider::getLegendGraphicReplyProgress( qint64 bytesReceived, qint64
emit statusChanged( msg );
}

bool QgsWmsProvider::shouldInvertAxisOrientation( const QString& ogcCrs )
{
//according to the WMS spec for 1.3, some CRS have inverted axis
bool changeXY = false;
if ( !mIgnoreAxisOrientation && ( mCapabilities.version == "1.3.0" || mCapabilities.version == "1.3" ) )
{
//create CRS from string
QgsCoordinateReferenceSystem theSrs;
if ( theSrs.createFromOgcWmsCrs( ogcCrs ) && theSrs.axisInverted() )
{
changeXY = true;
}
}

if ( mInvertAxisOrientation )
changeXY = !changeXY;

return changeXY;
}



/**
* Class factory to return a pointer to a newly created
* QgsWmsProvider object
Expand Down
3 changes: 3 additions & 0 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -778,6 +778,9 @@ class QgsWmsProvider : public QgsRasterDataProvider
private:
void showMessageBox( const QString& title, const QString& text );

/** Find out whether to invert axis orientation when parsing/writing coordinates */
bool shouldInvertAxisOrientation( const QString& ogcCrs );

/**
* Try to get best extent for the layer in given CRS. Returns true on success, false otherwise (layer not found, invalid CRS, transform failed)
*/
Expand Down

0 comments on commit b5897c7

Please sign in to comment.