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,
Qgis::DataProviderReadFlags 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;
101QString QgsMbTilesVectorTileDataProvider::name()
const
105 return MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY;
108QString QgsMbTilesVectorTileDataProvider::description()
const
112 return MB_TILES_VECTOR_TILE_DATA_PROVIDER_DESCRIPTION;
118 return new QgsMbTilesVectorTileDataProvider( *
this );
121QString QgsMbTilesVectorTileDataProvider::sourcePath()
const
127 return dsUri.param( QStringLiteral(
"url" ) );
130bool QgsMbTilesVectorTileDataProvider::isValid()
const
137QgsRectangle QgsMbTilesVectorTileDataProvider::extent()
const
165 QgsMbTiles mbReader( dsUri.param( QStringLiteral(
"url" ) ) );
177 QgsMbTiles mbReader( dsUri.param( QStringLiteral(
"url" ) ) );
180 QList<QgsVectorTileRawData> rawTiles;
181 rawTiles.reserve( tiles.size() );
182 for (
QgsTileXYZ id : std::as_const( tiles ) )
187 const QByteArray rawData = loadFromMBTiles( mbReader,
id, feedback );
188 if ( !rawData.isEmpty() )
199 const int rowTMS =
static_cast<int>( pow( 2,
id.zoomLevel() ) -
id.row() - 1 );
200 QByteArray gzippedTileData = mbTileReader.
tileData(
id.zoomLevel(),
id.column(), rowTMS );
201 if ( gzippedTileData.isEmpty() )
212 QgsDebugError( QStringLiteral(
"Failed to decompress tile " ) +
id.toString() );
216 QgsDebugMsgLevel( QStringLiteral(
"Tile blob size %1 -> uncompressed size %2" ).arg( gzippedTileData.size() ).arg( data.size() ), 2 );
225QgsMbTilesVectorTileDataProviderMetadata::QgsMbTilesVectorTileDataProviderMetadata()
226 :
QgsProviderMetadata( QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY,
227 QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_DESCRIPTION )
233 return ProviderMetadataCapability::LayerTypesForUri
234 | ProviderMetadataCapability::PriorityForUri
235 | ProviderMetadataCapability::QuerySublayers;
240 return new QgsMbTilesVectorTileDataProvider( uri, options, flags );
243QIcon QgsMbTilesVectorTileDataProviderMetadata::icon()
const
250 return FileBasedUris;
266 return QObject::tr(
"Mbtiles Vector Tiles" ) + QStringLiteral(
" (*.mbtiles *.MBTILES)" );
274 const QFileInfo fi( uri );
281 const QVariantMap parts = decodeUri( uri );
282 fileName = parts.value( QStringLiteral(
"path" ) ).toString();
285 if ( fileName.isEmpty() )
288 if ( QFileInfo( fileName ).suffix().compare( QLatin1String(
"mbtiles" ), Qt::CaseInsensitive ) == 0 )
291 parts.insert( QStringLiteral(
"path" ), fileName );
297 details.
setUri( encodeUri( parts ) );
310 if ( reader.metadataValue(
"format" ) == QLatin1String(
"pbf" ) )
313 details.
setUri( encodeUri( parts ) );
325int QgsMbTilesVectorTileDataProviderMetadata::priorityForUri(
const QString &uri )
const
333QList<Qgis::LayerType> QgsMbTilesVectorTileDataProviderMetadata::validLayerTypesForUri(
const QString &uri )
const
335 const QFileInfo fi( uri );
336 if ( fi.isFile() && fi.suffix().compare( QLatin1String(
"mbtiles" ), Qt::CaseInsensitive ) == 0 )
341 const QVariantMap parts = decodeUri( uri );
342 if ( parts.value( QStringLiteral(
"path" ) ).toString().endsWith(
".mbtiles", Qt::CaseSensitivity::CaseInsensitive ) )
348QVariantMap QgsMbTilesVectorTileDataProviderMetadata::decodeUri(
const QString &uri )
const
353 QVariantMap uriComponents;
354 uriComponents.insert( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
355 uriComponents.insert( QStringLiteral(
"path" ), dsUri.
param( QStringLiteral(
"url" ) ) );
357 return uriComponents;
360QString QgsMbTilesVectorTileDataProviderMetadata::encodeUri(
const QVariantMap &parts )
const
363 dsUri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
364 dsUri.
setParam( QStringLiteral(
"url" ), parts.value( parts.contains( QStringLiteral(
"path" ) ) ? QStringLiteral(
"path" ) : QStringLiteral(
"url" ) ).toString() );
368QString QgsMbTilesVectorTileDataProviderMetadata::absoluteToRelativeUri(
const QString &uri,
const QgsReadWriteContext &context )
const
370 QVariantMap parts = decodeUri( uri );
372 const QString originalPath = parts.value( QStringLiteral(
"path" ) ).toString();
375 return encodeUri( parts );
378QString QgsMbTilesVectorTileDataProviderMetadata::relativeToAbsoluteUri(
const QString &uri,
const QgsReadWriteContext &context )
const
380 QVariantMap parts = decodeUri( uri );
382 const QString originalPath = parts.value( QStringLiteral(
"path" ) ).toString();
385 return encodeUri( parts );
388QList<Qgis::LayerType> QgsMbTilesVectorTileDataProviderMetadata::supportedLayerTypes()
const
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 ...
@ FastScan
Indicates that the provider must scan for sublayers using the fastest possible approach – e....
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
@ 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 from one or more sources 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.