Class: QgsMapHitTest

class qgis.core.QgsMapHitTest

Bases: sip.wrapper

Class that runs a hit test with given map settings. Based on the hit test it returns which symbols will be visible on the map - this is useful for content based legend.

QgsMapHitTest(settings: QgsMapSettings, polygon: QgsGeometry = QgsGeometry(), layerFilterExpression: Dict[str, str] = {})

Parameters:
  • settings – Map settings used to evaluate symbols

  • polygon – Polygon geometry to refine the hit test

  • layerFilterExpression – Expression string for each layer id to evaluate in order to refine the symbol selection

QgsMapHitTest(settings: QgsMapSettings, layerFilterExpression: Dict[str, str]) Constructor version used with only expressions to filter symbols (no extent or polygon intersection)

QgsMapHitTest(settings: QgsLayerTreeFilterSettings) Constructor based off layer tree filter settings.

New in version 3.32.

QgsMapHitTest(QgsMapHitTest)

Methods

legendKeyVisible

Tests whether a given legend key is visible for a specified layer.

results

Returns the hit test results, which are a map of layer ID to visible symbol legend keys.

run

Runs the map hit test

symbolVisible

Tests whether a symbol is visible for a specified layer.

legendKeyVisible(self, ruleKey: str, layer: QgsVectorLayer) bool

Tests whether a given legend key is visible for a specified layer.

Parameters:
  • ruleKey (str) – legend rule key

  • layer (QgsVectorLayer) – vector layer

See also

symbolVisible()

Return type:

bool

results(self) object

Returns the hit test results, which are a map of layer ID to visible symbol legend keys.

New in version 3.32.

Return type:

object

run(self)

Runs the map hit test

symbolVisible(self, symbol: QgsSymbol, layer: QgsVectorLayer) bool

Tests whether a symbol is visible for a specified layer.

Parameters:
Return type:

bool