QGIS API Documentation 3.99.0-Master (c22de0620c0)
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
22#include "qgis_sip.h"
24#include "qgsmbtiles.h"
26
27#define SIP_NO_FILE
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 {}
55
56 void addTile( const int row, const int col, Tile tileToAdd )
57 {
58 tiles.insert( QPair<int, int>( row, col ), tileToAdd );
59 if ( row >= rows )
60 {
61 rows = row + 1;
62 }
63 if ( col >= cols )
64 {
65 cols = col + 1;
66 }
67 }
68
69 QgsRectangle extent()
70 {
71 const Tile first = tiles.first();
72 const Tile last = tiles.last();
73 return QgsRectangle( tileX2lon( first.x, first.z ), tileY2lat( last.y + 1, last.z ), tileX2lon( last.x + 1, last.z ), tileY2lat( first.y, first.z ) );
74 }
75
76 QMap<QPair<int, int>, Tile> tiles;
77 int rows = 0;
78 int cols = 0;
79};
80QList<MetaTile> getMetatiles( const QgsRectangle extent, const int zoom, const int tileSize = 4 );
81
82
86class QgsXyzTilesBaseAlgorithm : public QgsProcessingAlgorithm
87{
88 public:
89 QString group() const override;
90 QString groupId() const override;
92
93 protected:
97 void createCommonParameters();
98
99 bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
100
101 void checkLayersUsagePolicy( QgsProcessingFeedback *feedback );
102
103 void startJobs();
104 virtual void processMetaTile( QgsMapRendererSequentialJob *job ) = 0;
105
106 QgsRectangle mExtent;
107 QColor mBackgroundColor;
108 int mMinZoom = 12;
109 int mMaxZoom = 12;
110 int mDpi = 96;
111 bool mAntialias = true;
112 int mJpgQuality = 75;
113 int mMetaTileSize = 4;
114 int mThreadsNumber = 1;
115 int mTileWidth = 256;
116 int mTileHeight = 256;
117 QString mTileFormat;
118 QList<QgsMapLayer *> mLayers;
119 QgsCoordinateReferenceSystem mWgs84Crs;
120 QgsCoordinateReferenceSystem mMercatorCrs;
121 QgsCoordinateTransform mSrc2Wgs;
122 QgsCoordinateTransform mWgs2Mercator;
123 QgsRectangle mWgs84Extent;
124 QgsProcessingFeedback *mFeedback = nullptr;
125 long long mTotalTiles = 0;
126 long long mProcessedTiles = 0;
127 QgsCoordinateTransformContext mTransformContext;
128 QPointer<QEventLoop> mEventLoop;
129 QList<MetaTile> mMetaTiles;
130 QMap<QgsMapRendererSequentialJob *, MetaTile> mRendererJobs;
132};
133
134
138class QgsXyzTilesDirectoryAlgorithm : public QgsXyzTilesBaseAlgorithm
139{
140 public:
141 QgsXyzTilesDirectoryAlgorithm() = default;
142 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
143 QString name() const override;
144 QString displayName() const override;
145 QStringList tags() const override;
146 QString shortHelpString() const override;
147 QgsXyzTilesDirectoryAlgorithm *createInstance() const override SIP_FACTORY;
148
149 protected:
150 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
151
152 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
153
154 private:
155 bool mTms = false;
156 QString mOutputDir;
157};
158
162class QgsXyzTilesMbtilesAlgorithm : public QgsXyzTilesBaseAlgorithm
163{
164 public:
165 QgsXyzTilesMbtilesAlgorithm() = default;
166 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
167 QString name() const override;
168 QString displayName() const override;
169 QStringList tags() const override;
170 QString shortHelpString() const override;
171 QgsXyzTilesMbtilesAlgorithm *createInstance() const override SIP_FACTORY;
172
173 protected:
174 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
175
176 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
177
178 private:
179 std::unique_ptr<QgsMbTiles> mMbtilesWriter;
180};
181
183
184#endif // QGSALGORITHMXYZTILES_H
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3695
ScaleCalculationMethod
Scale calculation logic.
Definition qgis.h:5407
@ HorizontalMiddle
Calculate horizontally, across midle of map.
Definition qgis.h:5409
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.
A rectangle specified with double values.
#define SIP_FACTORY
Definition qgis_sip.h:83