Skip to content

Commit

Permalink
Merge pull request #3906 from rldhont/server-wms-stretch-compliancy
Browse files Browse the repository at this point in the history
[BUGFIX][Server] WMS compliance: stretched, distort, increase, decrease
  • Loading branch information
rldhont authored Jan 3, 2017
2 parents 47130a6 + 8475fc3 commit 9fd65a2
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 25 deletions.
28 changes: 17 additions & 11 deletions src/server/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1974,26 +1974,32 @@ QImage* QgsWmsServer::createImage( int width, int height, bool useBbox ) const

//Adapt width / height if the aspect ratio does not correspond with the BBOX.
//Required by WMS spec. 1.3.
if ( useBbox )
QString version = mParameters.value( QStringLiteral( "VERSION" ), QStringLiteral( "1.3.0" ) );
if ( useBbox && version != QLatin1String( "1.1.1" ) )
{
bool bboxOk;
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
QString crs = mParameters.value( QStringLiteral( "CRS" ), mParameters.value( QStringLiteral( "SRS" ) ) );
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
{
crs = QString( "EPSG:4326" );
mapExtent.invert();
}
QgsCoordinateReferenceSystem outputCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crs );
if ( outputCRS.hasAxisInverted() )
{
mapExtent.invert();
}
if ( bboxOk )
{
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
double imageWidthHeightRatio = ( double )width / ( double )height;
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
{
if ( mapWidthHeightRatio >= imageWidthHeightRatio )
{
//increase image height
height = width * mapWidthHeightRatio;
}
else
{
//increase image width
width = height / mapWidthHeightRatio;
}
// inspired by MapServer, mapdraw.c L115
double cellsize = ( mapExtent.width() / ( double )width ) * 0.5 + ( mapExtent.height() / ( double )height ) * 0.5;
width = mapExtent.width() / cellsize;
height = mapExtent.height() / cellsize;
}
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions tests/testdata/qgis_server/ets-wms13/project.qgs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<ymax>0.0022</ymax>
</extent>
<id>shapefile_Autos_any20161212175224004</id>
<datasource>./shapefile|layername=Autos</datasource>
<datasource>./shapefile/Autos.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -456,7 +456,7 @@ def my_form_open(dialog, layer, feature):
<ymax>6</ymax>
</extent>
<id>shapefile_BasicPolygons_any20161212175223962</id>
<datasource>./shapefile|layername=BasicPolygons</datasource>
<datasource>./shapefile/BasicPolygons.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -720,7 +720,7 @@ def my_form_open(dialog, layer, feature):
<ymax>0.0007</ymax>
</extent>
<id>shapefile_Bridges_any20161212175224135</id>
<datasource>./shapefile|layername=Bridges</datasource>
<datasource>./shapefile/Bridges.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -993,7 +993,7 @@ def my_form_open(dialog, layer, feature):
<ymax>0.0009</ymax>
</extent>
<id>shapefile_BuildingCenters_any20161212175224065</id>
<datasource>./shapefile|layername=BuildingCenters</datasource>
<datasource>./shapefile/BuildingCenters.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -1266,7 +1266,7 @@ def my_form_open(dialog, layer, feature):
<ymax>0.001</ymax>
</extent>
<id>shapefile_Buildings_any20161212175224108</id>
<datasource>./shapefile|layername=Buildings</datasource>
<datasource>./shapefile/Buildings.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -1533,7 +1533,7 @@ def my_form_open(dialog, layer, feature):
<ymax>0.0024</ymax>
</extent>
<id>shapefile_DividedRoutes_any20161212175224115</id>
<datasource>./shapefile|layername=DividedRoutes</datasource>
<datasource>./shapefile/DividedRoutes.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -1807,7 +1807,7 @@ def my_form_open(dialog, layer, feature):
<ymax>0.0018</ymax>
</extent>
<id>shapefile_Forests_any20161212175224149</id>
<datasource>./shapefile|layername=Forests</datasource>
<datasource>./shapefile/Forests.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -2074,7 +2074,7 @@ def my_form_open(dialog, layer, feature):
<ymax>-0.0001</ymax>
</extent>
<id>shapefile_Lakes_any20161212175224157</id>
<datasource>./shapefile|layername=Lakes</datasource>
<datasource>./shapefile/Lakes.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -2341,7 +2341,7 @@ def my_form_open(dialog, layer, feature):
<ymax>0.0024</ymax>
</extent>
<id>shapefile_MapNeatline_any20161212175224085</id>
<datasource>./shapefile|layername=MapNeatline</datasource>
<datasource>./shapefile/MapNeatline.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -2609,7 +2609,7 @@ def my_form_open(dialog, layer, feature):
<ymax>0.0024</ymax>
</extent>
<id>shapefile_NamedPlaces_any20161212175224102</id>
<datasource>./shapefile|layername=NamedPlaces</datasource>
<datasource>./shapefile/NamedPlaces.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -2876,7 +2876,7 @@ def my_form_open(dialog, layer, feature):
<ymax>0.002</ymax>
</extent>
<id>shapefile_Ponds_any20161212175224054</id>
<datasource>./shapefile|layername=Ponds</datasource>
<datasource>./shapefile/Ponds.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -3146,7 +3146,7 @@ def my_form_open(dialog, layer, feature):
<ymax>0.0024</ymax>
</extent>
<id>shapefile_RoadSegments_any20161212175224127</id>
<datasource>./shapefile|layername=RoadSegments</datasource>
<datasource>./shapefile/RoadSegments.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -3417,7 +3417,7 @@ def my_form_open(dialog, layer, feature):
<ymax>0.0024</ymax>
</extent>
<id>shapefile_Streams_any20161212175223969</id>
<datasource>./shapefile|layername=Streams</datasource>
<datasource>./shapefile/Streams.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down Expand Up @@ -3688,7 +3688,7 @@ def my_form_open(dialog, layer, feature):
<ymax>-0.0001</ymax>
</extent>
<id>shapefile_lakesWithElevation_any20161212175224039</id>
<datasource>./shapefile|layername=lakesWithElevation</datasource>
<datasource>./shapefile/lakesWithElevation.shp</datasource>
<keywordList>
<value></value>
</keywordList>
Expand Down

0 comments on commit 9fd65a2

Please sign in to comment.