8

I have a layer with the coordinates of animals from a field experiment. Apart from other attributes the layer also contains the animals' unique ID and a timestamp. I want to know the travelled distance for each individual in a given time frame (e.g. 1 - 5 days).

I tried the points to paths tool but was only able to create paths between all points.

How can I measure the travelled distance and add that information to my attribute table?

Attribute table

Tool settings

Result

Result with SpatiaLite

0

3 Answers 3

10

Points to path has a 'group' expression optional setting

Use this as your unique Id

Order expression being the timestamp.

Using this, you should get one line for each Id with the Id as an attribute

enter image description here

enter image description here

4
  • Thank you for your reply. I tried that already with the result that every point becomes connected by the same path. What I'm looking for are paths between points with the same ID.
    – Simon
    Commented Mar 2, 2023 at 15:28
  • See updated answer with screenshots, waht are you doing different ?
    – Kasper
    Commented Mar 2, 2023 at 17:54
  • Thanks for the edit and sorry for the late reply! Unfortunately it still doesn't work for me. The "order expression" doesn't seem to work. Maybe it's my formating? It'll add pictures as soon as I find out how.
    – Simon
    Commented Mar 6, 2023 at 11:05
  • 1
    What is the Field type for your Datum field ? It should be of a date type to be properly interpreted with the proper ordering. You can try checking the 'sort text containing number', won't probably solve things, but if at least you are getting multiple lines it will be a good start
    – Kasper
    Commented Mar 6, 2023 at 15:28
7

You can use spatialite.

Make sure you are using a projected coordinate system, if not reproject or the distances will be measured in degrees.

Export the point layer to a spatialite database by right-click - Export - Save features as.

Connect to the database in DB Manager: enter image description here

Execute this query in the SQL Window, after you have changed tracking to the name of your layer and 3006 to the srid you are using:

with cte as (
select  tag_id, datum,
        lag(datum,1,0) over(partition by tag_id order by datum) previous_date,
        st_distance(lag(geometry,1,0) over(partition by tag_id order by datum), geometry) distance_traveled,
        SetSRID(makeline(lag(geometry,1,0) over(partition by tag_id order by datum), geometry), 3006) as geometry
from tracking)

select row_number() over() as id, *, distance_traveled/((julianday(datum)-julianday(previous_date))*86400) as speed_mps
from cte
where distance_traveled is not null

enter image description here

LAG, julianday

0
2

I would have thought that Kasper's answer would be correct, Simon, but I also find that your question is a little confusing. Perhaps you should try the PointsToPaths plugin (note the plural "Paths"). It has added functionality beyond the installed "Points to path" tool.

In particular, try the plugin's "Line per Vertex" checkbox. For more details on PointstoPaths see my previous answer.

1
  • Pardon but I can't find the PointsToPaths plugin. I'm using QGIS Desktop 3.28.3 on Windows 10.
    – Simon
    Commented Mar 6, 2023 at 11:20

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.