Skip to content
Permalink
Browse files

[Bugfix][Server] WMTS - use resolution for bbox calculation

Because of the limit of double size in C++, it's bettre to use the resolution instead of the scale denominator for calculating tiles extent.
  • Loading branch information
rldhont committed Apr 19, 2019
1 parent 9637753 commit 25426e6a30de570d92e1e1c1a0c6e2eb541eb0b1
Showing with 12 additions and 4 deletions.
  1. +10 −4 src/server/services/wmts/qgswmtsutils.cpp
  2. +2 −0 src/server/services/wmts/qgswmtsutils.h
@@ -140,6 +140,7 @@ namespace QgsWmts
double top = ( extent.yMinimum() + ( extent.yMaximum() - extent.yMinimum() ) / 2.0 ) + ( row / 2.0 ) * ( tileSize * res );
tmi.extent = QgsRectangle( left, bottom, right, top );

tmi.resolution = res;
tmi.scaleDenominator = scaleDenominator;

calculatedTileMatrixInfoMap[crsStr] = tmi;
@@ -155,8 +156,7 @@ namespace QgsWmts
QgsUnitTypes::DistanceUnit unit = tmi.unit;

// constant
double UNIT_TO_M = QgsUnitTypes::fromUnitToUnitFactor( tmi.unit, QgsUnitTypes::DistanceMeters );
double resolution = POINTS_TO_M * scaleDenominator / UNIT_TO_M;
double resolution = tmi.resolution;
int column = std::ceil( ( extent.xMaximum() - extent.xMinimum() ) / ( tileSize * resolution ) );
int row = std::ceil( ( extent.yMaximum() - extent.yMinimum() ) / ( tileSize * resolution ) );

@@ -263,7 +263,7 @@ namespace QgsWmts
{
tmi = fixedTileMatrixInfoMap[crsStr];
// Calculate resolution based on scale denominator
resolution = POINTS_TO_M * tmi.scaleDenominator / QgsUnitTypes::fromUnitToUnitFactor( tmi.unit, QgsUnitTypes::DistanceMeters );
resolution = tmi.resolution;
// Get fixed corner
QgsRectangle extent = tmi.extent;
fixedTop = extent.yMaximum();
@@ -805,17 +805,23 @@ namespace QgsWmts

// Tile matrix information
// to build tile matrix set like Google Mercator or TMS
// some references for resolution
// https://github.com/mapserver/mapcache/blob/master/lib/configuration.c#L94
tileMatrixInfo tmi3857;
tmi3857.ref = QStringLiteral( "EPSG:3857" );
tmi3857.extent = QgsRectangle( -20037508.3427892480, -20037508.3427892480, 20037508.3427892480, 20037508.3427892480 );
tmi3857.resolution = 156543.0339280410;
tmi3857.scaleDenominator = 559082264.0287179;
tmi3857.unit = QgsUnitTypes::DistanceMeters;
m[tmi3857.ref] = tmi3857;


// To build tile matrix set like mapcache for WGS84
// some references for resolution
// https://github.com/mapserver/mapcache/blob/master/lib/configuration.c#L73
tileMatrixInfo tmi4326;
tmi4326.ref = QStringLiteral( "EPSG:4326" );
tmi4326.extent = QgsRectangle( -180, -90, 180, 90 );
tmi4326.resolution = 0.703125000000000;
tmi4326.scaleDenominator = 279541132.0143588675418869;
tmi4326.unit = QgsUnitTypes::DistanceDegrees;
tmi4326.hasAxisInverted = true;
@@ -45,6 +45,8 @@ namespace QgsWmts

bool hasAxisInverted = false;

double resolution = 0.0;

double scaleDenominator = 0.0;

int lastLevel = -1;

0 comments on commit 25426e6

Please sign in to comment.
You can’t perform that action at this time.