QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 "qgsrectangle.h"
23 
32 class CORE_EXPORT QgsTileXYZ
33 {
34  public:
36  QgsTileXYZ( int tc = -1, int tr = -1, int tz = -1 )
37  : mColumn( tc ), mRow( tr ), mZoomLevel( tz )
38  {
39  }
40 
42  int column() const { return mColumn; }
44  int row() const { return mRow; }
46  int zoomLevel() const { return mZoomLevel; }
47 
49  QString toString() const { return QStringLiteral( "X=%1 Y=%2 Z=%3" ).arg( mColumn ).arg( mRow ).arg( mZoomLevel ); }
50 
51  private:
52  int mColumn;
53  int mRow;
54  int mZoomLevel;
55 };
56 
57 
65 class CORE_EXPORT QgsTileRange
66 {
67  public:
69  QgsTileRange( int c1 = -1, int c2 = -1, int r1 = -1, int r2 = -1 )
70  : mStartColumn( c1 ), mEndColumn( c2 ), mStartRow( r1 ), mEndRow( r2 ) {}
71 
73  bool isValid() const { return mStartColumn >= 0 && mEndColumn >= 0 && mStartRow >= 0 && mEndRow >= 0; }
74 
76  int startColumn() const { return mStartColumn; }
78  int endColumn() const { return mEndColumn; }
80  int startRow() const { return mStartRow; }
82  int endRow() const { return mEndRow; }
83 
84  private:
85  int mStartColumn;
86  int mEndColumn;
87  int mStartRow;
88  int mEndRow;
89 };
90 
91 
102 class CORE_EXPORT QgsTileMatrix
103 {
104  public:
105 
107  static QgsTileMatrix fromWebMercator( int mZoomLevel );
108 
110  int zoomLevel() const { return mZoomLevel; }
111 
113  int matrixWidth() const { return mMatrixWidth; }
114 
116  int matrixHeight() const { return mMatrixHeight; }
117 
119  QgsRectangle extent() const { return mExtent; }
120 
122  double scale() const { return mScaleDenom; }
123 
125  QgsRectangle tileExtent( QgsTileXYZ id ) const;
126 
128  QgsPointXY tileCenter( QgsTileXYZ id ) const;
129 
131  QgsTileRange tileRangeFromExtent( const QgsRectangle &mExtent );
132 
134  QPointF mapToTileCoordinates( const QgsPointXY &mapPoint ) const;
135 
136  private:
138  int mZoomLevel;
140  int mMatrixWidth;
142  int mMatrixHeight;
144  QgsRectangle mExtent;
146  double mScaleDenom;
148  double mTileXSpan;
150  double mTileYSpan;
151 };
152 
153 #endif // QGSTILES_H
A class to represent a 2D point.
Definition: qgspointxy.h:59
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
Definition: qgstiles.h:103
QgsRectangle extent() const
Returns extent of the tile matrix.
Definition: qgstiles.h:119
int matrixWidth() const
Returns number of columns of the tile matrix.
Definition: qgstiles.h:113
double scale() const
Returns scale denominator of the tile matrix.
Definition: qgstiles.h:122
int matrixHeight() const
Returns number of rows of the tile matrix.
Definition: qgstiles.h:116
int zoomLevel() const
Returns zoom level of the tile matrix.
Definition: qgstiles.h:110
Range of tiles in a tile matrix to be rendered.
Definition: qgstiles.h:66
int endColumn() const
Returns index of the last column in the range.
Definition: qgstiles.h:78
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:69
int endRow() const
Returns index of the last row in the range.
Definition: qgstiles.h:82
int startRow() const
Returns index of the first row in the range.
Definition: qgstiles.h:80
int startColumn() const
Returns index of the first column in the range.
Definition: qgstiles.h:76
bool isValid() const
Returns whether the range is valid (when all row/column numbers are not negative)
Definition: qgstiles.h:73
Stores coordinates of a tile in a tile matrix set.
Definition: qgstiles.h:33
QString toString() const
Returns tile coordinates in a formatted string.
Definition: qgstiles.h:49
int zoomLevel() const
Returns tile's zoom level (Z)
Definition: qgstiles.h:46
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:36
int column() const
Returns tile's column index (X)
Definition: qgstiles.h:42
int row() const
Returns tile's row index (Y)
Definition: qgstiles.h:44