Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make QgsVectorTileMVTDecoder::decode use QgsVectorTileRawData instead…
… of raw byte array
  • Loading branch information
nyalldawson committed May 22, 2023
1 parent a96c5a8 commit 981b4a8
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/core/vectortile/qgsvectortilelayer.cpp
Expand Up @@ -732,7 +732,7 @@ void QgsVectorTileLayer::selectByGeometry( const QgsGeometry &geometry, const Qg
continue; // failed to get data

QgsVectorTileMVTDecoder decoder( tileMatrixSet() );
if ( !decoder.decode( tileID, data ) )
if ( !decoder.decode( data ) )
continue; // failed to decode

QMap<QString, QgsFields> perLayerFields;
Expand Down
2 changes: 1 addition & 1 deletion src/core/vectortile/qgsvectortilelayerrenderer.cpp
Expand Up @@ -218,7 +218,7 @@ void QgsVectorTileLayerRenderer::decodeAndDrawTile( const QgsVectorTileRawData &

// currently only MVT encoding supported
QgsVectorTileMVTDecoder decoder( mTileMatrixSet );
if ( !decoder.decode( rawTile.id, rawTile.data ) )
if ( !decoder.decode( rawTile ) )
{
QgsDebugMsgLevel( QStringLiteral( "Failed to parse raw tile data! " ) + rawTile.id.toString(), 2 );
return;
Expand Down
8 changes: 4 additions & 4 deletions src/core/vectortile/qgsvectortilemvtdecoder.cpp
Expand Up @@ -15,9 +15,9 @@

#include <string>

#include "qgsvectortileloader.h"
#include "qgsvectortilemvtdecoder.h"

#include "qgsvectortilelayerrenderer.h"
#include "qgsvectortilemvtutils.h"
#include "qgsvectortileutils.h"

Expand All @@ -37,12 +37,12 @@ QgsVectorTileMVTDecoder::QgsVectorTileMVTDecoder( const QgsVectorTileMatrixSet &

QgsVectorTileMVTDecoder::~QgsVectorTileMVTDecoder() = default;

bool QgsVectorTileMVTDecoder::decode( QgsTileXYZ tileID, const QByteArray &rawTileData )
bool QgsVectorTileMVTDecoder::decode( const QgsVectorTileRawData &rawTileData )
{
if ( !tile.ParseFromArray( rawTileData.constData(), rawTileData.count() ) )
if ( !tile.ParseFromArray( rawTileData.data.constData(), rawTileData.data.count() ) )
return false;

mTileID = tileID;
mTileID = rawTileData.id;

mLayerNameToIndex.clear();
for ( int layerNum = 0; layerNum < tile.layers_size(); layerNum++ )
Expand Down
3 changes: 2 additions & 1 deletion src/core/vectortile/qgsvectortilemvtdecoder.h
Expand Up @@ -28,6 +28,7 @@ class QgsFeature;
#include "qgsvectortilerenderer.h"
#include "qgsvectortilematrixset.h"

class QgsVectorTileRawData;

/**
* \ingroup core
Expand All @@ -46,7 +47,7 @@ class CORE_EXPORT QgsVectorTileMVTDecoder
~QgsVectorTileMVTDecoder();

//! Tries to decode raw tile data, returns true on success
bool decode( QgsTileXYZ tileID, const QByteArray &rawTileData );
bool decode( const QgsVectorTileRawData &rawTileData );

//! Returns a list of sub-layer names in a tile. It can only be called after a successful decode()
QStringList layers() const;
Expand Down
2 changes: 1 addition & 1 deletion src/core/vectortile/qgsvectortileutils.cpp
Expand Up @@ -88,7 +88,7 @@ QgsVectorLayer *QgsVectorTileUtils::makeVectorLayerForTile( QgsVectorTileLayer *
{
QgsVectorTileMVTDecoder decoder( mvt->tileMatrixSet() );
const QgsVectorTileRawData rawTile = mvt->getRawTile( tileID );
decoder.decode( tileID, rawTile.data );
decoder.decode( rawTile );
QSet<QString> fieldNames = qgis::listToSet( decoder.layerFieldNames( layerName ) );
fieldNames << QStringLiteral( "_geom_type" );
QMap<QString, QgsFields> perLayerFields;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -456,7 +456,7 @@ bool QgsMapToolIdentify::identifyVectorTileLayer( QList<QgsMapToolIdentify::Iden
continue; // failed to get data

QgsVectorTileMVTDecoder decoder( layer->tileMatrixSet() );
if ( !decoder.decode( tileID, data ) )
if ( !decoder.decode( data ) )
continue; // failed to decode

QMap<QString, QgsFields> perLayerFields;
Expand Down
10 changes: 5 additions & 5 deletions tests/src/core/testqgsvectortilewriter.cpp
Expand Up @@ -117,7 +117,7 @@ void TestQgsVectorTileWriter::test_basic()

const QgsVectorTileRawData tile0 = vtLayer->getRawTile( QgsTileXYZ( 0, 0, 0 ) );
QgsVectorTileMVTDecoder decoder( QgsVectorTileMatrixSet::fromWebMercator() );
const bool resDecode0 = decoder.decode( QgsTileXYZ( 0, 0, 0 ), tile0.data );
const bool resDecode0 = decoder.decode( tile0 );
QVERIFY( resDecode0 );
const QStringList layerNames = decoder.layers();
QCOMPARE( layerNames, QStringList() << "points" << "lines" << "polys" );
Expand Down Expand Up @@ -186,7 +186,7 @@ void TestQgsVectorTileWriter::test_mbtiles()

const QgsVectorTileRawData tile0 = vtLayer->getRawTile( QgsTileXYZ( 0, 0, 0 ) );
QgsVectorTileMVTDecoder decoder( QgsVectorTileMatrixSet::fromWebMercator() );
const bool resDecode0 = decoder.decode( QgsTileXYZ( 0, 0, 0 ), tile0.data );
const bool resDecode0 = decoder.decode( tile0 );
QVERIFY( resDecode0 );
const QStringList layerNames = decoder.layers();
QCOMPARE( layerNames, QStringList() << "points" << "lines" << "polys" );
Expand Down Expand Up @@ -302,7 +302,7 @@ void TestQgsVectorTileWriter::test_filtering()

const QgsVectorTileRawData tile0 = vtLayer->getRawTile( QgsTileXYZ( 0, 0, 0 ) );
QgsVectorTileMVTDecoder decoder( QgsVectorTileMatrixSet::fromWebMercator() );
const bool resDecode0 = decoder.decode( QgsTileXYZ( 0, 0, 0 ), tile0.data );
const bool resDecode0 = decoder.decode( tile0 );
QVERIFY( resDecode0 );
const QStringList layerNames = decoder.layers();
QCOMPARE( layerNames, QStringList() << "b52" << "lines" );
Expand Down Expand Up @@ -365,7 +365,7 @@ void TestQgsVectorTileWriter::test_z0TileMatrix3857()

const QgsVectorTileRawData tile0 = vtLayer->getRawTile( QgsTileXYZ( 0, 0, 0 ) );
QgsVectorTileMVTDecoder decoder( QgsVectorTileMatrixSet::fromWebMercator() );
const bool resDecode0 = decoder.decode( QgsTileXYZ( 0, 0, 0 ), tile0.data );
const bool resDecode0 = decoder.decode( tile0 );
QVERIFY( resDecode0 );
const QStringList layerNames = decoder.layers();
QCOMPARE( layerNames, QStringList() << "points" << "lines" << "polys" );
Expand Down Expand Up @@ -451,7 +451,7 @@ void TestQgsVectorTileWriter::test_z0TileMatrix2154()

const QgsVectorTileRawData tile0 = vtLayer->getRawTile( QgsTileXYZ( 0, 0, 0 ) );
QgsVectorTileMVTDecoder decoder( QgsVectorTileMatrixSet::fromWebMercator() );
const bool resDecode0 = decoder.decode( QgsTileXYZ( 0, 0, 0 ), tile0.data );
const bool resDecode0 = decoder.decode( tile0 );
QVERIFY( resDecode0 );
const QStringList layerNames = decoder.layers();
QCOMPARE( layerNames, QStringList() << "points" << "lines" << "polys" );
Expand Down

0 comments on commit 981b4a8

Please sign in to comment.