QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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
25class QgsFeedback;
26class QgsTileMatrix;
27class QgsTileXYZ;
28class QgsVectorLayer;
29
30
76class CORE_EXPORT QgsVectorTileWriter
77{
78 Q_DECLARE_TR_FUNCTIONS( QgsVectorTileWriter )
79
80 public:
82
88 class Layer
89 {
90 public:
92 explicit Layer( QgsVectorLayer *layer )
93 : mLayer( layer )
94 {
95 }
96
98 QgsVectorLayer *layer() const { return mLayer; }
99
101 QString filterExpression() const { return mFilterExpression; }
103 void setFilterExpression( const QString &expr ) { mFilterExpression = expr; }
104
106 QString layerName() const { return mLayerName; }
108 void setLayerName( const QString &name ) { mLayerName = name; }
109
111 int minZoom() const { return mMinZoom; }
113 void setMinZoom( int minzoom ) { mMinZoom = minzoom; }
114
116 int maxZoom() const { return mMaxZoom; }
118 void setMaxZoom( int maxzoom ) { mMaxZoom = maxzoom; }
119
120 private:
121 QgsVectorLayer *mLayer;
122 QString mFilterExpression;
123 QString mLayerName;
124 int mMinZoom = -1;
125 int mMaxZoom = -1;
126 };
127
132 void setDestinationUri( const QString &uri ) { mDestinationUri = uri; }
133
138 void setExtent( const QgsRectangle &extent ) { mExtent = extent; }
139
141 void setMinZoom( int minZoom ) { mMinZoom = minZoom; }
143 void setMaxZoom( int maxZoom ) { mMaxZoom = maxZoom; }
144
146 void setLayers( const QList<QgsVectorTileWriter::Layer> &layers ) { mLayers = layers; }
147
149 void setMetadata( const QVariantMap &metadata ) { mMetadata = metadata; }
150
152 void setTransformContext( const QgsCoordinateTransformContext &transformContext ) { mTransformContext = transformContext; }
153
157 bool setRootTileMatrix( const QgsTileMatrix &tileMatrix );
158
166 bool writeTiles( QgsFeedback *feedback = nullptr );
167
172 QString errorMessage() const { return mErrorMessage; }
173
175 QgsRectangle fullExtent() const;
176
189 QByteArray writeSingleTile( QgsTileXYZ tileID, QgsFeedback *feedback = nullptr, int buffer = 256, int resolution = 4096 ) const;
190
191 private:
192 bool writeTileFileXYZ( const QString &sourcePath, QgsTileXYZ tileID, const QgsTileMatrix &tileMatrix, const QByteArray &tileData );
193 QString mbtilesJsonSchema();
194
195 private:
196 QgsTileMatrix mRootTileMatrix;
197 QgsRectangle mExtent;
198 int mMinZoom = 0;
199 int mMaxZoom = 4;
200 QList<Layer> mLayers;
201 QString mDestinationUri;
202 QVariantMap mMetadata;
203 QgsCoordinateTransformContext mTransformContext;
204
205 QString mErrorMessage;
206};
207
208#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:44
A rectangle specified with double values.
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
Definition qgstiles.h:136
Stores coordinates of a tile in a tile matrix set.
Definition qgstiles.h:40
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.
void setLayerName(const QString &name)
Sets layer name in the output. If not set, layer()->name() will be used.
QgsVectorLayer * layer() const
Returns vector layer of this entry.
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.