QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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 checkLayersUsagePolicy( QgsProcessingFeedback *feedback );
108
109 void startJobs();
110 virtual void processMetaTile( QgsMapRendererSequentialJob *job ) = 0;
111
112 QgsRectangle mExtent;
113 QColor mBackgroundColor;
114 int mMinZoom = 12;
115 int mMaxZoom = 12;
116 int mDpi = 96;
117 bool mAntialias = true;
118 int mJpgQuality = 75;
119 int mMetaTileSize = 4;
120 int mThreadsNumber = 1;
121 int mTileWidth = 256;
122 int mTileHeight = 256;
123 QString mTileFormat;
124 QList< QgsMapLayer * > mLayers;
126 QgsCoordinateReferenceSystem mMercatorCrs;
127 QgsCoordinateTransform mSrc2Wgs;
128 QgsCoordinateTransform mWgs2Mercator;
129 QgsRectangle mWgs84Extent;
130 QgsProcessingFeedback *mFeedback = nullptr;
131 long long mTotalTiles = 0;
132 long long mProcessedTiles = 0;
133 QgsCoordinateTransformContext mTransformContext;
134 QPointer<QEventLoop> mEventLoop;
135 QList< MetaTile > mMetaTiles;
136 QMap< QgsMapRendererSequentialJob *, MetaTile > mRendererJobs;
137};
138
139
143class QgsXyzTilesDirectoryAlgorithm : public QgsXyzTilesBaseAlgorithm
144{
145
146 public:
147
148 QgsXyzTilesDirectoryAlgorithm() = default;
149 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
150 QString name() const override;
151 QString displayName() const override;
152 QStringList tags() const override;
153 QString shortHelpString() const override;
154 QgsXyzTilesDirectoryAlgorithm *createInstance() const override SIP_FACTORY;
155
156 protected:
157 QVariantMap processAlgorithm( const QVariantMap &parameters,
158 QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
159
160 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
161
162 private:
163 bool mTms = false;
164 QString mOutputDir;
165
166};
167
171class QgsXyzTilesMbtilesAlgorithm : public QgsXyzTilesBaseAlgorithm
172{
173
174 public:
175
176 QgsXyzTilesMbtilesAlgorithm() = default;
177 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
178 QString name() const override;
179 QString displayName() const override;
180 QStringList tags() const override;
181 QString shortHelpString() const override;
182 QgsXyzTilesMbtilesAlgorithm *createInstance() const override SIP_FACTORY;
183
184 protected:
185 QVariantMap processAlgorithm( const QVariantMap &parameters,
186 QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
187
188 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
189
190 private:
191 std::unique_ptr<QgsMbTiles> mMbtilesWriter;
192
193};
194
196
197#endif // QGSALGORITHMXYZTILES_H
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3347
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.
#define SIP_FACTORY
Definition qgis_sip.h:76