33QString QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY = QStringLiteral(
"mbtilesvectortiles" );
34QString QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_DESCRIPTION = QObject::tr(
"MBTile Vector Tiles data provider" );
36QgsMbTilesVectorTileDataProvider::QgsMbTilesVectorTileDataProvider(
const QString &uri,
const ProviderOptions &providerOptions, ReadFlags flags )
41 const QString sourcePath = dsUri.
param( QStringLiteral(
"url" ) );
46 QgsDebugError( QStringLiteral(
"failed to open MBTiles file: " ) + sourcePath );
51 const QString format = reader.metadataValue( QStringLiteral(
"format" ) );
52 if ( format != QLatin1String(
"pbf" ) )
54 QgsDebugError( QStringLiteral(
"Cannot open MBTiles for vector tiles. Format = " ) + format );
59 QgsDebugMsgLevel( QStringLiteral(
"name: " ) + reader.metadataValue( QStringLiteral(
"name" ) ), 2 );
63 bool minZoomOk, maxZoomOk;
64 const int minZoom = reader.metadataValue( QStringLiteral(
"minzoom" ) ).toInt( &minZoomOk );
65 const int maxZoom = reader.metadataValue( QStringLiteral(
"maxzoom" ) ).toInt( &maxZoomOk );
67 mMatrixSet.dropMatricesOutsideZoomRange( minZoom, 99 );
69 mMatrixSet.dropMatricesOutsideZoomRange( 0, maxZoom );
70 QgsDebugMsgLevel( QStringLiteral(
"zoom range: %1 - %2" ).arg( mMatrixSet.minimumZoom() ).arg( mMatrixSet.maximumZoom() ), 2 );
75 ct.setBallparkTransformsAreAppropriate(
true );
78 mExtent = ct.transformBoundingBox( r );
82 QgsDebugError( QStringLiteral(
"Could not transform layer extent to layer CRS" ) );
88QgsMbTilesVectorTileDataProvider::QgsMbTilesVectorTileDataProvider(
const QgsMbTilesVectorTileDataProvider &other )
91 mIsValid = other.mIsValid;
92 mExtent = other.mExtent;
93 mMatrixSet = other.mMatrixSet;
96QString QgsMbTilesVectorTileDataProvider::name()
const
100 return MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY;
103QString QgsMbTilesVectorTileDataProvider::description()
const
107 return MB_TILES_VECTOR_TILE_DATA_PROVIDER_DESCRIPTION;
113 return new QgsMbTilesVectorTileDataProvider( *
this );
116QString QgsMbTilesVectorTileDataProvider::sourcePath()
const
122 return dsUri.param( QStringLiteral(
"url" ) );
125bool QgsMbTilesVectorTileDataProvider::isValid()
const
132QgsRectangle QgsMbTilesVectorTileDataProvider::extent()
const
160 QgsMbTiles mbReader( dsUri.param( QStringLiteral(
"url" ) ) );
172 QgsMbTiles mbReader( dsUri.param( QStringLiteral(
"url" ) ) );
175 QList<QgsVectorTileRawData> rawTiles;
176 rawTiles.reserve( tiles.size() );
177 for (
QgsTileXYZ id : std::as_const( tiles ) )
182 const QByteArray rawData = loadFromMBTiles( mbReader,
id, feedback );
183 if ( !rawData.isEmpty() )
194 const int rowTMS =
static_cast<int>( pow( 2,
id.zoomLevel() ) -
id.row() - 1 );
195 QByteArray gzippedTileData = mbTileReader.
tileData(
id.zoomLevel(),
id.column(), rowTMS );
196 if ( gzippedTileData.isEmpty() )
207 QgsDebugError( QStringLiteral(
"Failed to decompress tile " ) +
id.toString() );
211 QgsDebugMsgLevel( QStringLiteral(
"Tile blob size %1 -> uncompressed size %2" ).arg( gzippedTileData.size() ).arg( data.size() ), 2 );
220QgsMbTilesVectorTileDataProviderMetadata::QgsMbTilesVectorTileDataProviderMetadata()
221 :
QgsProviderMetadata( QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY,
222 QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_DESCRIPTION )
226QgsProviderMetadata::ProviderMetadataCapabilities QgsMbTilesVectorTileDataProviderMetadata::capabilities()
const
228 return ProviderMetadataCapability::LayerTypesForUri
229 | ProviderMetadataCapability::PriorityForUri
230 | ProviderMetadataCapability::QuerySublayers;
233QgsMbTilesVectorTileDataProvider *QgsMbTilesVectorTileDataProviderMetadata::createProvider(
const QString &uri,
const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
235 return new QgsMbTilesVectorTileDataProvider( uri, options, flags );
238QIcon QgsMbTilesVectorTileDataProviderMetadata::icon()
const
243QgsProviderMetadata::ProviderCapabilities QgsMbTilesVectorTileDataProviderMetadata::providerCapabilities()
const
245 return FileBasedUris;
261 return QObject::tr(
"Mbtiles Vector Tiles" ) + QStringLiteral(
" (*.mbtiles *.MBTILES)" );
266QList<QgsProviderSublayerDetails> QgsMbTilesVectorTileDataProviderMetadata::querySublayers(
const QString &uri, Qgis::SublayerQueryFlags flags,
QgsFeedback * )
const
269 const QFileInfo fi( uri );
276 const QVariantMap parts = decodeUri( uri );
277 fileName = parts.value( QStringLiteral(
"path" ) ).toString();
280 if ( fileName.isEmpty() )
283 if ( QFileInfo( fileName ).suffix().compare( QLatin1String(
"mbtiles" ), Qt::CaseInsensitive ) == 0 )
286 parts.insert( QStringLiteral(
"path" ), fileName );
292 details.
setUri( encodeUri( parts ) );
305 if ( reader.metadataValue(
"format" ) == QLatin1String(
"pbf" ) )
308 details.
setUri( encodeUri( parts ) );
320int QgsMbTilesVectorTileDataProviderMetadata::priorityForUri(
const QString &uri )
const
328QList<Qgis::LayerType> QgsMbTilesVectorTileDataProviderMetadata::validLayerTypesForUri(
const QString &uri )
const
330 const QFileInfo fi( uri );
331 if ( fi.isFile() && fi.suffix().compare( QLatin1String(
"mbtiles" ), Qt::CaseInsensitive ) == 0 )
336 const QVariantMap parts = decodeUri( uri );
337 if ( parts.value( QStringLiteral(
"path" ) ).toString().endsWith(
".mbtiles", Qt::CaseSensitivity::CaseInsensitive ) )
343QVariantMap QgsMbTilesVectorTileDataProviderMetadata::decodeUri(
const QString &uri )
const
348 QVariantMap uriComponents;
349 uriComponents.insert( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
350 uriComponents.insert( QStringLiteral(
"path" ), dsUri.
param( QStringLiteral(
"url" ) ) );
352 return uriComponents;
355QString QgsMbTilesVectorTileDataProviderMetadata::encodeUri(
const QVariantMap &parts )
const
358 dsUri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
359 dsUri.
setParam( QStringLiteral(
"url" ), parts.value( parts.contains( QStringLiteral(
"path" ) ) ? QStringLiteral(
"path" ) : QStringLiteral(
"url" ) ).toString() );
363QString QgsMbTilesVectorTileDataProviderMetadata::absoluteToRelativeUri(
const QString &uri,
const QgsReadWriteContext &context )
const
365 QVariantMap parts = decodeUri( uri );
367 const QString originalPath = parts.value( QStringLiteral(
"path" ) ).toString();
370 return encodeUri( parts );
373QString QgsMbTilesVectorTileDataProviderMetadata::relativeToAbsoluteUri(
const QString &uri,
const QgsReadWriteContext &context )
const
375 QVariantMap parts = decodeUri( uri );
377 const QString originalPath = parts.value( QStringLiteral(
"path" ) ).toString();
380 return encodeUri( parts );
383QList<Qgis::LayerType> QgsMbTilesVectorTileDataProviderMetadata::supportedLayerTypes()
const
FileFilterType
Type of file filters.
@ TiledScene
Tiled scene layers (since QGIS 3.34)
@ VectorTile
Vector tile layers (since QGIS 3.32)
@ MeshDataset
Mesh datasets.
@ PointCloud
Point clouds (since QGIS 3.18)
@ FastScan
Indicates that the provider must scan for sublayers using the fastest possible approach – e....
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
RendererUsage
Usage of the renderer.
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).
Custom exception class for Coordinate Reference System related exceptions.
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.
Utility class for reading and writing MBTiles files (which are SQLite3 databases).
QByteArray tileData(int z, int x, int y) const
Returns raw tile data for given tile.
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.
void setSkippedContainerScan(bool skipped)
Set to true if the layer is a potential dataset container and an in-depth scan of its contents was sk...
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.
Stores coordinates of a tile in a tile matrix set.
Base class for vector tile layer data providers.
Encapsulates properties of a vector tile matrix set, including tile origins and scaling information.
static QgsVectorTileMatrixSet fromWebMercator(int minimumZoom=0, int maximumZoom=14)
Returns a vector tile structure corresponding to the standard web mercator/GoogleCRS84Quad setup.
Keeps track of raw tile data that need to be decoded.
CORE_EXPORT bool decodeGzip(const QByteArray &bytesIn, QByteArray &bytesOut)
Decodes gzip byte stream, returns true on success.
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Setting options for creating vector data providers.