Class: QgsProfilePlotRenderer

Generates and renders elevation profile plots.

This class has two roles:

  1. Extraction and generation of the raw elevation profiles from a list of QgsAbstractProfileSource objects.

  2. Rendering the results

Step 1, involving the generation of the elevation profiles only needs to occur once. This is done via a call to startGeneration(), which commences generation of the profiles from each source in a separate background thread. When the generation is completed for all sources the generationFinished() signal is emitted.

After the profile is generated, it can be rendered. The rendering step may be undertaken multiple times (e.g. to render to different image sizes or data ranges) without having to re-generate the raw profile data.

Added in version 3.26.

Class Hierarchy

Inheritance diagram of qgis.core.QgsProfilePlotRenderer

Base classes

QObject

Methods

asFeatures

Exports the profile results as a set of features.

cancelGeneration

Stop the generation job - does not return until the job has terminated.

cancelGenerationWithoutBlocking

Triggers cancellation of the generation job without blocking.

generateSynchronously

Generate the profile results synchronously in this thread.

identify

Identify results visible at the specified profile point.

invalidateAllRefinableSources

Invalidates previous results from all refinable sources.

invalidateResults

Invalidates the profile results from the source with matching ID.

isActive

Returns True if the generation job is currently running in background.

regenerateInvalidatedResults

Starts a background regeneration of any invalidated results and immediately returns.

render

Renders a portion of the profile using the specified render context.

renderSubsectionsIndicator

Renders the vertices of the profile curve as vertical lines using the specified render context.

renderToImage

Renders a portion of the profile to an image with the given width and height.

replaceSource

Replaces the existing source with matching ID.

setContext

Sets the context in which the profile generation will occur.

setSubsectionsSymbol

Sets the symbol used to draw the subsections.

snapPoint

Snap a point to the results.

sourceIds

Returns the ordered list of source IDs for the sources used by the renderer.

startGeneration

Start the generation job and immediately return.

subsectionsSymbol

Returns the line symbol used to draw the subsections.

waitForFinished

Block until the current job has finished.

zRange

Returns the limits of the retrieved elevation values.

Static Methods

defaultSubSectionsSymbol

Returns the default line symbol to use for subsections lines.

Signals

generationFinished

Emitted when the profile generation is finished (or canceled).

class qgis.core.QgsProfilePlotRenderer[source]

Bases: QObject

__init__(sources: Iterable[QgsAbstractProfileSource], request: QgsProfileRequest)

Constructor for QgsProfilePlotRenderer, using the provided list of profile sources to generate the results.

Parameters:
asFeatures(self, type: Qgis.ProfileExportType, feedback: QgsFeedback | None = None) List[QgsAbstractProfileResults.Feature]

Exports the profile results as a set of features.

Added in version 3.32.

Parameters:
Return type:

List[QgsAbstractProfileResults.Feature]

cancelGeneration(self)[source]

Stop the generation job - does not return until the job has terminated. Does nothing if the generation is not active.

cancelGenerationWithoutBlocking(self)[source]

Triggers cancellation of the generation job without blocking. The generation job will continue to operate until it is able to cancel, at which stage the generationFinished() signal will be emitted. Does nothing if the generation is not active.

static defaultSubSectionsSymbol() QgsLineSymbol | None

Returns the default line symbol to use for subsections lines.

Added in version 3.44.

Return type:

Optional[QgsLineSymbol]

generateSynchronously(self)[source]

Generate the profile results synchronously in this thread. The function does not return until the generation is complete.

This is an alternative to ordinary API (using startGeneration() + waiting for generationFinished() signal). Users are discouraged to use this method unless they have a strong reason for doing it. The synchronous generation blocks the main thread, making the application unresponsive. Also, it is not possible to cancel generation while it is in progress.

Added in version 3.30.

signal generationFinished[source]

Emitted when the profile generation is finished (or canceled).

identify(self, point: QgsProfilePoint, context: QgsProfileIdentifyContext) List[QgsProfileIdentifyResults]

Identify results visible at the specified profile point.

Parameters:
Return type:

List[QgsProfileIdentifyResults]

