Class: QgsMapClippingUtils

Utility functions for use when clipping map renders.

Added in version 3.16.

Static Methods

calculateFeatureIntersectionGeometry

Returns the geometry representing the intersection of clipping regions from context which should be used to clip individual feature geometries prior to rendering.

calculateFeatureRequestGeometry

Returns the geometry representing the intersection of clipping regions from context.

calculateLabelIntersectionGeometry

Returns the geometry representing the intersection of clipping regions from context which should be used to clip individual feature geometries while registering them with labeling engines.

calculatePainterClipRegion

Returns a QPainterPath representing the intersection of clipping regions from context which should be used to clip the painter during rendering of a layer of the specified layerType.

collectClippingRegionsForLayer

Collects the list of map clipping regions from a context which apply to a map layer.

class qgis.core.QgsMapClippingUtils[source]

Bases: object

static calculateFeatureIntersectionGeometry(regions: Iterable[QgsMapClippingRegion], context: QgsRenderContext)[source]

Returns the geometry representing the intersection of clipping regions from context which should be used to clip individual feature geometries prior to rendering.

The returned geometry will be automatically reprojected into the same CRS as the source layer, ready for use for clipping features.

Parameters:
  • regions (Iterable[QgsMapClippingRegion]) – list of clip regions which apply to the layer

  • context (QgsRenderContext) -> (QgsGeometry) – a render context

  • shouldClip – will be set to True if layer’s features should be filtered, i.e. one or more clipping regions applies to the layer

Returns:

combined clipping region for use when rendering features

static calculateFeatureRequestGeometry(regions: Iterable[QgsMapClippingRegion], context: QgsRenderContext)[source]

Returns the geometry representing the intersection of clipping regions from context.

The returned geometry will be automatically reprojected into the same CRS as the source layer, ready for use for filtering a feature request.

Parameters:
  • regions (Iterable[QgsMapClippingRegion]) – list of clip regions which apply to the layer

  • context (QgsRenderContext) -> (QgsGeometry) – a render context

  • shouldFilter – will be set to True if layer’s features should be filtered, i.e. one or more clipping regions applies to the layer

Returns:

combined clipping region for use when filtering features to render

static calculateLabelIntersectionGeometry(regions: Iterable[QgsMapClippingRegion], context: QgsRenderContext)[source]

Returns the geometry representing the intersection of clipping regions from context which should be used to clip individual feature geometries while registering them with labeling engines.

The returned geometry will be automatically reprojected into the same CRS as the source layer, ready for use for clipping features.

Parameters:
  • regions (Iterable[QgsMapClippingRegion]) – list of clip regions which apply to the layer

  • context (QgsRenderContext) -> (QgsGeometry) – a render context

  • shouldClip – will be set to True if layer’s features should be clipped for labeling, i.e. one or more clipping regions applies to the layer

Returns:

combined clipping region for use when labeling features

static calculatePainterClipRegion(regions: Iterable[QgsMapClippingRegion], context: QgsRenderContext, layerType: Qgis.LayerType)[source]

Returns a QPainterPath representing the intersection of clipping regions from context which should be used to clip the painter during rendering of a layer of the specified layerType.

The returned coordinates are in painter coordinates for the destination context.

Parameters:
  • regions (Iterable[QgsMapClippingRegion]) – list of clip regions which apply to the layer

  • context (QgsRenderContext) – a render context

  • shouldClip – will be set to True if the clipping path should be applied

  • layerType (Qgis.LayerType) -> (QPainterPath) – the layer type to filter

Returns:

combined painter clipping region for use when rendering maps

static collectClippingRegionsForLayer(context: QgsRenderContext, layer: QgsMapLayer | None) List[QgsMapClippingRegion]

Collects the list of map clipping regions from a context which apply to a map layer.

Parameters:
Return type:

List[QgsMapClippingRegion]