Skip to content

Commit

Permalink
add support for optional wm(t)s axis inversion
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jun 4, 2012
1 parent e7af002 commit 08a712a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/gui/qgsmanageconnectionsdialog.cpp
Expand Up @@ -306,6 +306,7 @@ QDomDocument QgsManageConnectionsDialog::saveWMSConnections( const QStringList &
el.setAttribute( "ignoreGetMapURI", settings.value( path + connections[i] + "/ignoreGetMapURI", false ).toBool() ? "true" : "false" );
el.setAttribute( "ignoreGetFeatureInfoURI", settings.value( path + connections[i] + "/ignoreGetFeatureInfoURI", false ).toBool() ? "true" : "false" );
el.setAttribute( "ignoreAxisOrientation", settings.value( path + connections[i] + "/ignoreAxisOrientation", false ).toBool() ? "true" : "false" );
el.setAttribute( "invertAxisOrientation", settings.value( path + connections[i] + "/invertAxisOrientation", false ).toBool() ? "true" : "false" );

path = "/Qgis/WMS/";
el.setAttribute( "username", settings.value( path + connections[ i ] + "/username", "" ).toString() );
Expand Down Expand Up @@ -493,6 +494,7 @@ void QgsManageConnectionsDialog::loadWMSConnections( const QDomDocument &doc, co
settings.setValue( QString( "/" + connectionName + "/ignoreGetMapURI" ), child.attribute( "ignoreGetMapURI" ) == "true" );
settings.setValue( QString( "/" + connectionName + "/ignoreGetFeatureInfoURI" ), child.attribute( "ignoreGetFeatureInfoURI" ) == "true" );
settings.setValue( QString( "/" + connectionName + "/ignoreAxisOrientation" ), child.attribute( "ignoreAxisOrientation" ) == "true" );
settings.setValue( QString( "/" + connectionName + "/invertAxisOrientation" ), child.attribute( "invertAxisOrientation" ) == "true" );
settings.endGroup();

if ( !child.attribute( "username" ).isEmpty() )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsnewhttpconnection.cpp
Expand Up @@ -53,12 +53,14 @@ QgsNewHttpConnection::QgsNewHttpConnection(
cbxIgnoreGetMapURI->setChecked( settings.value( key + "/ignoreGetMapURI", false ).toBool() );
cbxIgnoreGetFeatureInfoURI->setChecked( settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool() );
cbxIgnoreAxisOrientation->setChecked( settings.value( key + "/ignoreAxisOrientation", false ).toBool() );
cbxInvertAxisOrientation->setChecked( settings.value( key + "/invertAxisOrientation", false ).toBool() );
}
else
{
cbxIgnoreGetMapURI->setVisible( false );
cbxIgnoreGetFeatureInfoURI->setVisible( false );
cbxIgnoreAxisOrientation->setVisible( false );
cbxInvertAxisOrientation->setVisible( false );
}

txtUserName->setText( settings.value( credentialsKey + "/username" ).toString() );
Expand Down Expand Up @@ -124,6 +126,7 @@ void QgsNewHttpConnection::accept()
settings.setValue( key + "/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
settings.setValue( key + "/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
settings.setValue( key + "/ignoreAxisOrientation", cbxIgnoreAxisOrientation->isChecked() );
settings.setValue( key + "/invertAxisOrientation", cbxInvertAxisOrientation->isChecked() );
}

settings.setValue( credentialsKey + "/username", txtUserName->text() );
Expand Down
46 changes: 28 additions & 18 deletions src/providers/wms/qgswmsconnection.cpp
Expand Up @@ -63,28 +63,38 @@ QgsWMSConnection::QgsWMSConnection( QString theConnName ) :
bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool();
bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool();
if ( ignoreGetMap || ignoreGetFeatureInfo || ignoreAxisOrientation )
bool invertAxisOrientation = settings.value( key + "/invertAxisOrientation", false ).toBool();

QString connArgs, delim;


if ( ignoreGetMap )
{
QString connArgs = "ignoreUrl=";
connArgs += delim + "GetMap";
delim = ";";
}

if ( ignoreGetMap )
{
connArgs += "GetMap";
}
if ( ignoreGetFeatureInfo )
{
connArgs += delim + "GetFeatureInfo";
delim = ";";
}

if ( ignoreGetFeatureInfo )
{
if ( !connArgs.endsWith( "=" ) )
connArgs += ";";
connArgs += "GetFeatureInfo";
}
if ( ignoreAxisOrientation )
{
connArgs += delim + "AxisOrientation";
delim = ";";
}

if ( ignoreAxisOrientation )
{
if ( !connArgs.endsWith( "=" ) )
connArgs += ";";
connArgs += "AxisOrientation";
}
if ( invertAxisOrientation )
{
connArgs += delim + "InvertAxisOrientation";
delim = ";";
}

if( !connArgs.isEmpty() )
{
connArgs.prepend( "ignoreUrl=" );

if ( mConnectionInfo.startsWith( "username=" ) )
{
Expand Down
19 changes: 17 additions & 2 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -130,6 +130,7 @@ void QgsWmsProvider::parseUri( QString uri )
mIgnoreGetMapUrl = false;
mIgnoreGetFeatureInfoUrl = false;
mIgnoreAxisOrientation = false;
mInvertAxisOrientation = false;

QString layer;

Expand Down Expand Up @@ -179,6 +180,10 @@ void QgsWmsProvider::parseUri( QString uri )
{
mIgnoreAxisOrientation = true;
}
else if ( param == "InvertAxisOrientation" )
{
mInvertAxisOrientation = true;
}
}
}
else if ( item.startsWith( "tileMatrixSet=" ) )
Expand Down Expand Up @@ -550,6 +555,9 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
}
}

if ( mInvertAxisOrientation )
changeXY = !changeXY;

// compose the URL query string for the WMS server.
QString crsKey = "SRS"; //SRS in 1.1.1 and CRS in 1.3.0
if ( mCapabilities.version == "1.3.0" || mCapabilities.version == "1.3" )
Expand Down Expand Up @@ -2529,12 +2537,16 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )

