QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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#include "qgsmbtiles.h"
27
29
30int tile2tms( const int y, const int zoom );
31int lon2tileX( const double lon, const int z );
32int lat2tileY( const double lat, const int z );
33double tileX2lon( const int x, const int z );
34double tileY2lat( const int y, const int z );
35void extent2TileXY( const QgsRectangle extent, const int zoom, int &xMin, int &yMin, int &xMax, int &yMax );
36
37struct Tile
38{
39 Tile( const int x, const int y, const int z )
40 : x( x )
41 , y( y )
42 , z( z )
43 {}
44
45 int x;
46 int y;
47 int z;
48};
49
50struct MetaTile
51{
52 MetaTile()
53 {}
54
55 void addTile( const int row, const int col, Tile tileToAdd )
56 {
57 tiles.insert( QPair<int, int>( row, col ), tileToAdd );
58 if ( row >= rows )
59 {
60 rows = row + 1;
61 }
62 if ( col >= cols )
63 {
64 cols = col + 1;
65 }
66 }
67
68 QgsRectangle extent()
69 {
70 const Tile first = tiles.first();
71 const Tile last = tiles.last();
72 return QgsRectangle( tileX2lon( first.x, first.z ), tileY2lat( last.y + 1, last.z ), tileX2lon( last.x + 1, last.z ), tileY2lat( first.y, first.z ) );
73 }
74
75 QMap<QPair<int, int>, Tile> tiles;
76 int rows = 0;
77 int cols = 0;
78};
79QList<MetaTile> getMetatiles( const QgsRectangle extent, const int zoom, const int tileSize = 4 );
80
81
85class QgsXyzTilesBaseAlgorithm : public QgsProcessingAlgorithm
86{
87 public:
88 QString group() const override;
89 QString groupId() const override;
91
92 protected:
96 void createCommonParameters();
97
98 bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
99
100 void checkLayersUsagePolicy( QgsProcessingFeedback *feedback );
101
102 void startJobs();
103 virtual void processMetaTile( QgsMapRendererSequentialJob *job ) = 0;
104
105 QgsRectangle mExtent;
106 QColor mBackgroundColor;
107 int mMinZoom = 12;
108 int mMaxZoom = 12;
109 int mDpi = 96;
110 bool mAntialias = true;
111 int mJpgQuality = 75;
112 int mMetaTileSize = 4;
113 int mThreadsNumber = 1;
114 int mTileWidth = 256;
115 int mTileHeight = 256;
116 QString mTileFormat;
117 QList<QgsMapLayer *> mLayers;
118 QgsCoordinateReferenceSystem mWgs84Crs;
119 QgsCoordinateReferenceSystem mMercatorCrs;
120 QgsCoordinateTransform mSrc2Wgs;
121 QgsCoordinateTransform mWgs2Mercator;
122 QgsRectangle mWgs84Extent;
123 QgsProcessingFeedback *mFeedback = nullptr;
124 long long mTotalTiles = 0;
125 long long mProcessedTiles = 0;
126 QgsCoordinateTransformContext mTransformContext;
127 QPointer<QEventLoop> mEventLoop;
128 QList<MetaTile> mMetaTiles;
129 QMap<QgsMapRendererSequentialJob *, MetaTile> mRendererJobs;
131};
132
133
137class QgsXyzTilesDirectoryAlgorithm : public QgsXyzTilesBaseAlgorithm
138{
139 public:
140 QgsXyzTilesDirectoryAlgorithm() = default;
141 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
142 QString name() const override;
143 QString displayName() const override;
144 QStringList tags() const override;
145 QString shortHelpString() const override;
146 QgsXyzTilesDirectoryAlgorithm *createInstance() const override SIP_FACTORY;
147
148 protected:
149 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
150
151 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
152
153 private:
154 bool mTms = false;
155 QString mOutputDir;
156};
157
161class QgsXyzTilesMbtilesAlgorithm : public QgsXyzTilesBaseAlgorithm
162{
163 public:
164 QgsXyzTilesMbtilesAlgorithm() = default;
165 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
166 QString name() const override;
167 QString displayName() const override;
168 QStringList tags() const override;
169 QString shortHelpString() const override;
170 QgsXyzTilesMbtilesAlgorithm *createInstance() const override SIP_FACTORY;
171
172 protected:
173 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
174
175 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
176
177 private:
178 std::unique_ptr<QgsMbTiles> mMbtilesWriter;
179};
180
182
183#endif // QGSALGORITHMXYZTILES_H
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3609
ScaleCalculationMethod
Scale calculation logic.
Definition qgis.h:5285
@ HorizontalMiddle
Calculate horizontally, across midle of map.
Definition qgis.h:5287
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:84