QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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
QgsVectorTileWriter::Layer::minZoom
int minZoom() const
Returns minimum zoom level at which this layer will be used. Negative value means no min....
Definition: qgsvectortilewriter.h:107
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsTileXYZ
Stores coordinates of a tile in a tile matrix set.
Definition: qgstiles.h:33
qgsrectangle.h
QgsVectorTileWriter::errorMessage
QString errorMessage() const
Returns error message related to the previous call to writeTiles().
Definition: qgsvectortilewriter.h:163
QgsVectorTileWriter::Layer::setLayerName
void setLayerName(const QString &name)
Sets layer name in the output. If not set, layer()->name() will be used.
Definition: qgsvectortilewriter.h:104
QgsVectorTileWriter::Layer::setMinZoom
void setMinZoom(int minzoom)
Sets minimum zoom level at which this layer will be used. Negative value means no min....
Definition: qgsvectortilewriter.h:109
qgscoordinatetransformcontext.h
QgsVectorTileWriter::Layer::setMaxZoom
void setMaxZoom(int maxzoom)
Sets maximum zoom level at which this layer will be used. Negative value means no max....
Definition: qgsvectortilewriter.h:114
QgsVectorTileWriter::Layer::filterExpression
QString filterExpression() const
Returns filter expression. If not empty, only features matching the expression will be used.
Definition: qgsvectortilewriter.h:97
QgsVectorTileWriter::Layer::setFilterExpression
void setFilterExpression(const QString &expr)
Sets filter expression. If not empty, only features matching the expression will be used.
Definition: qgsvectortilewriter.h:99
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsVectorTileWriter::setDestinationUri
void setDestinationUri(const QString &uri)
Sets where and how the vector tiles will be written.
Definition: qgsvectortilewriter.h:128
QgsVectorTileWriter::setMetadata
void setMetadata(const QVariantMap &metadata)
Sets that will be written to the output dataset. See class description for more on metadata support.
Definition: qgsvectortilewriter.h:145
QgsVectorTileWriter::Layer::maxZoom
int maxZoom() const
Returns maximum zoom level at which this layer will be used. Negative value means no max....
Definition: qgsvectortilewriter.h:112
QgsVectorTileWriter::setLayers
void setLayers(const QList< QgsVectorTileWriter::Layer > &layers)
Sets vector layers and their configuration for output of vector tiles.
Definition: qgsvectortilewriter.h:142
QgsTileMatrix
Defines a matrix of tiles for a single zoom level: it is defined by its size (width * height) and map...
Definition: qgstiles.h:103
QgsVectorTileWriter::setMinZoom
void setMinZoom(int minZoom)
Sets the minimum zoom level of tiles. Allowed values are in interval [0,24].
Definition: qgsvectortilewriter.h:137
QgsVectorTileWriter::setTransformContext
void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets coordinate transform context for transforms between layers and tile matrix CRS.
Definition: qgsvectortilewriter.h:148
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsVectorTileWriter::setMaxZoom
void setMaxZoom(int maxZoom)
Sets the maximum zoom level of tiles. Allowed values are in interval [0,24].
Definition: qgsvectortilewriter.h:139
QgsVectorTileWriter::Layer::layer
QgsVectorLayer * layer() const
Returns vector layer of this entry.
Definition: qgsvectortilewriter.h:94
QgsVectorTileWriter::Layer::Layer
Layer(QgsVectorLayer *layer)
Constructs an entry for a vector layer.
Definition: qgsvectortilewriter.h:88
QgsVectorTileWriter
Takes care of writing vector tiles.
Definition: qgsvectortilewriter.h:73
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsVectorTileWriter::Layer
Configuration of a single input vector layer to be included in the output.
Definition: qgsvectortilewriter.h:85
QgsVectorTileWriter::Layer::layerName
QString layerName() const
Returns layer name in the output. If not set, layer()->name() will be used.
Definition: qgsvectortilewriter.h:102
QgsVectorTileWriter::setExtent
void setExtent(const QgsRectangle &extent)
Sets extent of vector tile output.
Definition: qgsvectortilewriter.h:134