QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgsvectortilewriter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectortilewriter.h
3  --------------------------------------
4  Date : April 2020
5  Copyright : (C) 2020 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSVECTORTILEWRITER_H
17 #define QGSVECTORTILEWRITER_H
18 
19 #include <QCoreApplication>
20 #include "qgstiles.h"
21 #include "qgsrectangle.h"
24 
25 class QgsFeedback;
26 class QgsTileMatrix;
27 class QgsTileXYZ;
28 class QgsVectorLayer;
29 
30 
74 class CORE_EXPORT QgsVectorTileWriter
75 {
76  Q_DECLARE_TR_FUNCTIONS( QgsVectorTileWriter )
77 
78  public:
80 
86  class Layer
87  {
88  public:
90  explicit Layer( QgsVectorLayer *layer )
91  : mLayer( layer )
92  {
93  }
94 
96  QgsVectorLayer *layer() const { return mLayer; }
97 
99  QString filterExpression() const { return mFilterExpression; }
101  void setFilterExpression( const QString &expr ) { mFilterExpression = expr; }
102 
104  QString layerName() const { return mLayerName; }
106  void setLayerName( const QString &name ) { mLayerName = name; }
107 
109  int minZoom() const { return mMinZoom; }
111  void setMinZoom( int minzoom ) { mMinZoom = minzoom; }
112 
114  int maxZoom() const { return mMaxZoom; }
116  void setMaxZoom( int maxzoom ) { mMaxZoom = maxzoom; }
117 
118  private:
119  QgsVectorLayer *mLayer;
120  QString mFilterExpression;
121  QString mLayerName;
122  int mMinZoom = -1;
123  int mMaxZoom = -1;
124  };
125 
130  void setDestinationUri( const QString &uri ) { mDestinationUri = uri; }
131 
136  void setExtent( const QgsRectangle &extent ) { mExtent = extent; }
137 
139  void setMinZoom( int minZoom ) { mMinZoom = minZoom; }
141  void setMaxZoom( int maxZoom ) { mMaxZoom = maxZoom; }
142 
144  void setLayers( const QList<QgsVectorTileWriter::Layer> &layers ) { mLayers = layers; }
145 
147  void setMetadata( const QVariantMap &metadata ) { mMetadata = metadata; }
148 
150  void setTransformContext( const QgsCoordinateTransformContext &transformContext ) { mTransformContext = transformContext; }
151 
155  bool setRootTileMatrix( const QgsTileMatrix &tileMatrix );
156 
164  bool writeTiles( QgsFeedback *feedback = nullptr );
165 
170  QString errorMessage() const { return mErrorMessage; }
171 
173  QgsRectangle fullExtent() const;
174 
187  QByteArray writeSingleTile( QgsTileXYZ tileID, QgsFeedback *feedback = nullptr, int buffer = 256, int resolution = 4096 ) const;
188 
189  private:
190  bool writeTileFileXYZ( const QString &sourcePath, QgsTileXYZ tileID, const QgsTileMatrix &tileMatrix, const QByteArray &tileData );
191  QString mbtilesJsonSchema();
192 
193  private:
194  QgsTileMatrix mRootTileMatrix;
195  QgsRectangle mExtent;
196  int mMinZoom = 0;
197  int mMaxZoom = 4;
198  QList<Layer> mLayers;
199  QString mDestinationUri;
200  QVariantMap mMetadata;
201  QgsCoordinateTransformContext mTransformContext;
202 
203  QString mErrorMessage;
204 };
205 
206 #endif // QGSVECTORTILEWRITER_H
Contains information about the context in which a coordinate transform is executed.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
Definition: qgstiles.h:108
Stores coordinates of a tile in a tile matrix set.
Definition: qgstiles.h:38
Represents a vector layer which manages a vector based data sets.
Configuration of a single input vector layer to be included in the output.
QString layerName() const
Returns layer name in the output. If not set, layer()->name() will be used.
Layer(QgsVectorLayer *layer)
Constructs an entry for a vector layer.
QgsVectorLayer * layer() const
Returns vector layer of this entry.
void setLayerName(const QString &name)
Sets layer name in the output. If not set, layer()->name() will be used.
void setMaxZoom(int maxzoom)
Sets maximum zoom level at which this layer will be used. Negative value means no max....
void setFilterExpression(const QString &expr)
Sets filter expression. If not empty, only features matching the expression will be used.
void setMinZoom(int minzoom)
Sets minimum zoom level at which this layer will be used. Negative value means no min....
QString filterExpression() const
Returns filter expression. If not empty, only features matching the expression will be used.
int maxZoom() const
Returns maximum zoom level at which this layer will be used. Negative value means no max....
int minZoom() const
Returns minimum zoom level at which this layer will be used. Negative value means no min....
Takes care of writing vector tiles.
QString errorMessage() const
Returns error message related to the previous call to writeTiles().
void setMaxZoom(int maxZoom)
Sets the maximum zoom level of tiles. Allowed values are in interval [0,24].
void setDestinationUri(const QString &uri)
Sets where and how the vector tiles will be written.
void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets coordinate transform context for transforms between layers and tile matrix CRS.
void setExtent(const QgsRectangle &extent)
Sets extent of vector tile output.
void setLayers(const QList< QgsVectorTileWriter::Layer > &layers)
Sets vector layers and their configuration for output of vector tiles.
void setMinZoom(int minZoom)
Sets the minimum zoom level of tiles. Allowed values are in interval [0,24].
void setMetadata(const QVariantMap &metadata)
Sets that will be written to the output dataset. See class description for more on metadata support.