24 double z0xMin = -20037508.3427892, z0yMax = 20037508.3427892;
30 const QgsPointXY &z0TopLeftPoint,
double z0Dimension,
int z0MatrixWidth,
int z0MatrixHeight )
33 double z0xMin = z0TopLeftPoint.
x();
34 double z0yMax = z0TopLeftPoint.
y();
35 double z0xMax = z0xMin + z0MatrixWidth * z0Dimension;
36 double z0yMin = z0yMax - z0MatrixHeight * z0Dimension;
39 const double tileSize = 256.0;
40 const double PIXELS_TO_M = 2.8 / 10000.0;
43 double scaleDenom0 = ( z0Dimension / tileSize ) * ( UNIT_TO_M / PIXELS_TO_M );
45 int numTiles =
static_cast<int>( pow( 2,
zoomLevel ) );
50 tm.mMatrixWidth = z0MatrixWidth * numTiles;
51 tm.mMatrixHeight = z0MatrixHeight * numTiles;
52 tm.mTileXSpan = ( z0xMax - z0xMin ) / tm.mMatrixWidth;
53 tm.mTileYSpan = ( z0yMax - z0yMin ) / tm.mMatrixHeight;
54 tm.mExtent =
QgsRectangle( z0xMin, z0yMin, z0xMax, z0yMax );
55 tm.mScaleDenom = scaleDenom0 / pow( 2,
zoomLevel );
63 int numTiles =
static_cast<int>( pow( 2,
zoomLevel ) );
65 int aNumTiles =
static_cast<int>( pow( 2, aZoomLevel ) );
69 tm.mCrs = tileMatrix.
crs();
71 tm.mMatrixWidth = aMatrixWidth * numTiles / aNumTiles;
72 tm.mMatrixHeight = aMatrixHeight * numTiles / aNumTiles;
73 tm.mTileXSpan = aExtent.
width() / tm.mMatrixWidth;
74 tm.mTileYSpan = aExtent.
height() / tm.mMatrixHeight;
76 tm.mScaleDenom = tileMatrix.
scale() * pow( 2, aZoomLevel ) / pow( 2,
zoomLevel );
82 double xMin = mExtent.
xMinimum() + mTileXSpan *
id.column();
83 double xMax = xMin + mTileXSpan;
84 double yMax = mExtent.
yMaximum() - mTileYSpan *
id.row();
85 double yMin = yMax - mTileYSpan;
91 double x = mExtent.
xMinimum() + mTileXSpan *
id.column() + mTileXSpan / 2;
92 double y = mExtent.
yMaximum() - mTileYSpan *
id.row() - mTileYSpan / 2;
102 if ( x0 >= x1 || y0 >= y1 )
105 double tileX1 = ( x0 - mExtent.
xMinimum() ) / mTileXSpan;
106 double tileX2 = ( x1 - mExtent.
xMinimum() ) / mTileXSpan;
107 double tileY1 = ( mExtent.
yMaximum() - y1 ) / mTileYSpan;
108 double tileY2 = ( mExtent.
yMaximum() - y0 ) / mTileYSpan;
110 QgsDebugMsgLevel( QStringLiteral(
"Tile range of edges [%1,%2] - [%3,%4]" ).arg( tileX1 ).arg( tileY1 ).arg( tileX2 ).arg( tileY2 ), 2 );
113 int startColumn = std::clamp(
static_cast<int>( floor( tileX1 ) ), 0, mMatrixWidth - 1 );
114 int endColumn = std::clamp(
static_cast<int>( floor( tileX2 ) ), 0, mMatrixWidth - 1 );
115 int startRow = std::clamp(
static_cast<int>( floor( tileY1 ) ), 0, mMatrixHeight - 1 );
116 int endRow = std::clamp(
static_cast<int>( floor( tileY2 ) ), 0, mMatrixHeight - 1 );
117 return QgsTileRange( startColumn, endColumn, startRow, endRow );
122 double dx = mapPoint.
x() - mExtent.
xMinimum();
123 double dy = mExtent.
yMaximum() - mapPoint.
y();
124 return QPointF( dx / mTileXSpan, dy / mTileYSpan );
This class represents a coordinate reference system (CRS).
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
A class to represent a 2D point.
A rectangle specified with double values.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
QgsRectangle tileExtent(QgsTileXYZ id) const
Returns extent of the given tile in this matrix.
QPointF mapToTileCoordinates(const QgsPointXY &mapPoint) const
Returns row/column coordinates (floating point number) from the given point in map coordinates.
QgsTileRange tileRangeFromExtent(const QgsRectangle &mExtent)
Returns tile range that fully covers the given extent.
static QgsTileMatrix fromWebMercator(int zoomLevel)
Returns a tile matrix for the usual web mercator.
QgsRectangle extent() const
Returns extent of the tile matrix.
int matrixWidth() const
Returns number of columns of the tile matrix.
QgsCoordinateReferenceSystem crs() const
Returns the authority identifier for the CRS of the tile matrix.
double scale() const
Returns scale denominator of the tile matrix.
QgsPointXY tileCenter(QgsTileXYZ id) const
Returns center of the given tile in this matrix.
int matrixHeight() const
Returns number of rows of the tile matrix.
static QgsTileMatrix fromTileMatrix(const int &zoomLevel, const QgsTileMatrix &tileMatrix)
Returns a tile matrix based on another one.
int zoomLevel() const
Returns zoom level of the tile matrix.
static QgsTileMatrix fromCustomDef(int zoomLevel, const QgsCoordinateReferenceSystem &crs, const QgsPointXY &z0TopLeftPoint, double z0Dimension, int z0MatrixWidth=1, int z0MatrixHeight=1)
Returns a tile matrix for a specific CRS, top left point, zoom level 0 dimension in CRS units.
Range of tiles in a tile matrix to be rendered.
Stores coordinates of a tile in a tile matrix set.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
#define QgsDebugMsgLevel(str, level)
const QgsCoordinateReferenceSystem & crs