QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsvectortilelayer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectortilelayer.h
3  --------------------------------------
4  Date : March 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 QGSVECTORTILELAYER_H
17 #define QGSVECTORTILELAYER_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 
22 #include "qgsmaplayer.h"
23 #include "qgsvectortilematrixset.h"
24 
27 
28 class QgsTileXYZ;
29 
84 class CORE_EXPORT QgsVectorTileLayer : public QgsMapLayer
85 {
86  Q_OBJECT
87 
88  public:
89 
90 
96  struct LayerOptions
97  {
98 
103  : transformContext( transformContext )
104  {}
105 
108  };
109 
111  explicit QgsVectorTileLayer( const QString &path = QString(), const QString &baseName = QString(), const QgsVectorTileLayer::LayerOptions &options = QgsVectorTileLayer::LayerOptions() );
112  ~QgsVectorTileLayer() override;
113 
114 #ifdef SIP_RUN
115  SIP_PYOBJECT __repr__();
116  % MethodCode
117  QString str = QStringLiteral( "<QgsVectorTileLayer: '%1'>" ).arg( sipCpp->name() );
118  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
119  % End
120 #endif
121 
122  // implementation of virtual functions from QgsMapLayer
123 
124  QgsVectorTileLayer *clone() const override SIP_FACTORY;
125  QgsDataProvider *dataProvider() override;
126  const QgsDataProvider *dataProvider() const override SIP_SKIP;
127  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
128  bool readXml( const QDomNode &layerNode, QgsReadWriteContext &context ) override;
129  bool writeXml( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
130  bool readSymbology( const QDomNode &node, QString &errorMessage,
131  QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
132  bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
133  StyleCategories categories = AllStyleCategories ) const override;
134  void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
135  QString loadDefaultStyle( bool &resultFlag SIP_OUT ) override;
136  Qgis::MapLayerProperties properties() const override;
137 
149  bool loadDefaultStyle( QString &error, QStringList &warnings ) SIP_SKIP;
150 
151  QString loadDefaultMetadata( bool &resultFlag SIP_OUT ) override;
152 
153  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const FINAL;
154  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const FINAL;
155  QString htmlMetadata() const override;
156 
157  // new methods
158 
164  QgsVectorTileMatrixSet &tileMatrixSet() { return mMatrixSet; }
165 
167  QString sourceType() const { return mSourceType; }
169  QString sourcePath() const { return mSourcePath; }
170 
172  int sourceMinZoom() const { return mMatrixSet.minimumZoom(); }
174  int sourceMaxZoom() const { return mMatrixSet.maximumZoom(); }
175 
183  QByteArray getRawTile( QgsTileXYZ tileID ) SIP_SKIP;
184 
189  void setRenderer( QgsVectorTileRenderer *r SIP_TRANSFER );
191  QgsVectorTileRenderer *renderer() const;
192 
197  void setLabeling( QgsVectorTileLabeling *labeling SIP_TRANSFER );
199  QgsVectorTileLabeling *labeling() const;
200 
202  void setTileBorderRenderingEnabled( bool enabled ) { mTileBorderRendering = enabled; }
204  bool isTileBorderRenderingEnabled() const { return mTileBorderRendering; }
205 
206  private:
207  bool loadDataSource();
208 
209  private:
211  QString mSourceType;
213  QString mSourcePath;
214 
215  QgsVectorTileMatrixSet mMatrixSet;
216 
218  std::unique_ptr<QgsVectorTileRenderer> mRenderer;
220  std::unique_ptr<QgsVectorTileLabeling> mLabeling;
222  bool mTileBorderRendering = false;
223 
224  QVariantMap mArcgisLayerConfiguration;
225  QVariantMap mArcgisStyleConfiguration;
226 
227  QgsCoordinateTransformContext mTransformContext;
228 
229  std::unique_ptr< QgsDataProvider > mDataProvider;
230 
231  bool setupArcgisVectorTileServiceConnection( const QString &uri, const QgsDataSourceUri &dataSourceUri );
232 
233  void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
234  const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags ) override;
235 
236 };
237 
238 #ifndef SIP_RUN
239 
246 class QgsVectorTileDataProvider : public QgsDataProvider
247 {
248  Q_OBJECT
249 
250  public:
251  QgsVectorTileDataProvider( const QgsDataProvider::ProviderOptions &providerOptions,
252  QgsDataProvider::ReadFlags flags );
253  QgsCoordinateReferenceSystem crs() const override;
254  QString name() const override;
255  QString description() const override;
256  QgsRectangle extent() const override;
257  bool isValid() const override;
258  bool renderInPreview( const QgsDataProvider::PreviewContext &context ) override;
259 
260 };
262 #endif
263 
264 
265 #endif // QGSVECTORTILELAYER_H
QgsVectorTileLayer::LayerOptions
Setting options for loading vector tile layers.
Definition: qgsvectortilelayer.h:96
QgsDataSourceUri
Class for storing the component parts of a RDBMS data source URI (e.g. a Postgres data source).
Definition: qgsdatasourceuri.h:37
QgsVectorTileLayer
Implements a map layer that is dedicated to rendering of vector tiles. Vector tiles compared to "ordi...
Definition: qgsvectortilelayer.h:84
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsVectorTileLayer::sourceType
QString sourceType() const
Returns type of the data source.
Definition: qgsvectortilelayer.h:167
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:107
QgsTileXYZ
Stores coordinates of a tile in a tile matrix set. Tile matrix is identified by the zoomLevel(),...
Definition: qgstiles.h:37
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsVectorTileMatrixSet
Encapsulates properties of a vector tile matrix set, including tile origins and scaling information.
Definition: qgsvectortilematrixset.h:31
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:40
QgsMapLayer::clone
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
qgsvectortilematrixset.h
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsVectorTileLayer::LayerOptions::LayerOptions
LayerOptions(const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions with optional transformContext.
Definition: qgsvectortilelayer.h:102
QgsVectorTileLayer::LayerOptions::transformContext
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgsvectortilelayer.h:107
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
FINAL
#define FINAL
Definition: qgis_sip.h:237
QgsVectorTileLayer::isTileBorderRenderingEnabled
bool isTileBorderRenderingEnabled() const
Returns whether to render also borders of tiles (useful for debugging)
Definition: qgsvectortilelayer.h:204
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsDataProvider::description
virtual QString description() const =0
Returns description.
QgsMapLayerRenderer
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Definition: qgsmaplayerrenderer.h:54
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsVectorTileLayer::sourcePath
QString sourcePath() const
Returns URL/path of the data source (syntax different to each data source type)
Definition: qgsvectortilelayer.h:169
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsVectorTileLayer::setTileBorderRenderingEnabled
void setTileBorderRenderingEnabled(bool enabled)
Sets whether to render also borders of tiles (useful for debugging)
Definition: qgsvectortilelayer.h:202
QgsVectorTileRenderer
Abstract base class for all vector tile renderer implementations.
Definition: qgsvectortilerenderer.h:92
qgsmaplayer.h
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsDataProvider::PreviewContext
Stores settings related to the context in which a preview job runs.
Definition: qgsdataprovider.h:541
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsDataProvider::renderInPreview
virtual bool renderInPreview(const QgsDataProvider::PreviewContext &context)
Returns whether the layer must be rendered in preview jobs.
Definition: qgsdataprovider.cpp:76
QgsVectorTileLayer::sourceMaxZoom
int sourceMaxZoom() const
Returns maximum zoom level at which source has any valid tiles (negative = unconstrained)
Definition: qgsvectortilelayer.h:174
str
#define str(x)
Definition: qgis.cpp:37
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsDataProvider::extent
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
Qgis
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:71
QgsVectorTileLabeling
Base class for labeling configuration classes for vector tile layers.
Definition: qgsvectortilelabeling.h:70
QgsVectorTileLayer::sourceMinZoom
int sourceMinZoom() const
Returns minimum zoom level at which source has any valid tiles (negative = unconstrained)
Definition: qgsvectortilelayer.h:172
QgsDataProvider::name
virtual QString name() const =0
Returns a provider name.
QgsDataProvider::isValid
virtual bool isValid() const =0
Returns true if this is a valid layer.
QgsDataProvider::crs
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.