Skip to content

Commit 9fd65a2

Browse files
authoredJan 3, 2017
Merge pull request #3906 from rldhont/server-wms-stretch-compliancy
[BUGFIX][Server] WMS compliance: stretched, distort, increase, decrease
2 parents 47130a6 + 8475fc3 commit 9fd65a2

File tree

9 files changed

+31
-25
lines changed

9 files changed

+31
-25
lines changed
 

‎src/server/qgswmsserver.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,26 +1974,32 @@ QImage* QgsWmsServer::createImage( int width, int height, bool useBbox ) const
19741974

19751975
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
19761976
//Required by WMS spec. 1.3.
1977-
if ( useBbox )
1977+
QString version = mParameters.value( QStringLiteral( "VERSION" ), QStringLiteral( "1.3.0" ) );
1978+
if ( useBbox && version != QLatin1String( "1.1.1" ) )
19781979
{
19791980
bool bboxOk;
19801981
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
1982+
QString crs = mParameters.value( QStringLiteral( "CRS" ), mParameters.value( QStringLiteral( "SRS" ) ) );
1983+
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
1984+
{
1985+
crs = QString( "EPSG:4326" );
1986+
mapExtent.invert();
1987+
}
1988+
QgsCoordinateReferenceSystem outputCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crs );
1989+
if ( outputCRS.hasAxisInverted() )
1990+
{
1991+
mapExtent.invert();
1992+
}
19811993
if ( bboxOk )
19821994
{
19831995
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
19841996
double imageWidthHeightRatio = ( double )width / ( double )height;
19851997
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
19861998
{
1987-
if ( mapWidthHeightRatio >= imageWidthHeightRatio )
1988-
{
1989-
//increase image height
1990-
height = width * mapWidthHeightRatio;
1991-
}
1992-
else
1993-
{
1994-
//increase image width
1995-
width = height / mapWidthHeightRatio;
1996-
}
1999+
// inspired by MapServer, mapdraw.c L115
2000+
double cellsize = ( mapExtent.width() / ( double )width ) * 0.5 + ( mapExtent.height() / ( double )height ) * 0.5;
2001+
width = mapExtent.width() / cellsize;
2002+
height = mapExtent.height() / cellsize;
19972003
}
19982004
}
19992005
}

Error rendering embedded code

Invalid image source.

Error rendering embedded code

Invalid image source.

Error rendering embedded code

Invalid image source.

Error rendering embedded code

Invalid image source.

Error rendering embedded code

Invalid image source.

Error rendering embedded code

Invalid image source.

Error rendering embedded code

Invalid image source.

