Class: QgsRenderContext¶
- class qgis.core.QgsRenderContext¶
Bases:
QgsTemporalRangeObject
Contains information about the context of a rendering operation.
The context of a rendering operation defines properties such as the conversion ratio between screen and map units, the extents to be rendered etc.
Methods
Clears the specified custom rendering flag.
Returns the list of clipping regions to apply during the render.
Converts a size from map units to the specified units.
Convert meter distances to active MapUnit values for QgsUnitTypes.RenderMetersInMapUnits note When the
sourceCrs()
is geographic, the center of the Extent will be usedConverts a size from the specified units to map units.
Converts a size from the specified units to painter units (pixels).
Returns the current coordinate transform for the context.
Returns the current mask id, which can be used with
maskPainter()
Gets custom rendering flags.
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
Returns
True
if edit markers should be drawn during the render operation.Gets the expression context.
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the layer's CRS).
Returns the geometry to use to clip features at render time.
Gets the filter feature provider used for additional filtering of rendered features.
Returns combination of flags used for rendering.
Returns
True
if rendering operations should use vector operations instead of any faster raster shortcuts.create initialized
QgsRenderContext
instance from givenQgsMapSettings
Creates a default render context given a pixel based QPainter destination.
Returns pointer to the unsegmentized geometry
Returns
True
if the context has any rendered feature handlers.Returns the Gui preview mode.
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.
Returns the original extent of the map being rendered.
Returns the context's map to pixel transform, which transforms between map coordinates and device coordinates.
Returns the mask id provider attached to the context.
Returns a mask QPainter for the render operation.
Returns the destination QPainter for the render operation.
Returns the path resolver for conversion between relative and absolute paths during rendering operations, e.g.
Returns the list of rendered feature handlers to use while rendering map layers.
Returns the renderer map scale.
Returns
True
if the rendering operation has been stopped and any ongoing rendering should be canceled immediately.Returns the scaling factor for the render to convert painter units to physical sizes.
Gets the segmentation tolerance applied when rendering curved geometries
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)
Returns the color to use when rendering selected features.
Sets the current coordinate transform for the context.
Stores a mask id as the "current" one.
Sets a custom rendering flag.
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
Sets whether edit markers should be drawn during the render operation.
Sets the expression context.
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the layer's CRS).
Sets a
geometry
to use to clip features at render time.Set a filter feature provider used for additional filtering of rendered features.
Enable or disable a particular flag (other flags are not affected)
Set combination of flags that will be used for rendering.
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts.
Sets pointer to original (unsegmentized) geometry
Sets GUI preview mode.
Sets the original
extent
of the map being rendered.Sets the context's map to pixel transform, which transforms between map coordinates and device coordinates.
Attaches a mask id provider to the context.
Sets a mask QPainter for the render operation.
Sets the destination QPainter for the render operation.
Sets relevant flags on a destination
painter
, using the flags and settings currently defined for the render context.Sets the path
resolver
for conversion between relative and absolute paths during rendering operations, e.g.Sets the renderer map scale.
Sets whether the rendering operation has been
stopped
and any ongoing rendering should be canceled immediately.Sets the scaling factor for the render to convert painter units to physical sizes.
Sets the segmentation tolerance applied when rendering curved geometries
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)
Sets the
color
to use when rendering selected features.Sets whether vector selections should be shown in the rendered map
Sets the text render
format
, which dictates how text is rendered (e.g.Sets the texture
origin
, which should be used as a brush transform when rendering using QBrush objects.Sets the context's coordinate transform
context
, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.Used to enable or disable advanced effects such as blend modes
Sets whether the rendering optimization (geometry simplification) should be executed
Sets the simplification setting to use when rendering vector layers.
Returns
True
if vector selections should be shown in the rendered mapCheck whether a particular flag is enabled.
Returns the text render format, which dictates how text is rendered (e.g.
Returns the texture origin, which should be used as a brush transform when rendering using QBrush objects.
Returns the context's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.
Returns
True
if advanced effects such as blend modes such be usedReturns
True
if the rendering optimization (geometry simplification) can be executedReturns the simplification settings to use when rendering vector layers.
Attributes
- Antialiasing = 128¶
- ApplyClipAfterReprojection = 32768¶
- ApplyScalingWorkaroundForTextRendering = 8192¶
- DrawEditingInfo = 1¶
- DrawSelection = 16¶
- DrawSymbolBounds = 32¶
- class Flag¶
Bases:
int
- class Flags¶
- class Flags(Union[QgsRenderContext.Flags, QgsRenderContext.Flag]) None
- class Flags(QgsRenderContext.Flags) None
Bases:
sip.wrapper
- ForceVectorOutput = 2¶
- LosslessImageRendering = 4096¶
- Render3DMap = 16384¶
- RenderBlocking = 1024¶
- RenderMapTile = 64¶
- RenderPartialOutput = 256¶
- RenderPreviewJob = 512¶
- RenderSymbolPreview = 2048¶
- TextFormatAlwaysOutlines = 0¶
- TextFormatAlwaysText = 1¶
- class TextRenderFormat¶
Bases:
int
- UseAdvancedEffects = 4¶
- UseRenderingOptimization = 8¶
- clearCustomRenderingFlag(self, flag: str)¶
Clears the specified custom rendering flag.
- Parameters
flag (str) – the flag name
See also
New in version 3.12.
- clippingRegions(self) List[QgsMapClippingRegion] ¶
Returns the list of clipping regions to apply during the render.
These regions are always in the final destination CRS for the map.
New in version 3.16.
- Return type
List[QgsMapClippingRegion]
- convertFromMapUnits(self, sizeInMapUnits: float, outputUnit: QgsUnitTypes.RenderUnit) float ¶
Converts a size from map units to the specified units.
See also
New in version 3.0.
- Parameters
sizeInMapUnits (float) –
outputUnit (QgsUnitTypes.RenderUnit) –
- Return type
float
- convertMetersToMapUnits(self, meters: float) float ¶
Convert meter distances to active MapUnit values for QgsUnitTypes.RenderMetersInMapUnits note When the
sourceCrs()
is geographic, the center of the Extent will be usedNew in version 3.0.
- Parameters
meters (float) –
- Return type
float
- convertToMapUnits(self, size: float, unit: QgsUnitTypes.RenderUnit, scale: QgsMapUnitScale = QgsMapUnitScale()) float ¶
Converts a size from the specified units to map units. The conversion respects the limits specified by the optional scale parameter.
See also
New in version 3.0.
- Parameters
size (float) –
unit (QgsUnitTypes.RenderUnit) –
scale (
QgsMapUnitScale
= QgsMapUnitScale()) –
- Return type
float
- convertToPainterUnits(self, size: float, unit: QgsUnitTypes.RenderUnit, scale: QgsMapUnitScale = QgsMapUnitScale()) float ¶
Converts a size from the specified units to painter units (pixels). The conversion respects the limits specified by the optional scale parameter.
See also
New in version 3.0.
- Parameters
size (float) –
unit (QgsUnitTypes.RenderUnit) –
scale (
QgsMapUnitScale
= QgsMapUnitScale()) –
- Return type
float
- coordinateTransform(self) QgsCoordinateTransform ¶
Returns the current coordinate transform for the context.
This represents the coordinate transform required to transform a layer which is being rendered back to the CRS of the rendered map. If no coordinate transformation is required, or the render context is not associated with a map layer render, then an invalid coordinate transformation is returned.
See also
- Return type
- currentMaskId(self) int ¶
Returns the current mask id, which can be used with
maskPainter()
See also
See also
New in version 3.12.
- Return type
int
- customRenderingFlags(self) Dict[str, Any] ¶
Gets custom rendering flags. Layers might honour these to alter their rendering.
- Return type
Dict[str, Any]
- Returns
a map of custom flags
See also
New in version 3.12.
- disabledSymbolLayers(self) Set[QgsSymbolLayer] ¶
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.
Returns the list of disabled symbol layers.
See also
See also
New in version 3.12.
- Return type
Set[QgsSymbolLayer]
- distanceArea(self) QgsDistanceArea ¶
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
New in version 3.0.
- Return type
- drawEditingInformation(self) bool ¶
Returns
True
if edit markers should be drawn during the render operation.See also
- Return type
bool
- expressionContext(self) QgsExpressionContext ¶
Gets the expression context. This context should be used for all expression evaluation associated with this render context.
See also
New in version 2.12.
- Return type
- extent(self) QgsRectangle ¶
When rendering a map layer, calling this method returns the “clipping” extent for the layer (in the layer’s CRS).
This extent is a “worst-case” scenario, which is guaranteed to cover the complete visible portion of the layer when it is rendered to a map. It is often larger than the actual visible portion of that layer.
Warning
For some layers, depending on the visible extent and the coordinate transforms involved, this extent will represent the entire globe. This method should never be used to determine the actual visible extent of a map render.
See also
See also
- Return type
- featureClipGeometry(self) QgsGeometry ¶
Returns the geometry to use to clip features at render time.
When vector features are rendered, they should be clipped to this geometry.
Warning
The clipping must take effect for rendering the feature’s symbol only, and should never be applied directly to the feature being rendered. Doing so would impact the results of rendering rules which rely on feature geometry, such as a rule-based renderer using the feature’s area.
See also
New in version 3.16.
- Return type
- featureFilterProvider(self) QgsFeatureFilterProvider ¶
Gets the filter feature provider used for additional filtering of rendered features.
- Return type
- Returns
the filter feature provider
See also
New in version 2.14.
- flags(self) QgsRenderContext.Flags ¶
Returns combination of flags used for rendering.
New in version 2.14.
- Return type
- forceVectorOutput(self) bool ¶
Returns
True
if rendering operations should use vector operations instead of any faster raster shortcuts.See also
- Return type
bool
- fromMapSettings(mapSettings: QgsMapSettings) QgsRenderContext ¶
create initialized
QgsRenderContext
instance from givenQgsMapSettings
New in version 2.4.
- Parameters
mapSettings (QgsMapSettings) –
- Return type
- fromQPainter(painter: QPainter) QgsRenderContext ¶
Creates a default render context given a pixel based QPainter destination. If no painter is specified or the painter has no device, then a default DPI of 88 will be assumed.
New in version 3.0.
- Parameters
painter (QPainter) –
- Return type
- geometry(self) QgsAbstractGeometry ¶
Returns pointer to the unsegmentized geometry
- Return type
- hasRenderedFeatureHandlers(self) bool ¶
Returns
True
if the context has any rendered feature handlers.See also
New in version 3.10.
- Return type
bool
- isGuiPreview(self) bool ¶
Returns the Gui preview mode. GUI preview mode is used to change the behavior of some renderings when they are done to preview of symbology in the GUI. This is especially used to display mask symbol layers rather than painting them in a mask painter, which is not meant to be visible, by definition.
See also
See also
New in version 3.12.
- Return type
bool
- isSymbolLayerEnabled(self, layer: QgsSymbolLayer) bool ¶
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.
Checks whether a given symbol layer has been disabled for the current pass.
See also
See also
New in version 3.12.
- Parameters
layer (QgsSymbolLayer) –
- Return type
bool
- mapExtent(self) QgsRectangle ¶
Returns the original extent of the map being rendered.
Unlike
extent()
, this extent is always in the final destination CRS for the map render and represents the exact bounds of the map being rendered.See also
See also
New in version 3.4.8.
- Return type
- mapToPixel(self) QgsMapToPixel ¶
Returns the context’s map to pixel transform, which transforms between map coordinates and device coordinates.
See also
- Return type
- maskIdProvider(self) QgsMaskIdProvider ¶
Returns the mask id provider attached to the context.
See also
New in version 3.12.
- Return type
- maskPainter(self, id: int = 0) QPainter ¶
Returns a mask QPainter for the render operation. Multiple mask painters can be defined, each with a unique identifier. None is returned if a mask painter with the given identifier does not exist. This is currently used to implement selective masking.
See also
See also
New in version 3.12.
- Parameters
id (int = 0) –
- Return type
QPainter
- painter(self) QPainter ¶
Returns the destination QPainter for the render operation.
See also
- Return type
QPainter
- pathResolver(self) QgsPathResolver ¶
Returns the path resolver for conversion between relative and absolute paths during rendering operations, e.g. for resolving relative symbol paths.
See also
New in version 3.0.
- Return type
- renderedFeatureHandlers(self) List[QgsRenderedFeatureHandlerInterface] ¶
Returns the list of rendered feature handlers to use while rendering map layers.
See also
New in version 3.10.
- Return type
- rendererScale(self) float ¶
Returns the renderer map scale. This will match the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render.
See also
- Return type
float
- renderingStopped(self) bool ¶
Returns
True
if the rendering operation has been stopped and any ongoing rendering should be canceled immediately.See also
- Return type
bool
- scaleFactor(self) float ¶
Returns the scaling factor for the render to convert painter units to physical sizes. This is usually equal to the number of pixels per millimeter.
See also
- Return type
float
- segmentationTolerance(self) float ¶
Gets the segmentation tolerance applied when rendering curved geometries
See also
- Return type
float
- segmentationToleranceType(self) QgsAbstractGeometry.SegmentationToleranceType ¶
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)
See also
- Return type
- selectionColor(self) QColor ¶
Returns the color to use when rendering selected features.
See also
- Return type
QColor
- setCoordinateTransform(self, t: QgsCoordinateTransform)¶
Sets the current coordinate transform for the context.
This represents the coordinate transform required to transform the layer which is being rendered back to the CRS of the rendered map.
Set to an invalid
QgsCoordinateTransform
to indicate that no transformation is required.See also
- Parameters
t (QgsCoordinateTransform) –
- setCurrentMaskId(self, id: int)¶
Stores a mask id as the “current” one.
See also
New in version 3.12.
- Parameters
id (int) –
- setCustomRenderingFlag(self, flag: str, value: Any)¶
Sets a custom rendering flag. Layers might honour these to alter their rendering.
- Parameters
flag (str) – the flag name
value (Any) – the flag value
See also
New in version 3.12.
- setDisabledSymbolLayers(self, symbolLayers: Iterable[QgsSymbolLayer])¶
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabled.
Sets the list of disabled symbol layers.
See also
See also
New in version 3.12.
- Parameters
symbolLayers (Iterable[QgsSymbolLayer]) –
- setDistanceArea(self, distanceArea: QgsDistanceArea)¶
A general purpose distance and area calculator, capable of performing ellipsoid based calculations. Will be used to convert meter distances to active MapUnit values for QgsUnitTypes.RenderMetersInMapUnits
New in version 3.0.
- Parameters
distanceArea (QgsDistanceArea) –
- setDrawEditingInformation(self, b: bool)¶
Sets whether edit markers should be drawn during the render operation.
See also
- Parameters
b (bool) –
- setExpressionContext(self, context: QgsExpressionContext)¶
Sets the expression context. This context is used for all expression evaluation associated with this render context.
See also
New in version 2.12.
- Parameters
context (QgsExpressionContext) –
- setExtent(self, extent: QgsRectangle)¶
When rendering a map layer, calling this method sets the “clipping” extent for the layer (in the layer’s CRS).
This extent should be a “worst-case” scenario, which is guaranteed to completely cover the entire visible portion of the layer when it is rendered to the map. It may be larger than the actual visible area, but MUST contain at least the entire visible area.
See also
See also
- Parameters
extent (QgsRectangle) –
- setFeatureClipGeometry(self, geometry: QgsGeometry)¶
Sets a
geometry
to use to clip features at render time.Note
This is not usually set directly, but rather specified by calling QgsMapSettings:
addClippingRegion()
prior to constructing a QgsRenderContext.See also
New in version 3.16.
- Parameters
geometry (QgsGeometry) –
- setFeatureFilterProvider(self, ffp: QgsFeatureFilterProvider)¶
Set a filter feature provider used for additional filtering of rendered features.
- Parameters
ffp (QgsFeatureFilterProvider) – the filter feature provider
See also
New in version 2.14.
- setFlag(self, flag: QgsRenderContext.Flag, on: bool = True)¶
Enable or disable a particular flag (other flags are not affected)
New in version 2.14.
- Parameters
flag (QgsRenderContext.Flag) –
on (bool = True) –
- setFlags(self, flags: Union[QgsRenderContext.Flags, QgsRenderContext.Flag])¶
Set combination of flags that will be used for rendering.
New in version 2.14.
- Parameters
flags (Union[QgsRenderContext.Flags) –
- setForceVectorOutput(self, force: bool)¶
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts.
See also
- Parameters
force (bool) –
- setGeometry(self, geometry: QgsAbstractGeometry)¶
Sets pointer to original (unsegmentized) geometry
- Parameters
geometry (QgsAbstractGeometry) –
- setIsGuiPreview(self, preview: bool)¶
Sets GUI preview mode. GUI preview mode is used to change the behavior of some renderings when they are done to preview of symbology in the GUI. This is especially used to display mask symbol layers rather than painting them in a mask painter, which is not meant to be visible, by definition.
See also
New in version 3.12.
- Parameters
preview (bool) –
- setMapExtent(self, extent: QgsRectangle)¶
Sets the original
extent
of the map being rendered.Unlike
setExtent()
, this extent is always in the final destination CRS for the map render and represents the exact bounds of the map being rendered.See also
See also
New in version 3.4.8.
- Parameters
extent (QgsRectangle) –
- setMapToPixel(self, mtp: QgsMapToPixel)¶
Sets the context’s map to pixel transform, which transforms between map coordinates and device coordinates.
See also
- Parameters
mtp (QgsMapToPixel) –
- setMaskIdProvider(self, provider: QgsMaskIdProvider)¶
Attaches a mask id provider to the context. It will allow some rendering operations to set the current mask id based on the context (label layer names and label rules for instance).
See also
See also
See also
New in version 3.12.
- Parameters
provider (QgsMaskIdProvider) –
- setMaskPainter(self, p: QPainter, id: int = 0)¶
Sets a mask QPainter for the render operation. Ownership of the painter is not transferred and the QPainter must stay alive for the duration of any rendering operations. Multiple mask painters can be defined and the second parameter gives a unique identifier to each one.
See also
- Parameters
p (QPainter) –
id (int = 0) –
- setPainter(self, p: QPainter)¶
Sets the destination QPainter for the render operation. Ownership of the painter is not transferred and the QPainter destination must stay alive for the duration of any rendering operations.
See also
- Parameters
p (QPainter) –
- setPainterFlagsUsingContext(self, painter: QPainter = None)¶
Sets relevant flags on a destination
painter
, using the flags and settings currently defined for the render context.If no
painter
is specified, then the flags will be applied to the render context’spainter()
.New in version 3.16.
- Parameters
painter (QPainter = None) –
- setPathResolver(self, resolver: QgsPathResolver)¶
Sets the path
resolver
for conversion between relative and absolute paths during rendering operations, e.g. for resolving relative symbol paths.See also
New in version 3.0.
- Parameters
resolver (QgsPathResolver) –
- setRendererScale(self, scale: float)¶
Sets the renderer map scale. This should match the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render.
See also
- Parameters
scale (float) –
- setRenderingStopped(self, stopped: bool)¶
Sets whether the rendering operation has been
stopped
and any ongoing rendering should be canceled immediately.See also
- Parameters
stopped (bool) –
- setScaleFactor(self, factor: float)¶
Sets the scaling factor for the render to convert painter units to physical sizes. This should usually be equal to the number of pixels per millimeter.
See also
- Parameters
factor (float) –
- setSegmentationTolerance(self, tolerance: float)¶
Sets the segmentation tolerance applied when rendering curved geometries
- Parameters
tolerance (float) – the segmentation tolerance
See also
See also
- setSegmentationToleranceType(self, type: QgsAbstractGeometry.SegmentationToleranceType)¶
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)
- Parameters
type (QgsAbstractGeometry.SegmentationToleranceType) – the segmentation tolerance typename
See also
See also
- setSelectionColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])¶
Sets the
color
to use when rendering selected features.See also
- Parameters
color (Union[QColor) –
- setShowSelection(self, showSelection: bool)¶
Sets whether vector selections should be shown in the rendered map
- Parameters
showSelection (bool) – set to
True
if selections should be shown
See also
See also
New in version 2.4.
- setTextRenderFormat(self, format: QgsRenderContext.TextRenderFormat)¶
Sets the text render
format
, which dictates how text is rendered (e.g. as paths or real text objects).See also
New in version 3.4.3.
- Parameters
format (QgsRenderContext.TextRenderFormat) –
- setTextureOrigin(self, origin: Union[QPointF, QPoint])¶
Sets the texture
origin
, which should be used as a brush transform when rendering using QBrush objects.See also
New in version 3.16.
- Parameters
origin (Union[QPointF) –
- setTransformContext(self, context: QgsCoordinateTransformContext)¶
Sets the context’s coordinate transform
context
, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.See also
New in version 3.0.
- Parameters
context (QgsCoordinateTransformContext) –
- setUseAdvancedEffects(self, enabled: bool)¶
Used to enable or disable advanced effects such as blend modes
See also
- Parameters
enabled (bool) –
- setUseRenderingOptimization(self, enabled: bool)¶
Sets whether the rendering optimization (geometry simplification) should be executed
See also
- Parameters
enabled (bool) –
- setVectorSimplifyMethod(self, simplifyMethod: QgsVectorSimplifyMethod)¶
Sets the simplification setting to use when rendering vector layers.
This can be used to specify simplification methods to apply during map exports and renders, e.g. to allow vector layers to be simplified to an appropriate maximum level of detail during PDF exports or to speed up layer rendering
The default is to use no simplification.
See also
New in version 2.4.
- Parameters
simplifyMethod (QgsVectorSimplifyMethod) –
- showSelection(self) bool ¶
Returns
True
if vector selections should be shown in the rendered map- Return type
bool
- Returns
True
if selections should be shown
See also
See also
New in version 2.4.
- testFlag(self, flag: QgsRenderContext.Flag) bool ¶
Check whether a particular flag is enabled.
New in version 2.14.
- Parameters
flag (QgsRenderContext.Flag) –
- Return type
bool
- textRenderFormat(self) QgsRenderContext.TextRenderFormat ¶
Returns the text render format, which dictates how text is rendered (e.g. as paths or real text objects).
See also
New in version 3.4.3.
- Return type
- textureOrigin(self) QPointF ¶
Returns the texture origin, which should be used as a brush transform when rendering using QBrush objects.
See also
New in version 3.16.
- Return type
QPointF
- transformContext(self) QgsCoordinateTransformContext ¶
Returns the context’s coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.
See also
New in version 3.0.
- Return type
- useAdvancedEffects(self) bool ¶
Returns
True
if advanced effects such as blend modes such be usedSee also
- Return type
bool
- useRenderingOptimization(self) bool ¶
Returns
True
if the rendering optimization (geometry simplification) can be executedSee also
- Return type
bool
- vectorSimplifyMethod(self) QgsVectorSimplifyMethod ¶
Returns the simplification settings to use when rendering vector layers.
The default is to use no simplification.
See also
New in version 2.4.
- Return type