s.crs = crs.authid();

bool invert = !mIgnoreAxisOrientation && crs.axisInverted();
if ( mInvertAxisOrientation )
invert = !invert;

QgsDebugMsg( QString( "tilematrix set: %1 (supportedCRS:%2 crs:%3; metersPerUnit:%4 axisInverted:%5)" )
.arg( s.identifier )
.arg( supportedCRS )
.arg( s.crs )
.arg( metersPerUnit, 0, 'f' )
.arg( !mIgnoreAxisOrientation && crs.axisInverted() ? "yes" : "no" )
.arg( invert ? "yes" : "no" )
);

for ( QDomNode n1 = n0.firstChildElement( "TileMatrix" );
Expand All @@ -2553,7 +2565,7 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
QStringList topLeft = n1.firstChildElement( "TopLeftCorner" ).text().split( " " );
if ( topLeft.size() == 2 )
{
if ( !mIgnoreAxisOrientation && crs.axisInverted() )
if ( invert )
{
m.topLeft.set( topLeft[1].toDouble(), topLeft[0].toDouble() );
}
Expand Down Expand Up @@ -3733,6 +3745,9 @@ QStringList QgsWmsProvider::identifyAs( const QgsPoint& point, QString format )
}
}

if ( mInvertAxisOrientation )
changeXY = !changeXY;

// compose the URL query string for the WMS server.
QString crsKey = "SRS"; //SRS in 1.1.1 and CRS in 1.3.0
if ( mCapabilities.version == "1.3.0" || mCapabilities.version == "1.3" )
Expand Down
1 change: 1 addition & 0 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -1098,6 +1098,7 @@ class QgsWmsProvider : public QgsRasterDataProvider
bool mIgnoreGetMapUrl;
bool mIgnoreGetFeatureInfoUrl;
bool mIgnoreAxisOrientation;
bool mInvertAxisOrientation;

//! supported formats for GetFeatureInfo in order of preference
QStringList mSupportedGetFeatureFormats;
Expand Down
17 changes: 15 additions & 2 deletions src/ui/qgsnewhttpconnectionbase.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>507</width>
<height>322</height>
<width>475</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -48,6 +48,12 @@
</item>
<item row="4" column="0" colspan="3">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>If the service requires basic authentication, enter a user name and optional password</string>
</property>
Expand Down Expand Up @@ -149,6 +155,13 @@
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="QCheckBox" name="cbxInvertAxisOrientation">
<property name="text">
<string>Invert axis orientation</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 08a712a

Please sign in to comment.