QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgstiles.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstiles.h
3 --------------------------------------
4 Date : March 2020
5 Copyright : (C) 2020 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSTILES_H
17#define QGSTILES_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21
22#include "qgis.h"
23#include "qgsrectangle.h"
25#include "qgsreadwritecontext.h"
26
28
37class CORE_EXPORT QgsTileXYZ
38{
39 public:
41 QgsTileXYZ( int tc = -1, int tr = -1, int tz = -1 )
42 : mColumn( tc ), mRow( tr ), mZoomLevel( tz )
43 {
44 }
45
47 int column() const { return mColumn; }
49 int row() const { return mRow; }
51 int zoomLevel() const { return mZoomLevel; }
52
54 QString toString() const { return QStringLiteral( "X=%1 Y=%2 Z=%3" ).arg( mColumn ).arg( mRow ).arg( mZoomLevel ); }
55
56 private:
57 int mColumn;
58 int mRow;
59 int mZoomLevel;
60};
61
62
70class CORE_EXPORT QgsTileRange
71{
72 public:
74 QgsTileRange( int c1 = -1, int c2 = -1, int r1 = -1, int r2 = -1 )
75 : mStartColumn( c1 ), mEndColumn( c2 ), mStartRow( r1 ), mEndRow( r2 ) {}
76
78 bool isValid() const { return mStartColumn >= 0 && mEndColumn >= 0 && mStartRow >= 0 && mEndRow >= 0; }
79
81 int startColumn() const { return mStartColumn; }
83 int endColumn() const { return mEndColumn; }
85 int startRow() const { return mStartRow; }
87 int endRow() const { return mEndRow; }
88
89 private:
90 int mStartColumn;
91 int mEndColumn;
92 int mStartRow;
93 int mEndRow;
94};
95
96
107class CORE_EXPORT QgsTileMatrix
108{
109 public:
110
112 static QgsTileMatrix fromWebMercator( int zoomLevel );
113
119 static QgsTileMatrix fromCustomDef( int zoomLevel, const QgsCoordinateReferenceSystem &crs,
120 const QgsPointXY &z0TopLeftPoint, double z0Dimension,
121 int z0MatrixWidth = 1, int z0MatrixHeight = 1 );
122
124 static QgsTileMatrix fromTileMatrix( int zoomLevel, const QgsTileMatrix &tileMatrix );
125
131 QgsCoordinateReferenceSystem crs() const { return mCrs; }
132
139 void setCrs( const QgsCoordinateReferenceSystem &crs ) { mCrs = crs;}
140
146 int zoomLevel() const { return mZoomLevel; }
147
154 void setZoomLevel( int level ) { mZoomLevel = level; }
155
157 int matrixWidth() const { return mMatrixWidth; }
158
160 int matrixHeight() const { return mMatrixHeight; }
161
163 QgsRectangle extent() const { return mExtent; }
164
170 double scale() const { return mScaleDenom; }
171
178 void setScale( double scale ) { mScaleDenom = scale; }
179
181 QgsRectangle tileExtent( QgsTileXYZ id ) const;
182
184 QgsPointXY tileCenter( QgsTileXYZ id ) const;
185
187 QgsTileRange tileRangeFromExtent( const QgsRectangle &mExtent ) const;
188
190 QPointF mapToTileCoordinates( const QgsPointXY &mapPoint ) const;
191
193 bool isRootTileMatrix() const { return mZoomLevel == 0; }
194
195 private:
199 int mZoomLevel = -1;
201 int mMatrixWidth;
203 int mMatrixHeight;
205 QgsRectangle mExtent;
207 double mScaleDenom;
209 double mTileXSpan;
211 double mTileYSpan;
212
213 friend class QgsTileMatrixSet;
214};
215
216
223class CORE_EXPORT QgsTileMatrixSet
224{
225
226 public:
227
228 virtual ~QgsTileMatrixSet() = default;
229
233 bool isEmpty() const;
234
238 void addGoogleCrs84QuadTiles( int minimumZoom = 0, int maximumZoom = 14 );
239
243 QgsTileMatrix tileMatrix( int zoom ) const;
244
250 QgsTileMatrix rootMatrix() const;
251
257 void setRootMatrix( const QgsTileMatrix &matrix );
258
264 void addMatrix( const QgsTileMatrix &matrix );
265
271 int minimumZoom() const;
272
278 int maximumZoom() const;
279
284 void dropMatricesOutsideZoomRange( int minimumZoom, int maximumZoom );
285
293
299 double scaleToZoom( double scale ) const;
300
306 int scaleToZoomLevel( double scale ) const;
307
313 double scaleForRenderContext( const QgsRenderContext &context ) const;
314
320 double calculateTileScaleForMap( double actualMapScale,
321 const QgsCoordinateReferenceSystem &mapCrs,
322 const QgsRectangle &mapExtent,
323 const QSize mapSize,
324 const double mapDpi
325 ) const;
326
332 virtual bool readXml( const QDomElement &element, QgsReadWriteContext &context );
333
337 virtual QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const;
338
344 Qgis::ScaleToTileZoomLevelMethod scaleToTileZoomMethod() const { return mScaleToTileZoomMethod; }
345
351 void setScaleToTileZoomMethod( Qgis::ScaleToTileZoomLevelMethod method ) { mScaleToTileZoomMethod = method; }
352
353 private:
354
355 // Usually corresponds to zoom level 0, even if that zoom level is NOT present in the actual tile matrices for this set
356 QgsTileMatrix mRootMatrix;
357 QMap< int, QgsTileMatrix > mTileMatrices;
359};
360
361#endif // QGSTILES_H
ScaleToTileZoomLevelMethod
Available methods for converting map scales to tile zoom levels.
Definition: qgis.h:1793
@ MapBox
Uses a scale doubling approach to account for hi-DPI tiles, and rounds to the nearest tile level for ...
This class represents a coordinate reference system (CRS).
A class to represent a 2D point.
Definition: qgspointxy.h:59
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Contains information about the context of a rendering operation.
Defines a set of tile matrices for multiple zoom levels.
Definition: qgstiles.h:224
virtual ~QgsTileMatrixSet()=default
Qgis::ScaleToTileZoomLevelMethod scaleToTileZoomMethod() const
Returns the scale to tile zoom method.
Definition: qgstiles.h:344
void setScaleToTileZoomMethod(Qgis::ScaleToTileZoomLevelMethod method)
Sets the scale to tile zoom method.
Definition: qgstiles.h:351
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
Definition: qgstiles.h:108
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the crs of the tile matrix.
Definition: qgstiles.h:139
void setScale(double scale)
Sets the scale denominator of the tile matrix.
Definition: qgstiles.h:178
QgsRectangle extent() const
Returns extent of the tile matrix.
Definition: qgstiles.h:163
int matrixWidth() const
Returns number of columns of the tile matrix.
Definition: qgstiles.h:157
QgsCoordinateReferenceSystem crs() const
Returns the crs of the tile matrix.
Definition: qgstiles.h:131
bool isRootTileMatrix() const
Returns the root status of the tile matrix (zoom level == 0)
Definition: qgstiles.h:193
double scale() const
Returns scale denominator of the tile matrix.
Definition: qgstiles.h:170
void setZoomLevel(int level)
Sets the zoom level of the tile matrix.
Definition: qgstiles.h:154
int matrixHeight() const
Returns number of rows of the tile matrix.
Definition: qgstiles.h:160
int zoomLevel() const
Returns the zoom level of the tile matrix.
Definition: qgstiles.h:146
Range of tiles in a tile matrix to be rendered.
Definition: qgstiles.h:71
int endColumn() const
Returns index of the last column in the range.
Definition: qgstiles.h:83
QgsTileRange(int c1=-1, int c2=-1, int r1=-1, int r2=-1)
Constructs a range of tiles from given span of columns and rows.
Definition: qgstiles.h:74
int endRow() const
Returns index of the last row in the range.
Definition: qgstiles.h:87
int startRow() const
Returns index of the first row in the range.
Definition: qgstiles.h:85
int startColumn() const
Returns index of the first column in the range.
Definition: qgstiles.h:81
bool isValid() const
Returns whether the range is valid (when all row/column numbers are not negative)
Definition: qgstiles.h:78
Stores coordinates of a tile in a tile matrix set.
Definition: qgstiles.h:38
QString toString() const
Returns tile coordinates in a formatted string.
Definition: qgstiles.h:54
int zoomLevel() const
Returns tile's zoom level (Z)
Definition: qgstiles.h:51
QgsTileXYZ(int tc=-1, int tr=-1, int tz=-1)
Constructs a tile identifier from given column, row and zoom level indices.
Definition: qgstiles.h:41
int column() const
Returns tile's column index (X)
Definition: qgstiles.h:47
int row() const
Returns tile's row index (Y)
Definition: qgstiles.h:49
const QgsCoordinateReferenceSystem & crs