Skip to content

Commit fe45af0

Browse files
authoredApr 24, 2019
Merge pull request #9841 from signedav/default_symbol_scale_bp_34
[server] Default scale/mupmm on GetLegendGraphics
2 parents 8e19a32 + 434df5b commit fe45af0

File tree

18 files changed

+1107
-444
lines changed

18 files changed

+1107
-444
lines changed
 

‎python/server/auto_generated/qgsserverprojectutils.sip.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ Returns the quality for WMS images defined in a QGIS project.
152152
:param project: the QGIS project
153153

154154
:return: quality if defined in project, -1 otherwise.
155+
%End
156+
157+
double wmsDefaultMapUnitsPerMm( const QgsProject &project );
158+
%Docstring
159+
Returns the default number of map units per millimeters in case of the scale is not given
160+
161+
:param project: the QGIS project
162+
163+
:return: the default number of map units per millimeter
164+
165+
.. versionadded:: 3.4
155166
%End
156167

157168
bool wmsUseLayerIds( const QgsProject &project );

‎src/app/qgsprojectproperties.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,25 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
637637
mWMSImageQualitySpinBox->setValue( imageQuality );
638638
}
639639

640+
QString defaultValueToolTip = tr( "In case of no other information to evaluate the map unit sized symbols, it uses default scale (on projected CRS) or default map units per mm (on geographic CRS)." );
641+
mWMSDefaultMapUnitsPerMm = new QDoubleSpinBox();
642+
mWMSDefaultMapUnitsPerMm->setDecimals( 4 );
643+
mWMSDefaultMapUnitsPerMm->setSingleStep( 0.001 );
644+
mWMSDefaultMapUnitsPerMm->setValue( QgsProject::instance()->readDoubleEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), 1 ) );
645+
mWMSDefaultMapUnitsPerMm->setToolTip( defaultValueToolTip );
646+
mWMSDefaultMapUnitScale = new QgsScaleWidget();
647+
mWMSDefaultMapUnitScale->setScale( QgsProject::instance()->readDoubleEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), 1 ) * QgsUnitTypes::fromUnitToUnitFactor( QgsProject::instance()->crs().mapUnits(), QgsUnitTypes::DistanceMillimeters ) );
648+
mWMSDefaultMapUnitScale->setToolTip( defaultValueToolTip );
649+
if ( QgsProject::instance()->crs().isGeographic() )
650+
{
651+
mWMSDefaultMapUnitsPerMmLayout->addWidget( mWMSDefaultMapUnitsPerMm );
652+
}
653+
else
654+
{
655+
mWMSDefaultMapUnitsPerMmLayout->addWidget( mWMSDefaultMapUnitScale );
656+
mWMSDefaultMapUnitsPerMmLabel->setText( tr( "Default scale for legend" ) );
657+
}
658+
640659
mWMTSUrlLineEdit->setText( QgsProject::instance()->readEntry( QStringLiteral( "WMTSUrl" ), QStringLiteral( "/" ), QString() ) );
641660
mWMTSMinScaleLineEdit->setValue( QgsProject::instance()->readNumEntry( QStringLiteral( "WMTSMinScale" ), QStringLiteral( "/" ), 5000 ) );
642661

@@ -1257,6 +1276,18 @@ void QgsProjectProperties::apply()
12571276
QgsProject::instance()->writeEntry( QStringLiteral( "WMSImageQuality" ), QStringLiteral( "/" ), imageQualityValue );
12581277
}
12591278

1279+
double defaultMapUnitsPerMm;
1280+
if ( QgsProject::instance()->crs().isGeographic() )
1281+
{
1282+
defaultMapUnitsPerMm = mWMSDefaultMapUnitsPerMm->value();
1283+
}
1284+
else
1285+
{
1286+
defaultMapUnitsPerMm = mWMSDefaultMapUnitScale->scale() / QgsUnitTypes::fromUnitToUnitFactor( QgsProject::instance()->crs().mapUnits(), QgsUnitTypes::DistanceMillimeters );
1287+
}
1288+
1289+
QgsProject::instance()->writeEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), defaultMapUnitsPerMm );
1290+
12601291
QgsProject::instance()->writeEntry( QStringLiteral( "WMTSUrl" ), QStringLiteral( "/" ), mWMTSUrlLineEdit->text() );
12611292
QgsProject::instance()->writeEntry( QStringLiteral( "WMTSMinScale" ), QStringLiteral( "/" ), mWMTSMinScaleLineEdit->value() );
12621293
bool wmtsProject = false;

