QGIS API Documentation 3.43.0-Master (b60ef06885e)
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 ), tileX2lon( last.x + 1, last.z ), tileY2lat( first.y, first.z ) );
76 }
77
78 QMap<QPair<int, int>, Tile> tiles;
79 int rows;
80 int cols;
81};
82QList<MetaTile> getMetatiles( const QgsRectangle extent, const int zoom, const int tileSize = 4 );
83
84
88class QgsXyzTilesBaseAlgorithm : public QgsProcessingAlgorithm
89{
90 public:
91 QString group() const override;
92 QString groupId() const override;
94
95 protected:
99 void createCommonParameters();
100
101 bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
102
103 void checkLayersUsagePolicy( QgsProcessingFeedback *feedback );
104
105 void startJobs();
106 virtual void processMetaTile( QgsMapRendererSequentialJob *job ) = 0;
107
108 QgsRectangle mExtent;
109 QColor mBackgroundColor;
110 int mMinZoom = 12;
111 int mMaxZoom = 12;
112 int mDpi = 96;
113 bool mAntialias = true;
114 int mJpgQuality = 75;
115 int mMetaTileSize = 4;
116 int mThreadsNumber = 1;
117 int mTileWidth = 256;
118 int mTileHeight = 256;
119 QString mTileFormat;
120 QList<QgsMapLayer *> mLayers;
122 QgsCoordinateReferenceSystem mMercatorCrs;
123 QgsCoordinateTransform mSrc2Wgs;
124 QgsCoordinateTransform mWgs2Mercator;
125 QgsRectangle mWgs84Extent;
126 QgsProcessingFeedback *mFeedback = nullptr;
127 long long mTotalTiles = 0;
128 long long mProcessedTiles = 0;
129 QgsCoordinateTransformContext mTransformContext;
130 QPointer<QEventLoop> mEventLoop;
131 QList<MetaTile> mMetaTiles;
132 QMap<QgsMapRendererSequentialJob *, MetaTile> mRendererJobs;
134};
135
136
140class QgsXyzTilesDirectoryAlgorithm : public QgsXyzTilesBaseAlgorithm
141{
142 public:
143 QgsXyzTilesDirectoryAlgorithm() = default;
144 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
145 QString name() const override;
146 QString displayName() const override;
147 QStringList tags() const override;
148 QString shortHelpString() const override;
149 QgsXyzTilesDirectoryAlgorithm *createInstance() const override SIP_FACTORY;
150
151 protected:
152 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
153
154 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
155
156 private:
157 bool mTms = false;
158 QString mOutputDir;
159};
160
164class QgsXyzTilesMbtilesAlgorithm : public QgsXyzTilesBaseAlgorithm
165{
166 public:
167 QgsXyzTilesMbtilesAlgorithm() = default;
168 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
169 QString name() const override;
170 QString displayName() const override;
171 QStringList tags() const override;
172 QString shortHelpString() const override;
173 QgsXyzTilesMbtilesAlgorithm *createInstance() const override SIP_FACTORY;
174
175 protected:
176 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
177
178 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
179
180 private:
181 std::unique_ptr<QgsMbTiles> mMbtilesWriter;
182};
183
185
186#endif // QGSALGORITHMXYZTILES_H
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3476
ScaleCalculationMethod
Scale calculation logic.
Definition qgis.h:5080
@ HorizontalMiddle
Calculate horizontally, across midle of map.
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Handles coordinate transforms between two 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