QGIS Temporal Controller is a powerful successor of TimeManager. Temporal Controller is a new core feature of the current development version and will be shipped with the 3.14 release. This post demonstrates two key advantages of this new temporal support:
- Expression support for defining start and end timestamps
- Integration into the PyQGIS API
These features come in very handy in many use cases. For example, they make it much easier to create animations from folders full of GPS tracks since the files can now be loaded and configured automatically:
All tracks start at the same location but at different times. (Kudos for Andrew Fletcher for recordings these tracks and sharing them with me!) To create an animation that shows all tracks start simultaneously, we need to synchronize them. This synchronization can be achieved on-the-fly by subtracting the start time from all track timestamps using an expression:
directory = "E:/Google Drive/QGIS_Course/05_TimeManager/Example_Dayrides/" def load_and_configure(filename): path = os.path.join(directory, filename) uri = 'file:///' + path + "?type=csv&escape=&useHeader=No&detectTypes=yes" uri = uri + "&crs=EPSG:4326&xField=field_3&yField=field_2" vlayer = QgsVectorLayer(uri, filename, "delimitedtext") QgsProject.instance().addMapLayer(vlayer) mode = QgsVectorLayerTemporalProperties.ModeFeatureDateTimeStartAndEndFromExpressions expression = """to_datetime(field_1) - make_interval(seconds:=minimum(epoch(to_datetime("field_1")))/1000) """ tprops = vlayer.temporalProperties() tprops.setStartExpression(expression) tprops.setEndExpression(expression) # optional tprops.setMode(mode) tprops.setIsActive(True) for filename in os.listdir(directory): if filename.endswith(".csv"): load_and_configure(filename)
The above script loads all CSV files from the given directory (field_1 is the timestamp, field_2 is y, and field_3 is x), enables sets the start and end expression as well as the corresponding temporal control mode and finally activates temporal rendering. The resulting config can be verified in the layer properties dialog:
To adapt this script to other datasets, it’s sufficient to change the file directory and revisit the layer uri definition as well as the field names referenced in the expression.
This post is part of a series. Read more about movement data in GIS.