QGIS API Documentation 3.41.0-Master (cea29feecf2)
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 ), 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;
133};
134
135
139class QgsXyzTilesDirectoryAlgorithm : public QgsXyzTilesBaseAlgorithm
140{
141 public:
142 QgsXyzTilesDirectoryAlgorithm() = default;
143 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
144 QString name() const override;
145 QString displayName() const override;
146 QStringList tags() const override;
147 QString shortHelpString() const override;
148 QgsXyzTilesDirectoryAlgorithm *createInstance() const override SIP_FACTORY;
149
150 protected:
151 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
152
153 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
154
155 private:
156 bool mTms = false;
157 QString mOutputDir;
158};
159
163class QgsXyzTilesMbtilesAlgorithm : public QgsXyzTilesBaseAlgorithm
164{
165 public:
166 QgsXyzTilesMbtilesAlgorithm() = default;
167 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
168 QString name() const override;
169 QString displayName() const override;
170 QStringList tags() const override;
171 QString shortHelpString() const override;
172 QgsXyzTilesMbtilesAlgorithm *createInstance() const override SIP_FACTORY;
173
174 protected:
175 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
176
177 void processMetaTile( QgsMapRendererSequentialJob *job ) override;
178
179 private:
180 std::unique_ptr<QgsMbTiles> mMbtilesWriter;
181};
182
184
185#endif // QGSALGORITHMXYZTILES_H
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3392
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