QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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
QgsTileXYZ
Definition: qgstiles.h:32
qgsrectangle.h
QgsTileRange
Definition: qgstiles.h:65
QgsRectangle
Definition: qgsrectangle.h:41
QgsTileMatrix::zoomLevel
int zoomLevel() const
Returns zoom level of the tile matrix.
Definition: qgstiles.h:110
QgsTileRange::endRow
int endRow() const
Returns index of the last row in the range.
Definition: qgstiles.h:82
QgsTileMatrix
Definition: qgstiles.h:102
QgsTileMatrix::matrixHeight
int matrixHeight() const
Returns number of rows of the tile matrix.
Definition: qgstiles.h:116
QgsTileMatrix::extent
QgsRectangle extent() const
Returns extent of the tile matrix.
Definition: qgstiles.h:119
qgis_sip.h
QgsTileRange::QgsTileRange
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
QgsTileRange::isValid
bool isValid() const
Returns whether the range is valid (when all row/column numbers are not negative)
Definition: qgstiles.h:73
QgsTileRange::endColumn
int endColumn() const
Returns index of the last column in the range.
Definition: qgstiles.h:78
QgsPointXY
Definition: qgspointxy.h:43
QgsTileRange::startRow
int startRow() const
Returns index of the first row in the range.
Definition: qgstiles.h:80
QgsTileMatrix::matrixWidth
int matrixWidth() const
Returns number of columns of the tile matrix.
Definition: qgstiles.h:113
QgsTileMatrix::scale
double scale() const
Returns scale denominator of the tile matrix.
Definition: qgstiles.h:122
QgsTileRange::startColumn
int startColumn() const
Returns index of the first column in the range.
Definition: qgstiles.h:76