Class: QgsTemporalUtils

Contains utility methods for working with temporal layers and projects.

Added in version 3.14.

Static Methods

calculateDateTimesFromISO8601

Calculates a complete list of datetimes from a ISO8601 string containing a duration (eg "2021-03-23T00:00:00Z/2021-03-24T12:00:00Z/PT12H").

calculateDateTimesUsingDuration

Calculates a complete list of datetimes between start and end, using the specified ISO8601 duration string (eg "PT12H").

calculateFrameTime

Calculates the frame time for an animation.

calculateTemporalRangeForProject

Calculates the temporal range for a project.

exportAnimation

Exports animation frames by rendering the map to multiple destination images.

usedTemporalRangesForProject

Calculates all temporal ranges which are in use for a project.

class qgis.core.QgsTemporalUtils[source]

Bases: object

class AnimationExportSettings

Bases: object

Contains settings relating to exporting animations

animationRange: QgsDateTimeRange

Dictates the overall temporal range of the animation.

availableTemporalRanges: List[QgsDateTimeRange]

Contains the list of all available temporal ranges which have data available.

The list can be a list of non-contiguous ranges (i.e. containing gaps) which together describe the complete range of times which contain data.

This list is required whenever the QgsUnitTypes.TemporalIrregularStep interval is used for an animation.

Added in version 3.30.

decorations: List[QgsMapDecoration]

List of decorations to draw onto exported frames.

fileNameTemplate: str

The filename template for exporting the frames.

This must be in format prefix####.format, where number of ``# characters represents how many 0's should be left-padded to the frame number e.g. ``my###.jpg will create frames my001.jpg, my002.jpg, etc

frameDuration: QgsInterval

Duration of individual export frames

frameRate: float

Target animation frame rate in frames per second.

Added in version 3.26.

outputDirectory: str

Destination directory for created image files.

static calculateDateTimesFromISO8601(string: str | None, maxValues: int = -1)

Calculates a complete list of datetimes from a ISO8601 string containing a duration (eg “2021-03-23T00:00:00Z/2021-03-24T12:00:00Z/PT12H”).

Parameters:
  • string (Optional[str]) – ISO8601 compatible string

  • maxValues (int = -1) -> (List[QDateTime]) – maximum number of values to return, or -1 to return all values

Returns:

  • calculated list of date times

  • ok: True if string was successfully parsed and date times could be calculated

  • maxValuesExceeded: True if the maximum number of values to return was exceeded

Added in version 3.20.

static calculateDateTimesUsingDuration(start: QDateTime | datetime.datetime, end: QDateTime | datetime.datetime, duration: str | None, maxValues: int = -1)

Calculates a complete list of datetimes between start and end, using the specified ISO8601 duration string (eg “PT12H”).

Parameters:
  • start (Union[QDateTime, datetime.datetime]) – start date time

  • end (Union[QDateTime, datetime.datetime]) – end date time

  • duration (Optional[str]) – ISO8601 duration string

  • maxValues (int = -1) -> (List[QDateTime]) – maximum number of values to return, or -1 to return all values

Returns:

  • calculated list of date times

  • ok: True if duration was successfully parsed and date times could be calculated

  • maxValuesExceeded: True if the maximum number of values to return was exceeded

Added in version 3.20.

static calculateFrameTime(start: QDateTime | datetime.datetime, frame: int, interval: QgsInterval) QDateTime[source]

Calculates the frame time for an animation.

If the interval original duration is fractional or interval original unit is unknown (QgsUnitTypes.TemporalUnit.TemporalUnknownUnit), then QgsInterval is used to determine the duration of the frame. This uses average durations for months and years.

Otherwise, we use QDateTime to advance by the exact duration of the current month or year. So a time step of 1.5 months will result in a duration of 45 days, but a time step of 1 month will result in a duration that depends upon the number of days in the current month.

Parameters:
  • start (Union[QDateTime, datetime.datetime]) – time of the animation

  • frame (int) – number

  • interval (QgsInterval) – duration of the animation

Return type:

QDateTime

Returns:

The calculated datetime for the frame.

Added in version 3.18.

static calculateTemporalRangeForProject(project: QgsProject | None) QgsDateTimeRange[source]

Calculates the temporal range for a project.

This method considers the temporal range available from layers contained within the project and returns the maximal combined temporal extent of these layers.

Parameters:

project (Optional[QgsProject])

Return type:

QgsDateTimeRange

static exportAnimation(mapSettings: QgsMapSettings, settings: QgsTemporalUtils.AnimationExportSettings, feedback: QgsFeedback | None = None)[source]

Exports animation frames by rendering the map to multiple destination images.

The mapSettings argument dictates the overall map settings such as extent and size, while animation and export specific settings are specified via the settings argument.

An optional feedback argument can be used to provide progress reports and cancellation support.

Parameters:
Returns:

  • True if the export was successful.

  • error: a descriptive error message if the export fails

static usedTemporalRangesForProject(project: QgsProject | None) List[QgsDateTimeRange]

Calculates all temporal ranges which are in use for a project.

This method considers the temporal range available from layers contained within the project and returns a list of ranges which cover only the temporal ranges which are actually in use by layers in the project.

The returned list may be non-contiguous and have gaps in the ranges. The ranges are sorted in ascending order.

Added in version 3.20.

Parameters:

project (Optional[QgsProject])

Return type:

List[QgsDateTimeRange]