31QString QgsVtpkVectorTileDataProvider::DATA_PROVIDER_KEY = QStringLiteral(
"vtpkvectortiles" );
32QString QgsVtpkVectorTileDataProvider::DATA_PROVIDER_DESCRIPTION = QObject::tr(
"VTPK Vector Tiles data provider" );
35QgsVtpkVectorTileDataProvider::QgsVtpkVectorTileDataProvider(
const QString &uri,
const ProviderOptions &providerOptions,
Qgis::DataProviderReadFlags flags )
40 const QString sourcePath = dsUri.
param( QStringLiteral(
"url" ) );
45 QgsDebugError( QStringLiteral(
"failed to open VTPK file: " ) + sourcePath );
50 const QVariantMap metadata = reader.metadata();
51 const QString format = metadata.value( QStringLiteral(
"tileInfo" ) ).toMap().value( QStringLiteral(
"format" ) ).toString();
52 if ( format != QLatin1String(
"pbf" ) )
54 QgsDebugError( QStringLiteral(
"Cannot open VTPK for vector tiles. Format = " ) + format );
59 mMatrixSet = reader.matrixSet();
60 mCrs = mMatrixSet.crs();
61 mExtent = reader.extent( transformContext() );
62 mLayerMetadata = reader.layerMetadata();
63 mStyleDefinition = reader.styleDefinition();
64 mSpriteDefinition = reader.spriteDefinition();
65 if ( !mSpriteDefinition.isEmpty() )
67 mSpriteImage = reader.spriteImage();
73QgsVtpkVectorTileDataProvider::QgsVtpkVectorTileDataProvider(
const QgsVtpkVectorTileDataProvider &other )
76 mIsValid = other.mIsValid;
78 mExtent = other.mExtent;
79 mMatrixSet = other.mMatrixSet;
80 mLayerMetadata = other.mLayerMetadata;
81 mStyleDefinition = other.mStyleDefinition;
82 mSpriteDefinition = other.mSpriteDefinition;
83 mSpriteImage = other.mSpriteImage;
101QString QgsVtpkVectorTileDataProvider::name()
const
105 return DATA_PROVIDER_KEY;
108QString QgsVtpkVectorTileDataProvider::description()
const
112 return DATA_PROVIDER_DESCRIPTION;
118 return new QgsVtpkVectorTileDataProvider( *
this );
121QString QgsVtpkVectorTileDataProvider::sourcePath()
const
127 return dsUri.param( QStringLiteral(
"url" ) );
130bool QgsVtpkVectorTileDataProvider::isValid()
const
144QgsRectangle QgsVtpkVectorTileDataProvider::extent()
const
153 return mLayerMetadata;
163QVariantMap QgsVtpkVectorTileDataProvider::styleDefinition()
const
167 return mStyleDefinition;
170QVariantMap QgsVtpkVectorTileDataProvider::spriteDefinition()
const
174 return mSpriteDefinition;
177QImage QgsVtpkVectorTileDataProvider::spriteImage()
const
189 if ( mShared->getCachedTileData( data,
id ) )
197 mShared->storeCachedTileData( rawData );
209 std::unique_ptr< QgsVtpkTiles > reader;
211 QList<QgsVectorTileRawData> rawTiles;
212 QSet< QgsTileXYZ > fetchedTiles;
213 rawTiles.reserve( tiles.size() );
214 fetchedTiles.reserve( tiles.size() );
215 for (
QgsTileXYZ id : std::as_const( tiles ) )
220 if ( fetchedTiles.contains(
id ) )
224 if ( mShared->getCachedTileData( data,
id ) )
226 rawTiles.append( data );
227 fetchedTiles.insert( data.
id );
233 reader = std::make_unique< QgsVtpkTiles >( dsUri.param( QStringLiteral(
"url" ) ) );
237 if ( !rawData.
data.isEmpty() && !fetchedTiles.contains( rawData.
id ) )
239 rawTiles.append( rawData );
240 fetchedTiles.insert( rawData.
id );
241 mShared->storeCachedTileData( rawData );
248QString QgsVtpkVectorTileDataProvider::htmlMetadata()
const
257 if ( !reader.rootTileMap().isEmpty() )
258 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) % tr(
"VTPK storage" ) % QStringLiteral(
"</td><td>" ) % tr(
"Indexed VTPK (tilemap is present)" ) % QStringLiteral(
"</td></tr>\n" );
260 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) % tr(
"VTPK storage" ) % QStringLiteral(
"</td><td>" ) % tr(
"Flat VTPK (no tilemap)" ) % QStringLiteral(
"</td></tr>\n" );
262 if ( reader.metadata().contains( QStringLiteral(
"minLOD" ) ) )
264 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) % tr(
"Tile detail levels" ) % QStringLiteral(
"</td><td>" ) % QStringLiteral(
"%1 - %2" ).arg( reader.metadata().value( QStringLiteral(
"minLOD" ) ).toInt() ).arg( reader.metadata().value( QStringLiteral(
"maxLOD" ) ).toInt() ) % QStringLiteral(
"</td></tr>\n" );
283 if ( tileData.isNull() )
287 res.tileGeometryId = requestedTile;
296QgsVtpkVectorTileDataProviderMetadata::QgsVtpkVectorTileDataProviderMetadata()
297 :
QgsProviderMetadata( QgsVtpkVectorTileDataProvider::DATA_PROVIDER_KEY, QgsVtpkVectorTileDataProvider::DATA_PROVIDER_DESCRIPTION )
303 return ProviderMetadataCapability::LayerTypesForUri
304 | ProviderMetadataCapability::PriorityForUri
305 | ProviderMetadataCapability::QuerySublayers;
310 return new QgsVtpkVectorTileDataProvider( uri, options, flags );
313QIcon QgsVtpkVectorTileDataProviderMetadata::icon()
const
320 return FileBasedUris;
336 return QObject::tr(
"VTPK Vector Tiles" ) + QStringLiteral(
" (*.vtpk *.VTPK)" );
344 const QFileInfo fi( uri );
351 const QVariantMap parts = decodeUri( uri );
352 fileName = parts.value( QStringLiteral(
"path" ) ).toString();
355 if ( fileName.isEmpty() )
358 if ( QFileInfo( fileName ).suffix().compare( QLatin1String(
"vtpk" ), Qt::CaseInsensitive ) == 0 )
361 parts.insert( QStringLiteral(
"path" ), fileName );
364 details.
setUri( encodeUri( parts ) );
376int QgsVtpkVectorTileDataProviderMetadata::priorityForUri(
const QString &uri )
const
384QList<Qgis::LayerType> QgsVtpkVectorTileDataProviderMetadata::validLayerTypesForUri(
const QString &uri )
const
386 const QFileInfo fi( uri );
387 if ( fi.isFile() && fi.suffix().compare( QLatin1String(
"vtpk" ), Qt::CaseInsensitive ) == 0 )
392 const QVariantMap parts = decodeUri( uri );
393 if ( parts.value( QStringLiteral(
"path" ) ).toString().endsWith(
".vtpk", Qt::CaseSensitivity::CaseInsensitive ) )
399QVariantMap QgsVtpkVectorTileDataProviderMetadata::decodeUri(
const QString &uri )
const
404 QVariantMap uriComponents;
405 uriComponents.insert( QStringLiteral(
"type" ), QStringLiteral(
"vtpk" ) );
406 uriComponents.insert( QStringLiteral(
"path" ), dsUri.
param( QStringLiteral(
"url" ) ) );
408 return uriComponents;
411QString QgsVtpkVectorTileDataProviderMetadata::encodeUri(
const QVariantMap &parts )
const
414 dsUri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"vtpk" ) );
415 dsUri.
setParam( QStringLiteral(
"url" ), parts.value( parts.contains( QStringLiteral(
"path" ) ) ? QStringLiteral(
"path" ) : QStringLiteral(
"url" ) ).toString() );
419QString QgsVtpkVectorTileDataProviderMetadata::absoluteToRelativeUri(
const QString &uri,
const QgsReadWriteContext &context )
const
421 QVariantMap parts = decodeUri( uri );
423 const QString originalPath = parts.value( QStringLiteral(
"path" ) ).toString();
426 return encodeUri( parts );
429QString QgsVtpkVectorTileDataProviderMetadata::relativeToAbsoluteUri(
const QString &uri,
const QgsReadWriteContext &context )
const
431 QVariantMap parts = decodeUri( uri );
433 const QString originalPath = parts.value( QStringLiteral(
"path" ) ).toString();
436 return encodeUri( parts );
439QList<Qgis::LayerType> QgsVtpkVectorTileDataProviderMetadata::supportedLayerTypes()
const
@ ReadLayerMetadata
Provider can read layer metadata from data store. See QgsDataProvider::layerMetadata()
@ AlwaysUseTileMatrixSetFromProvider
Vector tile layer must always use the tile matrix set from the data provider, and should never store,...
QFlags< DataProviderFlag > DataProviderFlags
Data provider flags.
FileFilterType
Type of file filters.
@ TiledScene
Tiled scene layers.
@ VectorTile
Vector tile layers.
@ MeshDataset
Mesh datasets.
@ PointCloud
Point clouds.
@ FastExtent2D
Provider's 2D extent retrieval via QgsDataProvider::extent() is always guaranteed to be trivial/fast ...
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
QFlags< VectorTileProviderCapability > VectorTileProviderCapabilities
Vector tile data provider capabilities.
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
RendererUsage
Usage of the renderer.
QFlags< VectorTileProviderFlag > VectorTileProviderFlags
Vector tile data provider flags.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
This class represents a coordinate reference system (CRS).
Class for storing the component parts of a RDBMS data source URI (e.g.
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
bool isCanceled() const
Tells whether the operation has been canceled already.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
Contains details about a sub layer available from a dataset.
void setUri(const QString &uri)
Sets the layer's uri.
void setType(Qgis::LayerType type)
Sets the layer type.
void setName(const QString &name)
Sets the layer's name.
void setProviderKey(const QString &key)
Sets the associated data provider key.
static QString suggestLayerNameFromFilePath(const QString &path)
Suggests a suitable layer name given only a file path.
The class is used as a container of context for various read/write operations on other objects.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
A rectangle specified with double values.
Defines a set of tile matrices for multiple zoom levels.
int minimumZoom() const
Returns the minimum zoom level for tiles present in the set.
Stores coordinates of a tile in a tile matrix set.
int zoomLevel() const
Returns tile's zoom level (Z)
int column() const
Returns tile's column index (X)
int row() const
Returns tile's row index (Y)
Base class for vector tile layer data providers.
Encapsulates properties of a vector tile matrix set, including tile origins and scaling information.
Keeps track of raw tile data from one or more sources that need to be decoded.
QMap< QString, QByteArray > data
Raw tile data by source ID.
QgsTileXYZ id
Tile position in tile matrix set.
Utility class for reading and writing ESRI VTPK files.
QByteArray tileData(int z, int x, int y)
Returns the raw tile data for the matching tile.
QgsVectorTileMatrixSet matrixSet() const
Returns the vector tile matrix set representing the tiles.
#define QgsDebugError(str)
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Setting options for creating vector data providers.