Skip to content

Commit

Permalink
Merge pull request #60058 from ptitjano/wms-scale-denominator-format
Browse files Browse the repository at this point in the history
qgswmsgetcapabilities: Use float format for min/max scale parameters
  • Loading branch information
elpaso authored Jan 9, 2025
2 parents 1b2e33e + 183d1ce commit 0984ab8
Show file tree
Hide file tree
Showing 4 changed files with 1,218 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/server/services/wms/qgswmsgetcapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,25 +1048,32 @@ namespace QgsWms
//min/max scale denominatorScaleBasedVisibility
if ( layerInfos.hasScaleBasedVisibility )
{
// Convert double to string and remove trailing zero and last point if present
auto formatScale = []( double value ) {
const thread_local QRegularExpression trailingZeroRegEx = QRegularExpression( QStringLiteral( "0+$" ) );
const thread_local QRegularExpression trailingPointRegEx = QRegularExpression( QStringLiteral( "[.]+$" ) );
return QString::number( value, 'f' ).remove( trailingZeroRegEx ).remove( trailingPointRegEx );
};

if ( version == QLatin1String( "1.1.1" ) )
{
double OGC_PX_M = 0.00028; // OGC reference pixel size in meter, also used by qgis
double SCALE_TO_SCALEHINT = OGC_PX_M * M_SQRT2;

QDomElement scaleHintElem = doc.createElement( QStringLiteral( "ScaleHint" ) );
scaleHintElem.setAttribute( QStringLiteral( "min" ), QString::number( layerInfos.maxScale * SCALE_TO_SCALEHINT ) );
scaleHintElem.setAttribute( QStringLiteral( "max" ), QString::number( layerInfos.minScale * SCALE_TO_SCALEHINT ) );
scaleHintElem.setAttribute( QStringLiteral( "min" ), formatScale( layerInfos.maxScale * SCALE_TO_SCALEHINT ) );
scaleHintElem.setAttribute( QStringLiteral( "max" ), formatScale( layerInfos.minScale * SCALE_TO_SCALEHINT ) );
layerElem.appendChild( scaleHintElem );
}
else
{
QDomElement minScaleElem = doc.createElement( QStringLiteral( "MinScaleDenominator" ) );
QDomText minScaleText = doc.createTextNode( QString::number( layerInfos.maxScale ) );
QDomText minScaleText = doc.createTextNode( formatScale( layerInfos.maxScale ) );
minScaleElem.appendChild( minScaleText );
layerElem.appendChild( minScaleElem );

QDomElement maxScaleElem = doc.createElement( QStringLiteral( "MaxScaleDenominator" ) );
QDomText maxScaleText = doc.createTextNode( QString::number( layerInfos.minScale ) );
QDomText maxScaleText = doc.createTextNode( formatScale( layerInfos.minScale ) );
maxScaleElem.appendChild( maxScaleText );
layerElem.appendChild( maxScaleElem );
}
Expand Down
8 changes: 8 additions & 0 deletions tests/src/python/test_qgsserver_wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ def test_getcapabilities_advertised_url(self):
b"\n".join(headers) + b"\n\n" + bytes(response.body()), expected
)

def test_getcapabilities_scale_denominator(self):
self.wms_request_compare(
"GetCapabilities",
None,
"wms_getcapabilities_scale_denominator",
"test_project_scale_denominator.qgs",
)

def test_getprojectsettings(self):
self.wms_request_compare("GetProjectSettings")

Expand Down
Loading

0 comments on commit 0984ab8

Please sign in to comment.