QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 "qgsrectangle.h"
22 
23 class QgsFeedback;
24 class QgsTileMatrix;
25 class QgsTileXYZ;
26 class QgsVectorLayer;
27 
28 
72 class CORE_EXPORT QgsVectorTileWriter
73 {
74  Q_DECLARE_TR_FUNCTIONS( QgsVectorTileWriter )
75 
76  public:
78 
84  class Layer
85  {
86  public:
88  explicit Layer( QgsVectorLayer *layer )
89  : mLayer( layer )
90  {
91  }
92 
94  QgsVectorLayer *layer() const { return mLayer; }
95 
97  QString filterExpression() const { return mFilterExpression; }
99  void setFilterExpression( const QString &expr ) { mFilterExpression = expr; }
100 
102  QString layerName() const { return mLayerName; }
104  void setLayerName( const QString &name ) { mLayerName = name; }
105 
107  int minZoom() const { return mMinZoom; }
109  void setMinZoom( int minzoom ) { mMinZoom = minzoom; }
110 
112  int maxZoom() const { return mMaxZoom; }
114  void setMaxZoom( int maxzoom ) { mMaxZoom = maxzoom; }
115 
116  private:
117  QgsVectorLayer *mLayer;
118  QString mFilterExpression;
119  QString mLayerName;
120  int mMinZoom = -1;
121  int mMaxZoom = -1;
122  };
123 
128  void setDestinationUri( const QString &uri ) { mDestinationUri = uri; }
129 
134  void setExtent( const QgsRectangle &extent ) { mExtent = extent; }
135 
137  void setMinZoom( int minZoom ) { mMinZoom = minZoom; }
139  void setMaxZoom( int maxZoom ) { mMaxZoom = maxZoom; }
140 
142  void setLayers( const QList<QgsVectorTileWriter::Layer> &layers ) { mLayers = layers; }
143 
145  void setMetadata( const QVariantMap &metadata ) { mMetadata = metadata; }
146 
148  void setTransformContext( const QgsCoordinateTransformContext &transformContext ) { mTransformContext = transformContext; }
149 
157  bool writeTiles( QgsFeedback *feedback = nullptr );
158 
163  QString errorMessage() const { return mErrorMessage; }
164 
166  QgsRectangle fullExtent() const;
167 
168  private:
169  bool writeTileFileXYZ( const QString &sourcePath, QgsTileXYZ tileID, const QgsTileMatrix &tileMatrix, const QByteArray &tileData );
170  QString mbtilesJsonSchema();
171 
172  private:
173  QgsRectangle mExtent;
174  int mMinZoom = 0;
175  int mMaxZoom = 4;
176  QList<Layer> mLayers;
177  QString mDestinationUri;
178  QVariantMap mMetadata;
179  QgsCoordinateTransformContext mTransformContext;
180 
181  QString mErrorMessage;
182 };
183 
184 #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:103
Stores coordinates of a tile in a tile matrix set.
Definition: qgstiles.h:33
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.