QGIS API Documentation  3.21.0-Master (56b4176581)
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"
24 
33 class CORE_EXPORT QgsTileXYZ
34 {
35  public:
37  QgsTileXYZ( int tc = -1, int tr = -1, int tz = -1 )
38  : mColumn( tc ), mRow( tr ), mZoomLevel( tz )
39  {
40  }
41 
43  int column() const { return mColumn; }
45  int row() const { return mRow; }
47  int zoomLevel() const { return mZoomLevel; }
48 
50  QString toString() const { return QStringLiteral( "X=%1 Y=%2 Z=%3" ).arg( mColumn ).arg( mRow ).arg( mZoomLevel ); }
51 
52  private:
53  int mColumn;
54  int mRow;
55  int mZoomLevel;
56 };
57 
58 
66 class CORE_EXPORT QgsTileRange
67 {
68  public:
70  QgsTileRange( int c1 = -1, int c2 = -1, int r1 = -1, int r2 = -1 )
71  : mStartColumn( c1 ), mEndColumn( c2 ), mStartRow( r1 ), mEndRow( r2 ) {}
72 
74  bool isValid() const { return mStartColumn >= 0 && mEndColumn >= 0 && mStartRow >= 0 && mEndRow >= 0; }
75 
77  int startColumn() const { return mStartColumn; }
79  int endColumn() const { return mEndColumn; }
81  int startRow() const { return mStartRow; }
83  int endRow() const { return mEndRow; }
84 
85  private:
86  int mStartColumn;
87  int mEndColumn;
88  int mStartRow;
89  int mEndRow;
90 };
91 
92 
103 class CORE_EXPORT QgsTileMatrix
104 {
105  public:
106 
108  static QgsTileMatrix fromWebMercator( int zoomLevel );
109 
111  static QgsTileMatrix fromCustomDef( int zoomLevel, const QgsCoordinateReferenceSystem &crs,
112  const QgsPointXY &z0TopLeftPoint, double z0Dimension,
113  int z0MatrixWidth = 1, int z0MatrixHeight = 1 );
114 
116  static QgsTileMatrix fromTileMatrix( const int &zoomLevel, const QgsTileMatrix &tileMatrix );
117 
119  QgsCoordinateReferenceSystem crs() const { return mCrs; }
120 
122  int zoomLevel() const { return mZoomLevel; }
123 
125  int matrixWidth() const { return mMatrixWidth; }
126 
128  int matrixHeight() const { return mMatrixHeight; }
129 
131  QgsRectangle extent() const { return mExtent; }
132 
134  double scale() const { return mScaleDenom; }
135 
137  QgsRectangle tileExtent( QgsTileXYZ id ) const;
138 
140  QgsPointXY tileCenter( QgsTileXYZ id ) const;
141 
143  QgsTileRange tileRangeFromExtent( const QgsRectangle &mExtent );
144 
146  QPointF mapToTileCoordinates( const QgsPointXY &mapPoint ) const;
147 
149  bool isRootTileMatrix() const { return mZoomLevel == 0; }
150 
151  private:
155  int mZoomLevel = -1;
157  int mMatrixWidth;
159  int mMatrixHeight;
161  QgsRectangle mExtent;
163  double mScaleDenom;
165  double mTileXSpan;
167  double mTileYSpan;
168 };
169 
170 #endif // QGSTILES_H
This class represents a coordinate reference system (CRS).
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:104
QgsRectangle extent() const
Returns extent of the tile matrix.
Definition: qgstiles.h:131
int matrixWidth() const
Returns number of columns of the tile matrix.
Definition: qgstiles.h:125
QgsCoordinateReferenceSystem crs() const
Returns the authority identifier for the CRS of the tile matrix.
Definition: qgstiles.h:119
bool isRootTileMatrix() const
Returns the root status of the tile matrix (zoom level == 0)
Definition: qgstiles.h:149
double scale() const
Returns scale denominator of the tile matrix.
Definition: qgstiles.h:134
int matrixHeight() const
Returns number of rows of the tile matrix.
Definition: qgstiles.h:128
int zoomLevel() const
Returns zoom level of the tile matrix.
Definition: qgstiles.h:122
Range of tiles in a tile matrix to be rendered.
Definition: qgstiles.h:67
int endColumn() const
Returns index of the last column in the range.
Definition: qgstiles.h:79
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:70
int endRow() const
Returns index of the last row in the range.
Definition: qgstiles.h:83
int startRow() const
Returns index of the first row in the range.
Definition: qgstiles.h:81
int startColumn() const
Returns index of the first column in the range.
Definition: qgstiles.h:77
bool isValid() const
Returns whether the range is valid (when all row/column numbers are not negative)
Definition: qgstiles.h:74
Stores coordinates of a tile in a tile matrix set.
Definition: qgstiles.h:34
QString toString() const
Returns tile coordinates in a formatted string.
Definition: qgstiles.h:50
int zoomLevel() const
Returns tile's zoom level (Z)
Definition: qgstiles.h:47
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:37
int column() const
Returns tile's column index (X)
Definition: qgstiles.h:43
int row() const
Returns tile's row index (Y)
Definition: qgstiles.h:45
const QgsCoordinateReferenceSystem & crs