Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Handle indexed tiles in vector tile selections
  • Loading branch information
nyalldawson committed May 16, 2023
1 parent 19654b7 commit cf3aeb5
Showing 1 changed file with 45 additions and 48 deletions.
93 changes: 45 additions & 48 deletions src/core/vectortile/qgsvectortilelayer.cpp
Expand Up @@ -721,64 +721,61 @@ void QgsVectorTileLayer::selectByGeometry( const QgsGeometry &geometry, const Qg
const int tileZoom = tileMatrixSet().scaleToZoomLevel( context.scale() );
const QgsTileMatrix tileMatrix = tileMatrixSet().tileMatrix( tileZoom );
const QgsTileRange tileRange = tileMatrix.tileRangeFromExtent( r );
const QVector< QgsTileXYZ> tiles = tileMatrixSet().tilesInRange( tileRange, tileZoom );

for ( int row = tileRange.startRow(); row <= tileRange.endRow(); ++row )
for ( const QgsTileXYZ &tileID : tiles )
{
for ( int col = tileRange.startColumn(); col <= tileRange.endColumn(); ++col )
QByteArray data = getRawTile( tileID );
if ( data.isEmpty() )
continue; // failed to get data

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

QMap<QString, QgsFields> perLayerFields;
const QStringList layerNames = decoder.layers();
for ( const QString &layerName : layerNames )
{
QgsTileXYZ tileID( col, row, tileZoom );
QByteArray data = getRawTile( tileID );
if ( data.isEmpty() )
continue; // failed to get data

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

QMap<QString, QgsFields> perLayerFields;
const QStringList layerNames = decoder.layers();
for ( const QString &layerName : layerNames )
{
QSet<QString> fieldNames = qgis::listToSet( decoder.layerFieldNames( layerName ) );
perLayerFields[layerName] = QgsVectorTileUtils::makeQgisFields( fieldNames );
}
QSet<QString> fieldNames = qgis::listToSet( decoder.layerFieldNames( layerName ) );
perLayerFields[layerName] = QgsVectorTileUtils::makeQgisFields( fieldNames );
}

const QgsVectorTileFeatures features = decoder.layerFeatures( perLayerFields, QgsCoordinateTransform() );
const QStringList featuresLayerNames = features.keys();
for ( const QString &layerName : featuresLayerNames )
const QgsVectorTileFeatures features = decoder.layerFeatures( perLayerFields, QgsCoordinateTransform() );
const QStringList featuresLayerNames = features.keys();
for ( const QString &layerName : featuresLayerNames )
{
const QgsFields fFields = perLayerFields[layerName];
const QVector<QgsFeature> &layerFeatures = features[layerName];
for ( const QgsFeature &f : layerFeatures )
{
const QgsFields fFields = perLayerFields[layerName];
const QVector<QgsFeature> &layerFeatures = features[layerName];
for ( const QgsFeature &f : layerFeatures )
{
if ( renderContext && mRenderer && !mRenderer->willRenderFeature( f, tileZoom, layerName, *renderContext ) )
continue;
if ( renderContext && mRenderer && !mRenderer->willRenderFeature( f, tileID.zoomLevel(), layerName, *renderContext ) )
continue;

if ( f.geometry().intersects( r ) )
if ( f.geometry().intersects( r ) )
{
bool selectFeature = true;
if ( selectionGeomPrepared )
{
bool selectFeature = true;
if ( selectionGeomPrepared )
switch ( relationship )
{
switch ( relationship )
{
case Qgis::SelectGeometryRelationship::Intersect:
selectFeature = selectionGeomPrepared->intersects( f.geometry().constGet() );
break;
case Qgis::SelectGeometryRelationship::Within:
selectFeature = selectionGeomPrepared->contains( f.geometry().constGet() );
break;
}
case Qgis::SelectGeometryRelationship::Intersect:
selectFeature = selectionGeomPrepared->intersects( f.geometry().constGet() );
break;
case Qgis::SelectGeometryRelationship::Within:
selectFeature = selectionGeomPrepared->contains( f.geometry().constGet() );
break;
}
}

if ( selectFeature )
{
QgsFeature derivedFeature = f;
addDerivedFields( derivedFeature, tileZoom, layerName );
if ( flags & Qgis::SelectionFlag::SingleFeatureSelection )
singleSelectCandidates << derivedFeature;
else
mSelectedFeatures.insert( derivedFeature.id(), derivedFeature );
}
if ( selectFeature )
{
QgsFeature derivedFeature = f;
addDerivedFields( derivedFeature, tileID.zoomLevel(), layerName );
if ( flags & Qgis::SelectionFlag::SingleFeatureSelection )
singleSelectCandidates << derivedFeature;
else
mSelectedFeatures.insert( derivedFeature.id(), derivedFeature );
}
}
}
Expand Down

0 comments on commit cf3aeb5

Please sign in to comment.