I am learning pyQGIS and written a script that may solve this issue.
Start with the original dataset but the timestamps converted to integers (Unix time). You can do it with the
epoch() expression in the Field Calculator.
This is my Attributes Table to test:
To create subgroups of the group numbered
2, ordered by the
timestamp values, open the Python Console, show the Editor, and paste the following code:
layername = 'test points'
#Field name to ordering
orderfield = 'timestamp'
#Field name to group
groupfield = 'group'
#Field value to group
groupvalue = 2
#Unique values field
uvf = 'fid'
#get the layer
lyr = QgsProject.instance().mapLayersByName(layername)
lyrcrs = lyr.sourceCrs().authid()
request = QgsFeatureRequest().addOrderBy(orderfield)
iterator = lyr.getFeatures(request)
feats = [i for i in iterator]
#New Attributes Logic
groupscounter = 1
hadchanged = 0
for feat in feats:
if feat[groupfield] == groupvalue:
if hadchanged == 1:
groupscounter += 1
hadchanged = 0
subgroup = groupscounter
hadchanged = 1
subgroup = 0
#Create a memory layer
uri = "Point?crs=" + lyrcrs + \
"&field=" + uvf + ":integer" + \
"&field=" + orderfield + ":integer" + \
"&field=subgroup:integer" + \
mem_layer = QgsVectorLayer(uri,'reordered','memory')
prov = mem_layer.dataProvider()
What are we doing is request the features of the
test points layer, ordered by
In logic we are creating subgroups every time a
group value other than
The output is a new memory layer named
reordered, with the same features as the original layer, its
tiemstamp value and the new subgroups. All values not equal to
2 go to subgroup
Then, you can run the Points to Path tool against that layer.
Any advice about the code will be welcome.