Skip to content

Commit

Permalink
[Bugfix][Server] WMTS - use resolution for bbox calculation
Browse files Browse the repository at this point in the history
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 25, 2019
1 parent 2d67f3f commit 202a479
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/server/services/wmts/qgswmtsutils.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ namespace QgsWmts
double top = ( extent.yMinimum() + ( extent.yMaximum() - extent.yMinimum() ) / 2.0 ) + ( row / 2.0 ) * ( tileSize * res ); double top = ( extent.yMinimum() + ( extent.yMaximum() - extent.yMinimum() ) / 2.0 ) + ( row / 2.0 ) * ( tileSize * res );
tmi.extent = QgsRectangle( left, bottom, right, top ); tmi.extent = QgsRectangle( left, bottom, right, top );


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


tileMatrixInfoMap[crsStr] = tmi; tileMatrixInfoMap[crsStr] = tmi;
Expand All @@ -152,8 +153,7 @@ namespace QgsWmts
QgsUnitTypes::DistanceUnit unit = tmi.unit; QgsUnitTypes::DistanceUnit unit = tmi.unit;


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


Expand Down Expand Up @@ -691,17 +691,23 @@ namespace QgsWmts


// Tile matrix information // Tile matrix information
// to build tile matrix set like Google Mercator or TMS // 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; tileMatrixInfo tmi3857;
tmi3857.ref = QStringLiteral( "EPSG:3857" ); tmi3857.ref = QStringLiteral( "EPSG:3857" );
tmi3857.extent = QgsRectangle( -20037508.3427892480, -20037508.3427892480, 20037508.3427892480, 20037508.3427892480 ); tmi3857.extent = QgsRectangle( -20037508.3427892480, -20037508.3427892480, 20037508.3427892480, 20037508.3427892480 );
tmi3857.resolution = 156543.0339280410;
tmi3857.scaleDenominator = 559082264.0287179; tmi3857.scaleDenominator = 559082264.0287179;
tmi3857.unit = QgsUnitTypes::DistanceMeters; tmi3857.unit = QgsUnitTypes::DistanceMeters;
m[tmi3857.ref] = tmi3857; 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; tileMatrixInfo tmi4326;
tmi4326.ref = QStringLiteral( "EPSG:4326" ); tmi4326.ref = QStringLiteral( "EPSG:4326" );
tmi4326.extent = QgsRectangle( -180, -90, 180, 90 ); tmi4326.extent = QgsRectangle( -180, -90, 180, 90 );
tmi4326.resolution = 0.703125000000000;
tmi4326.scaleDenominator = 279541132.0143588675418869; tmi4326.scaleDenominator = 279541132.0143588675418869;
tmi4326.unit = QgsUnitTypes::DistanceDegrees; tmi4326.unit = QgsUnitTypes::DistanceDegrees;
tmi4326.hasAxisInverted = true; tmi4326.hasAxisInverted = true;
Expand Down
2 changes: 2 additions & 0 deletions src/server/services/wmts/qgswmtsutils.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace QgsWmts


bool hasAxisInverted = false; bool hasAxisInverted = false;


double resolution = 0.0;

double scaleDenominator = 0.0; double scaleDenominator = 0.0;
}; };


Expand Down

0 comments on commit 202a479

Please sign in to comment.