QGIS API Documentation 4.3.0-Master (7c7bd4d7018)
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 );
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 void addTile( const int row, const int col, Tile tileToAdd )
55 {
56 tiles.insert( QPair<int, int>( row, col ), tileToAdd );
57 if ( row >= rows )
58 {
59 rows = row + 1;
60 }
61 if ( col >= cols )
62 {
63 cols = col + 1;
64 }
65 }
66
67 QgsRectangle extent()
68 {
69 const Tile first = tiles.first();
70 const Tile last = tiles.last();
71 return QgsRectangle( tileX2lon( first.x, first.z ), tileY2lat( last.y + 1, last.z ), tileX2lon( last.x + 1, last.z ), tileY2lat( first.y, first.z ) );
72 }
73
74 QMap<QPair<int, int>, Tile> tiles;
75 int rows = 0;
76 int cols = 0;
77};
78QList<MetaTile> getMetatiles( const QgsRectangle extent, const int zoom, long long &tileCount, const int tileSize = 4 );
79
80
84class QgsXyzTilesBaseAlgorithm : public QgsProcessingAlgorithm
85{
86 public:
87 QString group() const override;
88 QString groupId() const override;
90
91 protected:
95 void createCommonParameters();
96
97 bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
98
99 void checkLayersUsagePolicy( QgsProcessingFeedback *feedback );
100
101 void startJobs();
102 virtual void processMetaTile( QgsMapRendererSequentialJob *job ) = 0;
103
104 QgsRectangle mExtent;
105 QColor mBackgroundColor;
106 int mMinZoom = 12;
107 int mMaxZoom = 12;
108 int mDpi = 96;
109 bool mAntialias = true;
110 int mJpgQuality = 75;
111 int mMetaTileSize = 4;
112 int mThreadsNumber = 1;
113 int mTileWidth = 256;
114 int mTileHeight = 256;
115 QString mTileFormat;
116 QList<QgsMapLayer *> mLayers;
117 QgsCoordinateReferenceSystem mWgs84Crs;
118 QgsCoordinateReferenceSystem mMercatorCrs;
119 QgsCoordinateTransform mSrc2Wgs;
120 QgsCoordinateTransform mWgs2Mercator;
121 QgsRectangle mWgs84Extent;
122 QgsProcessingFeedback *mFeedback = nullptr;
123 long long mTotalMetaTiles = 0;
124 long long mProcessedMetaTiles = 0;
125 QgsCoordinateTransformContext mTransformContext;
126 QString mEllipsoid;
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:3792
ScaleCalculationMethod
Scale calculation logic.
Definition qgis.h:5714
@ HorizontalMiddle
Calculate horizontally, across midle of map.
Definition qgis.h:5716
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