Skip to content
Permalink
Browse files

[vector tile] Add pseudo-unique FIDs where none are given (fixes #36995)

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 af2e50caf75aec86b2597dda3a17cfa2f650c974
Showing with 15 additions and 1 deletion.
  1. +15 −1 src/core/vectortile/qgsvectortilemvtdecoder.cpp
@@ -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

0 comments on commit af2e50c

Please sign in to comment.
You can’t perform that action at this time.