2

I have just formed point clusters using ST-DBSCAN, which gave me a single output with all points categorised by the new column "CLUSTER_ID".

My next step is to acquire the centroids of each cluster through the Mean coordinate(s) tool. But it is critical that these centroids have information on the time difference between the earliest and the latest timestamp from their clusters.

For that, I would like to create a new field "time_dif" in the ST-DBSCAN output which will be joined to the centroids later. Values of "time_dif" should be calculated as follows:

  • Within each CLUSTER_ID, take the latest value in the column "time" and subtract it by the earliest datetime value in the same column.
  • All points with the same CLUSTER_ID should have their "time_dif" columns populated with the same difference value
  • Time should be in integers and minutes

Below is a simplified example of what I'm looking for.

enter image description here

How can I populate the "time_dif" field as specified?

1 Answer 1

3

Try this expression in the Field Calculator:

age( -- get time difference
    minimum(to_time("ttime"), "CLUSTER_ID"), -- get the earlier time in the current cluster
    maximum(to_time("ttime"), "CLUSTER_ID") -- get the latest time in the current cluster
    )

It looks like the "ttime" field is a text field, so I added the to_time function to convert it to time and calculate the de difference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.