‎src/app/qgsprojectproperties.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgis.h"
2323
#include "qgsunittypes.h"
2424
#include "qgsguiutils.h"
25+
#include "qgsscalewidget.h"
2526
#include "qgshelp.h"
2627
#include "qgis_app.h"
2728

@@ -188,6 +189,9 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
188189
QgsMetadataWidget *mMetadataWidget = nullptr;
189190
QgsLayerCapabilitiesModel *mLayerCapabilitiesModel = nullptr;
190191

192+
QDoubleSpinBox *mWMSDefaultMapUnitsPerMm = nullptr;
193+
QgsScaleWidget *mWMSDefaultMapUnitScale = nullptr;
194+
191195
QgsCoordinateReferenceSystem mCrs;
192196

193197
void checkPageWidgetNameMap();

‎src/server/qgsserverprojectutils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ int QgsServerProjectUtils::wmsImageQuality( const QgsProject &project )
111111
return project.readNumEntry( QStringLiteral( "WMSImageQuality" ), QStringLiteral( "/" ), -1 );
112112
}
113113

114+
double QgsServerProjectUtils::wmsDefaultMapUnitsPerMm( const QgsProject &project )
115+
{
116+
return project.readDoubleEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), 1 );
117+
}
118+
114119
bool QgsServerProjectUtils::wmsInfoFormatSia2045( const QgsProject &project )
115120
{
116121
QString sia2045 = project.readEntry( QStringLiteral( "WMSInfoFormatSIA2045" ), QStringLiteral( "/" ), "" );

‎src/server/qgsserverprojectutils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ namespace QgsServerProjectUtils
147147
*/
148148
SERVER_EXPORT int wmsImageQuality( const QgsProject &project );
149149

150+
/**
151+
* Returns the default number of map units per millimeters in case of the scale is not given
152+
* \param project the QGIS project
153+
* \returns the default number of map units per millimeter
154+
* \since QGIS 3.4
155+
*/
156+
SERVER_EXPORT double wmsDefaultMapUnitsPerMm( const QgsProject &project );
157+
150158
/**
151159
* Returns if layer ids are used as name in WMS.
152160
* \param project the QGIS project

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,20 @@ namespace QgsWms
193193
std::unique_ptr<QImage> image;
194194
std::unique_ptr<QPainter> painter;
195195

196-
// getting scale from bbox
196+
// getting scale from bbox or default size
197197
if ( !mWmsParameters.bbox().isEmpty() )
198198
{
199199
QgsMapSettings mapSettings;
200-
image.reset( createImage( width(), height(), false ) );
201-
configureMapSettings( image.get(), mapSettings );
200+
std::unique_ptr<QImage> tmp( createImage( width(), height(), false ) );
201+
configureMapSettings( tmp.get(), mapSettings );
202202
legendSettings.setMapScale( mapSettings.scale() );
203203
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
204204
}
205+
else
206+
{
207+
double defaultMapUnitsPerPixel = QgsServerProjectUtils::wmsDefaultMapUnitsPerMm( *mProject ) / dpmm;
208+
legendSettings.setMapUnitsPerPixel( defaultMapUnitsPerPixel );
209+
}
205210

206211
if ( !mWmsParameters.rule().isEmpty() )
207212
{

‎src/ui/qgsprojectpropertiesbase.ui

Lines changed: 277 additions & 235 deletions
Large diffs are not rendered by default.

‎tests/src/python/test_qgsserver_wms_getlegendgraphic.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,51 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Max(self):
665665
r, h = self._result(self._execute_request(qs))
666666
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ScaleSymbol_Max", max_size_diff=QSize(15, 15))
667667

668+
def test_wms_GetLegendGraphic_ScaleSymbol_DefaultMapUnitsPerMillimeter(self):
669+
# map units per mm on 1:20000000 with SRCHEIGHT=598&SRCWIDTH=1640&BBOX=16.5,-69.7,73.3,86.1 would be around what is set as default: 0.359 map units per mm
670+
qs = "?" + "&".join(["%s=%s" % i for i in list({
671+
"MAP": self.testdata_path + 'test_project_scaledsymbols.qgs',
672+
"SERVICE": "WMS",
673+
"REQUEST": "GetLegendGraphic",
674+
"LAYER": "testlayer",
675+
"FORMAT": "image/png",
676+
"CRS": "EPSG:4326"
677+
}.items())])
678+
679+
r, h = self._result(self._execute_request(qs))
680+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ScaleSymbol_DefaultMapUnitsPerMillimeter", max_size_diff=QSize(15, 15))
681+
682+
def test_wms_GetLegendGraphic_ScaleSymbol_Scaled_2056(self):
683+
# 1:1000 scale on an EPSG:2056 calculating DPI that is around 96
684+
qs = "?" + "&".join(["%s=%s" % i for i in list({
685+
"MAP": self.testdata_path + 'test_project_scaledsymbols_2056.qgs',
686+
"SERVICE": "WMS",
687+
"REQUEST": "GetLegendGraphic",
688+
"LAYER": "testlayer_2056",
689+
"FORMAT": "image/png",
690+
"SRCHEIGHT": "600",
691+
"SRCWIDTH": "1500",
692+
"BBOX": "2662610.7,1268841.8,2663010.5,1269000.05",
693+
"CRS": "EPSG:2056"
694+
}.items())])
695+
696+
r, h = self._result(self._execute_request(qs))
697+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ScaleSymbol_Scaled_2056", max_size_diff=QSize(15, 15))
698+
699+
def test_wms_GetLegendGraphic_ScaleSymbol_DefaultScale_2056(self):
700+
# 1:1000 as default value - it's not exactly the same result than passing the bbox and size because of exact DPI 96 (default)
701+
qs = "?" + "&".join(["%s=%s" % i for i in list({
702+
"MAP": self.testdata_path + 'test_project_scaledsymbols_2056.qgs',
703+
"SERVICE": "WMS",
704+
"REQUEST": "GetLegendGraphic",
705+
"LAYER": "testlayer_2056",
706+
"FORMAT": "image/png",
707+
"CRS": "EPSG:2056"
708+
}.items())])
709+
710+
r, h = self._result(self._execute_request(qs))
711+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ScaleSymbol_DefaultScale_2056", max_size_diff=QSize(15, 15))
712+
668713
def test_wms_GetLegendGraphic_LAYERFONTCOLOR(self):
669714
qs = "?" + "&".join(["%s=%s" % i for i in list({
670715
"MAP": urllib.parse.quote(self.projectPath),

‎tests/testdata/qgis_server/test_project_scaledsymbols.qgs

Lines changed: 211 additions & 206 deletions
Large diffs are not rendered by default.

‎tests/testdata/qgis_server/test_project_scaledsymbols_2056.qgs

Lines changed: 505 additions & 0 deletions
Large diffs are not rendered by default.
189 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PROJCS["CH1903+_LV95",GEOGCS["GCS_CH1903+",DATUM["D_CH1903+",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Hotine_Oblique_Mercator_Azimuth_Center"],PARAMETER["latitude_of_center",46.95240555555556],PARAMETER["longitude_of_center",7.439583333333333],PARAMETER["azimuth",90],PARAMETER["scale_factor",1],PARAMETER["false_easting",2600000],PARAMETER["false_northing",1200000],UNIT["Meter",1]]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PROJCS["CH1903+ / LV95",GEOGCS["CH1903+",DATUM["CH1903+",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[674.374,15.056,405.346,0,0,0,0],AUTHORITY["EPSG","6150"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4150"]],PROJECTION["Hotine_Oblique_Mercator_Azimuth_Center"],PARAMETER["latitude_of_center",46.95240555555556],PARAMETER["longitude_of_center",7.439583333333333],PARAMETER["azimuth",90],PARAMETER["rectified_grid_angle",90],PARAMETER["scale_factor",1],PARAMETER["false_easting",2600000],PARAMETER["false_northing",1200000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","2056"]]
128 Bytes
Binary file not shown.
108 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.