identify(self, distanceRange: QgsDoubleRange, elevationRange: QgsDoubleRange, context: QgsProfileIdentifyContext) List[QgsProfileIdentifyResults]

Identify results visible within the specified ranges.

Parameters:
Return type:

List[QgsProfileIdentifyResults]

invalidateAllRefinableSources(self)[source]

Invalidates previous results from all refinable sources.

invalidateResults(self, source: QgsAbstractProfileSource | None) bool[source]

Invalidates the profile results from the source with matching ID.

The matching stored source will be deleted and replaced with source.

Returns True if results were previously stored for the matching source and have been invalidated.

Parameters:

source (Optional[QgsAbstractProfileSource])

Return type:

bool

isActive(self) bool[source]

Returns True if the generation job is currently running in background.

Return type:

bool

regenerateInvalidatedResults(self)[source]

Starts a background regeneration of any invalidated results and immediately returns.

Does nothing if the generation is already in progress.

render(self, context: QgsRenderContext, width: float, height: float, distanceMin: float, distanceMax: float, zMin: float, zMax: float, sourceId: str | None = '')[source]

Renders a portion of the profile using the specified render context.

If sourceId is empty then all sources will be rendered, otherwise only the matching source will be rendered.

Parameters:
  • context (QgsRenderContext)

  • width (float)

  • height (float)

  • distanceMin (float)

  • distanceMax (float)

  • zMin (float)

  • zMax (float)

  • sourceId (Optional[str] = '')

renderSubsectionsIndicator(self, context: QgsRenderContext, plotArea: QRectF, distanceMin: float, distanceMax: float, zMin: float, zMax: float)[source]

Renders the vertices of the profile curve as vertical lines using the specified render context. The style of the lines the style corresponds to the symbol defined by setSubsectionsSymbol().

Added in version 3.44.

Parameters:
  • context (QgsRenderContext)

  • plotArea (QRectF)

  • distanceMin (float)

  • distanceMax (float)

  • zMin (float)

  • zMax (float)

renderToImage(self, width: int, height: int, distanceMin: float, distanceMax: float, zMin: float, zMax: float, sourceId: str | None = '', devicePixelRatio: float = 1) QImage[source]

Renders a portion of the profile to an image with the given width and height.

If sourceId is empty then all sources will be rendered, otherwise only the matching source will be rendered.

Parameters:
  • width (int)

  • height (int)

  • distanceMin (float)

  • distanceMax (float)

  • zMin (float)

  • zMax (float)

  • sourceId (Optional[str] = '')

  • devicePixelRatio (float = 1)

Return type:

QImage

replaceSource(self, source: QgsAbstractProfileSource | None)[source]

Replaces the existing source with matching ID.

The matching stored source will be deleted and replaced with source.

Parameters:

source (Optional[QgsAbstractProfileSource])

setContext(self, context: QgsProfileGenerationContext)[source]

Sets the context in which the profile generation will occur.

Depending on the sources present, this may trigger automatically a regeneration of results.

Parameters:

context (QgsProfileGenerationContext)

setSubsectionsSymbol(self, symbol: QgsLineSymbol | None)[source]

Sets the symbol used to draw the subsections. If symbol is None, the subsections are not drawn. Ownership of symbol is transferred.

Added in version 3.44.

Parameters:

symbol (Optional[QgsLineSymbol])

snapPoint(self, point: QgsProfilePoint, context: QgsProfileSnapContext) QgsProfileSnapResult[source]

Snap a point to the results.

Parameters:
Return type:

QgsProfileSnapResult

sourceIds(self) List[str][source]

Returns the ordered list of source IDs for the sources used by the renderer.

Return type:

List[str]

startGeneration(self)[source]

Start the generation job and immediately return. Does nothing if the generation is already in progress.

subsectionsSymbol(self) QgsLineSymbol | None[source]

Returns the line symbol used to draw the subsections.

Added in version 3.44.

Return type:

Optional[QgsLineSymbol]

waitForFinished(self)[source]

Block until the current job has finished.

zRange(self) QgsDoubleRange[source]

Returns the limits of the retrieved elevation values.

Return type:

QgsDoubleRange