Skip to content

Commit

Permalink
Fixes WMTS GetCapabilities and axis order
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Jun 25, 2021
1 parent 8cb7fa0 commit 20a9b4c
Show file tree
Hide file tree
Showing 4 changed files with 746 additions and 4 deletions.
32 changes: 30 additions & 2 deletions src/server/services/wmts/qgswmtsgetcapabilities.cpp
Expand Up @@ -414,14 +414,42 @@ namespace QgsWmts

QDomElement bboxElement = doc.createElement( QStringLiteral( "ows:BoundingBox" ) );
bboxElement.setAttribute( QStringLiteral( "crs" ), tms.ref );

// lower corner
double firstCoord = rect.xMinimum();
double secondCoord = rect.yMinimum();

if ( crs.hasAxisInverted() )
{
std::swap( firstCoord, secondCoord );
}

QString firstCoordStr = qgsDoubleToString( QgsServerProjectUtils::floorWithPrecision( firstCoord, precision ), precision );
QString secondCoordStr = qgsDoubleToString( QgsServerProjectUtils::floorWithPrecision( secondCoord, precision ), precision );
const QDomText lowerCornerText = doc.createTextNode( QString( "%1 %2" ).arg( firstCoordStr, secondCoordStr ) );

QDomElement lowerCornerElement = doc.createElement( QStringLiteral( "ows:LowerCorner" ) );
QDomText lowerCornerText = doc.createTextNode( qgsDoubleToString( QgsServerProjectUtils::floorWithPrecision( rect.xMinimum(), precision ), precision ) + ' ' + qgsDoubleToString( QgsServerProjectUtils::floorWithPrecision( rect.yMinimum(), precision ), precision ) );
lowerCornerElement.appendChild( lowerCornerText );
bboxElement.appendChild( lowerCornerElement );

// upper corner
firstCoord = rect.xMaximum();
secondCoord = rect.yMaximum();

if ( crs.hasAxisInverted() )
{
std::swap( firstCoord, secondCoord );
}

firstCoordStr = qgsDoubleToString( QgsServerProjectUtils::ceilWithPrecision( firstCoord, precision ), precision );
secondCoordStr = qgsDoubleToString( QgsServerProjectUtils::ceilWithPrecision( secondCoord, precision ), precision );
const QDomText upperCornerText = doc.createTextNode( QString( "%1 %2" ).arg( firstCoordStr, secondCoordStr ) );

QDomElement upperCornerElement = doc.createElement( QStringLiteral( "ows:UpperCorner" ) );
QDomText upperCornerText = doc.createTextNode( qgsDoubleToString( QgsServerProjectUtils::ceilWithPrecision( rect.xMaximum(), precision ), precision ) + ' ' + qgsDoubleToString( QgsServerProjectUtils::ceilWithPrecision( rect.yMaximum(), precision ), precision ) );
upperCornerElement.appendChild( upperCornerText );
bboxElement.appendChild( upperCornerElement );

// update layer element
layerElem.appendChild( bboxElement );
}

Expand Down
10 changes: 8 additions & 2 deletions tests/src/python/test_qgsserver_wmts.py
Expand Up @@ -45,9 +45,11 @@ class TestQgsServerWMTS(QgsServerTestBase):
# Set to True to re-generate reference files for this class
regenerate_reference = False

def wmts_request_compare(self, request, version='', extra_query_string='', reference_base_name=None):
def wmts_request_compare(self, request, version='', extra_query_string='', reference_base_name=None, project=None):
# project = self.testdata_path + "test_project_wfs.qgs"
project = self.projectGroupsPath
if not project:
project = self.projectGroupsPath

assert os.path.exists(project), "Project file not found: " + project

query_string = '?MAP=%s&SERVICE=WMTS&REQUEST=%s' % (urllib.parse.quote(project), request)
Expand Down Expand Up @@ -118,6 +120,10 @@ def test_project_wmts(self):
self.wmts_request_compare(request)
# self.wmts_request_compare(request, '1.0.0')

def test_getcapabilities_epsg_axis_inverted(self):
project = os.path.join(self.testdata_path, "test_project_wmts_epsg_axis_inverted.qgz")
self.wmts_request_compare('GetCapabilities', project=project, reference_base_name="wmts_getcapabilities_axis_inverted")

def test_wmts_gettile(self):
# Testing project WMTS layer
qs = "?" + "&".join(["%s=%s" % i for i in list({
Expand Down
Binary file not shown.

0 comments on commit 20a9b4c

Please sign in to comment.