QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsalgorithmxyztiles.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmxyztiles.h
3 ---------------------
4 begin : August 2023
5 copyright : (C) 2023 by Alexander Bruy
6 email : alexander dot bruy at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSALGORITHMXYZTILES_H
19#define QGSALGORITHMXYZTILES_H
20
21#define SIP_NO_FILE
22
23#include "qgis_sip.h"
25
27#include "qgsmbtiles.h"
28
30
31int tile2tms( const int y, const int zoom );
32int lon2tileX( const double lon, const int z );
33int lat2tileY( const double lat, const int z );
34double tileX2lon( const int x, const int z );
35double tileY2lat( const int y, const int z );
36void extent2TileXY( const QgsRectangle extent, const int zoom, int &xMin, int &yMin, int &xMax, int &yMax );
37
38struct Tile
39{
40 Tile( const int x, const int y, const int z )
41 : x( x )
42 , y( y )
43 , z( z )
44 {}
45
46 int x;
47 int y;
48 int z;
49};
50
51struct MetaTile
52{
53 MetaTile()
54 : rows( 0 )
55 , cols( 0 )
56 {}
57
58 void addTile( const int row, const int col, Tile tileToAdd )
59 {
60 tiles.insert( QPair<int, int>( row, col ), tileToAdd );
61 if ( row >= rows )
62 {
63 rows = row + 1;
64 }
65 if ( col >= cols )
66 {
67 cols = col + 1;
68 }
69 }
70
71 QgsRectangle extent()
72 {
73 const Tile first = tiles.first();
74 const Tile last = tiles.last();
75 return QgsRectangle( tileX2lon( first.x, first.z ), tileY2lat( last.y + 1, last.z ),
76 tileX2lon( last.x + 1, last.z ), tileY2lat( first.y, first.z ) );
77 }
78
79 QMap< QPair<int, int>, Tile > tiles;
80 int rows;
81 int cols;
82};
83QList< MetaTile > getMetatiles( const QgsRectangle extent, const int zoom, const int tileSize = 4 );
84
85
89class QgsXyzTilesBaseAlgorithm : public QgsProcessingAlgorithm
90{
91
92 public:
93
94 QString group() const override;
95 QString groupId() const override;
97
98 protected:
99
103 void createCommonParameters();
104
105 bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
106
107 void startJobs();
108 virtual void processMetaTile( QgsMapRendererSequentialJob *job ) = 0;
109
110 QgsRectangle mExtent;
111 QColor mBackgroundColor;
112 int mMinZoom = 12;
113 int mMaxZoom = 12;
114 int mDpi = 96;
115 bool mAntialias = true;
116 int mJpgQuality = 75;
117 int mMetaTileSize = 4;
118 int mThreadsNumber = 1;
119 int mTileWidth = 256;
120 int mTileHeight = 256;
121 QString mTileFormat;
122 QList< QgsMapLayer * > mLayers;
124 QgsCoordinateReferenceSystem mMercatorCrs;
125 QgsCoordinateTransform mSrc2Wgs;
126 QgsCoordinateTransform mWgs2Mercator;
127 QgsRectangle mWgs84Extent;
128 QgsProcessingFeedback *mFeedback;
129 long long mTotalTiles = 0;
130 long long mProcessedTiles = 0;
131 QgsCoordinateTransformContext mTransformContext;
132 QEventLoop *mEventLoop;
133 QList< MetaTile > mMetaTiles;
134 QMap< QgsMapRendererSequentialJob *, MetaTile > mRendererJobs;
135};
136
137
141class QgsXyzTilesDirectoryAlgorithm : public QgsXyzTilesBaseAlgorithm
142{
143
144 public:
145
146 QgsXyzTilesDirectoryAlgorithm() = default;
147 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
148 QString name() const override;
149 QString displayName() const override;
150 QStringList tags() const override;
151 QString shortHelpString() const override;
152 QgsXyzTilesDirectoryAlgorithm *createInstance() const override SIP_FACTORY;
153
154 protected:
155 QVariantMap processAlgorithm( const QVariantMap &parameters,
156 QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
157
158 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
159
160 private:
161 bool mTms;
162 QString mOutputDir;
163
164};
165
169class QgsXyzTilesMbtilesAlgorithm : public QgsXyzTilesBaseAlgorithm
170{
171
172 public:
173
174 QgsXyzTilesMbtilesAlgorithm() = default;
175 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
176 QString name() const override;
177 QString displayName() const override;
178 QStringList tags() const override;
179 QString shortHelpString() const override;
180 QgsXyzTilesMbtilesAlgorithm *createInstance() const override SIP_FACTORY;
181
182 protected:
183 QVariantMap processAlgorithm( const QVariantMap &parameters,
184 QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
185
186 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
187
188 private:
189 std::unique_ptr<QgsMbTiles> mMbtilesWriter;
190
191};
192
194
195#endif // QGSALGORITHMXYZTILES_H
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition: qgis.h:2934
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Class for doing transforms between two map coordinate systems.
Job implementation that renders everything sequentially in one thread.
Utility class for reading and writing MBTiles files (which are SQLite3 databases).
Definition: qgsmbtiles.h:39
Abstract base class for processing algorithms.
virtual QString group() const
Returns the name of the group this algorithm belongs to.
virtual bool prepareAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm to run using the specified parameters.
virtual QString groupId() const
Returns the unique ID of the group this algorithm belongs to.
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:73
#define SIP_FACTORY
Definition: qgis_sip.h:76