QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
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:109
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsTileXYZ
Stores coordinates of a tile in a tile matrix set. Tile matrix is identified by the zoomLevel(),...
Definition: qgstiles.h:37
qgsrectangle.h
QgsVectorTileWriter::errorMessage
QString errorMessage() const
Returns error message related to the previous call to writeTiles().
Definition: qgsvectortilewriter.h:170
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:106
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:111
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:116
QgsVectorTileWriter::Layer::filterExpression
QString filterExpression() const
Returns filter expression. If not empty, only features matching the expression will be used.
Definition: qgsvectortilewriter.h:99
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:101
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsVectorTileWriter::setDestinationUri
void setDestinationUri(const QString &uri)
Sets where and how the vector tiles will be written.
Definition: qgsvectortilewriter.h:130
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:147
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:114
QgsVectorTileWriter::setLayers
void setLayers(const QList< QgsVectorTileWriter::Layer > &layers)
Sets vector layers and their configuration for output of vector tiles.
Definition: qgsvectortilewriter.h:144
QgsTileMatrix
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
Definition: qgstiles.h:107
QgsVectorTileWriter::setMinZoom
void setMinZoom(int minZoom)
Sets the minimum zoom level of tiles. Allowed values are in interval [0,24].
Definition: qgsvectortilewriter.h:139
QgsVectorTileWriter::setTransformContext
void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets coordinate transform context for transforms between layers and tile matrix CRS.
Definition: qgsvectortilewriter.h:150
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:141
QgsVectorTileWriter::Layer::layer
QgsVectorLayer * layer() const
Returns vector layer of this entry.
Definition: qgsvectortilewriter.h:96
QgsVectorTileWriter::Layer::Layer
Layer(QgsVectorLayer *layer)
Constructs an entry for a vector layer.
Definition: qgsvectortilewriter.h:90
qgstiles.h
QgsVectorTileWriter
Takes care of writing vector tiles. The intended use is to set up the class by setting the destinatio...
Definition: qgsvectortilewriter.h:74
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsVectorTileWriter::Layer
Configuration of a single input vector layer to be included in the output.
Definition: qgsvectortilewriter.h:86
qgscoordinatereferencesystem.h
QgsVectorTileWriter::Layer::layerName
QString layerName() const
Returns layer name in the output. If not set, layer()->name() will be used.
Definition: qgsvectortilewriter.h:104
QgsVectorTileWriter::setExtent
void setExtent(const QgsRectangle &extent)
Sets extent of vector tile output.
Definition: qgsvectortilewriter.h:136