Skip to content

Commit

Permalink
[vector tile] Add pseudo-unique FIDs where none are given (fixes #36995)
Browse files Browse the repository at this point in the history
Feature IDs are optional in MVT encoding, and some datasets do not include
them. In QGIS we need FIDs for some functionality to work correctly, for
example labeling ignores label features with duplicate FIDs.
  • Loading branch information
wonder-sk committed Jun 11, 2020
1 parent b2da49b commit af2e50c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/core/vectortile/qgsvectortilemvtdecoder.cpp
Expand Up @@ -111,7 +111,21 @@ QgsVectorTileFeatures QgsVectorTileMVTDecoder::layerFeatures( const QMap<QString
{
const ::vector_tile::Tile_Feature &feature = layer.features( featureNum );

QgsFeature f( layerFields, static_cast<QgsFeatureId>( feature.id() ) );
QgsFeatureId fid;
if ( feature.has_id() )
fid = static_cast<QgsFeatureId>( feature.id() );
else
{
// There is no assigned ID, but some parts of QGIS do not work correctly if all IDs are zero
// (e.g. labeling will not register two features with the same FID within a single layer),
// so let's generate some pseudo-unique FIDs to keep those bits happy
fid = featureNum;
fid |= ( layerNum & 0xff ) << 24;
fid |= ( static_cast<QgsFeatureId>( mTileID.row() ) & 0xff ) << 32;
fid |= ( static_cast<QgsFeatureId>( mTileID.column() ) & 0xff ) << 40;
}

QgsFeature f( layerFields, fid );

//
// parse attributes
Expand Down

0 comments on commit af2e50c

Please sign in to comment.