‎tests/testdata/qgis_server/ets-wms13/project.qgs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
<ymax>0.0022</ymax>
181181
</extent>
182182
<id>shapefile_Autos_any20161212175224004</id>
183-
<datasource>./shapefile|layername=Autos</datasource>
183+
<datasource>./shapefile/Autos.shp</datasource>
184184
<keywordList>
185185
<value></value>
186186
</keywordList>
@@ -456,7 +456,7 @@ def my_form_open(dialog, layer, feature):
456456
<ymax>6</ymax>
457457
</extent>
458458
<id>shapefile_BasicPolygons_any20161212175223962</id>
459-
<datasource>./shapefile|layername=BasicPolygons</datasource>
459+
<datasource>./shapefile/BasicPolygons.shp</datasource>
460460
<keywordList>
461461
<value></value>
462462
</keywordList>
@@ -720,7 +720,7 @@ def my_form_open(dialog, layer, feature):
720720
<ymax>0.0007</ymax>
721721
</extent>
722722
<id>shapefile_Bridges_any20161212175224135</id>
723-
<datasource>./shapefile|layername=Bridges</datasource>
723+
<datasource>./shapefile/Bridges.shp</datasource>
724724
<keywordList>
725725
<value></value>
726726
</keywordList>
@@ -993,7 +993,7 @@ def my_form_open(dialog, layer, feature):
993993
<ymax>0.0009</ymax>
994994
</extent>
995995
<id>shapefile_BuildingCenters_any20161212175224065</id>
996-
<datasource>./shapefile|layername=BuildingCenters</datasource>
996+
<datasource>./shapefile/BuildingCenters.shp</datasource>
997997
<keywordList>
998998
<value></value>
999999
</keywordList>
@@ -1266,7 +1266,7 @@ def my_form_open(dialog, layer, feature):
12661266
<ymax>0.001</ymax>
12671267
</extent>
12681268
<id>shapefile_Buildings_any20161212175224108</id>
1269-
<datasource>./shapefile|layername=Buildings</datasource>
1269+
<datasource>./shapefile/Buildings.shp</datasource>
12701270
<keywordList>
12711271
<value></value>
12721272
</keywordList>
@@ -1533,7 +1533,7 @@ def my_form_open(dialog, layer, feature):
15331533
<ymax>0.0024</ymax>
15341534
</extent>
15351535
<id>shapefile_DividedRoutes_any20161212175224115</id>
1536-
<datasource>./shapefile|layername=DividedRoutes</datasource>
1536+
<datasource>./shapefile/DividedRoutes.shp</datasource>
15371537
<keywordList>
15381538
<value></value>
15391539
</keywordList>
@@ -1807,7 +1807,7 @@ def my_form_open(dialog, layer, feature):
18071807
<ymax>0.0018</ymax>
18081808
</extent>
18091809
<id>shapefile_Forests_any20161212175224149</id>
1810-
<datasource>./shapefile|layername=Forests</datasource>
1810+
<datasource>./shapefile/Forests.shp</datasource>
18111811
<keywordList>
18121812
<value></value>
18131813
</keywordList>
@@ -2074,7 +2074,7 @@ def my_form_open(dialog, layer, feature):
20742074
<ymax>-0.0001</ymax>
20752075
</extent>
20762076
<id>shapefile_Lakes_any20161212175224157</id>
2077-
<datasource>./shapefile|layername=Lakes</datasource>
2077+
<datasource>./shapefile/Lakes.shp</datasource>
20782078
<keywordList>
20792079
<value></value>
20802080
</keywordList>
@@ -2341,7 +2341,7 @@ def my_form_open(dialog, layer, feature):
23412341
<ymax>0.0024</ymax>
23422342
</extent>
23432343
<id>shapefile_MapNeatline_any20161212175224085</id>
2344-
<datasource>./shapefile|layername=MapNeatline</datasource>
2344+
<datasource>./shapefile/MapNeatline.shp</datasource>
23452345
<keywordList>
23462346
<value></value>
23472347
</keywordList>
@@ -2609,7 +2609,7 @@ def my_form_open(dialog, layer, feature):
26092609
<ymax>0.0024</ymax>
26102610
</extent>
26112611
<id>shapefile_NamedPlaces_any20161212175224102</id>
2612-
<datasource>./shapefile|layername=NamedPlaces</datasource>
2612+
<datasource>./shapefile/NamedPlaces.shp</datasource>
26132613
<keywordList>
26142614
<value></value>
26152615
</keywordList>
@@ -2876,7 +2876,7 @@ def my_form_open(dialog, layer, feature):
28762876
<ymax>0.002</ymax>
28772877
</extent>
28782878
<id>shapefile_Ponds_any20161212175224054</id>
2879-
<datasource>./shapefile|layername=Ponds</datasource>
2879+
<datasource>./shapefile/Ponds.shp</datasource>
28802880
<keywordList>
28812881
<value></value>
28822882
</keywordList>
@@ -3146,7 +3146,7 @@ def my_form_open(dialog, layer, feature):
31463146
<ymax>0.0024</ymax>
31473147
</extent>
31483148
<id>shapefile_RoadSegments_any20161212175224127</id>
3149-
<datasource>./shapefile|layername=RoadSegments</datasource>
3149+
<datasource>./shapefile/RoadSegments.shp</datasource>
31503150
<keywordList>
31513151
<value></value>
31523152
</keywordList>
@@ -3417,7 +3417,7 @@ def my_form_open(dialog, layer, feature):
34173417
<ymax>0.0024</ymax>
34183418
</extent>
34193419
<id>shapefile_Streams_any20161212175223969</id>
3420-
<datasource>./shapefile|layername=Streams</datasource>
3420+
<datasource>./shapefile/Streams.shp</datasource>
34213421
<keywordList>
34223422
<value></value>
34233423
</keywordList>
@@ -3688,7 +3688,7 @@ def my_form_open(dialog, layer, feature):
36883688
<ymax>-0.0001</ymax>
36893689
</extent>
36903690
<id>shapefile_lakesWithElevation_any20161212175224039</id>
3691-
<datasource>./shapefile|layername=lakesWithElevation</datasource>
3691+
<datasource>./shapefile/lakesWithElevation.shp</datasource>
36923692
<keywordList>
36933693
<value></value>
36943694
</keywordList>

0 commit comments

Comments
 (0)
Please sign in to comment.