2

I am currently doing fieldwork on little owls. Part of this is noting down on a map where I hear their sounds coming from. These points I later transfer to QGIS (image 1).

enter image description here

Sometimes the owl moves while I'm recording data, so I have two different locations for the same individual (image 2).

enter image description here

I would like to connect these different locations with a line in QGIS. The lines need to be grouped per date, so the line only links the locations of the individual together of one certain date (so not all the locations the individual was heard from on different dates). I hope this makes sense.

How could I do this in QGIS? I've tried points to path, but this connects all the locations of the individual, so not sorted per date.

Matt
  • 16,843
  • 3
  • 21
  • 52
Roos
  • 41
  • 4

2 Answers2

4

(QGIS 3.22.3) In the Points to path tool, you can use an expression in the Path group expression option to group your data.

Click the button on the right of the field to open the expression editor.

enter image description here

Enter this expression. "date" and "indiv" are field names from your point layer, || is the concatenate operator. Be careful with double " and single ' quotes. Double quotes are for field names, single quotes are for strings.

"date" || '_' || "indiv"

It concatenates the date, an underscore, and the individual's ID. The result of the expression would look something like 2022-02-21_1 (and so on for each combination of date and indiv).

enter image description here

You won't see this calculated anywhere (except in the preview in the lower left of the expression editor). But the Paths to points tool will use it to group your points.

The paths are then generated per group.

enter image description here

It just so happens than owl 3 in my randomly generated data set only had a single observation per date and therefore didn't 'move'.


Variation:

For a more explicit version of the same concept (which will work on QGIS versions before the Path group expression option was added), you can use Field Calculator (with the same expression "date" || '_' || "indiv") to generate the groups in a new Text field (called group).

enter image description here

And then select this field in the Group field of the Points to path tool

enter image description here

Matt
  • 16,843
  • 3
  • 21
  • 52
  • Thank you Matt! I will try this out, hopefully it works! – Roos Feb 22 '22 at 15:29
  • I'm sorry Matt, I am afraid I do not understand this completely (I am a real QGIS newbie, I'm sorry). Where can I find the "path group expression option" in the points to path function? And should I then add this expression for every date and every individual that needs to be grouped? – Roos Feb 23 '22 at 12:00
  • No problem, we were all newbies once. I have updated my answer with some clarifications. You only need to make the expression one time. It will be calculated on every row of your attribute table, using the values it finds in the two fields. – Matt Feb 23 '22 at 13:27
  • Hello Matt! I do not see that expression , this is what I see in the points to path tool: link – Roos Feb 24 '22 at 11:34
  • It must be a feature added in a more recent version of QGIS. You can use the second part of my answer in that case, and make the groups with the field calculator (after the title "Variation"). – Matt Feb 24 '22 at 11:35
  • Probably "heardfrom" makes most sense. You may have to test a couple though, to see what it gives you. Do you have times of recordings as well as dates? That would be the best. – Matt Feb 24 '22 at 12:31
  • Thanks Matt! I think it worked! I had to add the "heardfrom" to the group expression (so it's date_heardfrom_indiv now ) and now it works! – Roos Feb 24 '22 at 12:36
  • Oh one more question! Does it update with new paths automatically whenever I add new datapoints, or should I just make a new path every time? – Roos Feb 24 '22 at 12:39
  • You will have to re-run Points to path tool after any changes in the points layer. There are ways to automate such things, but it is out of the scope of this question post. – Matt Feb 24 '22 at 12:42
  • I thought your comment about updating automatically and I have provided an alternative answer. It is purely visual, it doesn't create a data layer so you cannot do any analysis on it, but it will update dynamically as the point layer is changed. – Matt Feb 24 '22 at 17:42
0

To visualise lines between grouped points you can use Geometry Generator on a layer symbol in the point symbology.

enter image description here

Expression:

make_line(
    array_agg(
        expression:=$geometry, 
        group_by:=date||heardfrom||indiv,
        order_by:=heardfrom
    )
)

enter image description here (I added the labels and colours to better visualise the example).

Note:

It is not a perfect solution as outlined in this question, but it will update dynamically as the point layer is edited.

Matt
  • 16,843
  • 3
  • 21
  • 52
  • Thank you very much Matt! I will try this out!

    And if I do want to analysis on the layer, I should rerun the tool everytime? How do I do that? I have tried to find out, but cannot really see it.

    – Roos Feb 25 '22 at 14:44
  • There is no need to rerun this version. It will update automatically if new points are added, or existing points moved. It is just the layer symbology, it doesn't produce any data, and therefore not suitable if you need to do analysis on the lines, but for visualisation purposes it is much easier than the Points to path method. – Matt Feb 25 '22 at 14:45
  • Does this only work with new points I added and not retroactively? Because I just tried it, but it didn't draw the lines between the points I added today. – Roos Feb 25 '22 at 14:55
  • Provided the attributes of the new points meet the conditions for the group then they will be connected. I am doubting if you should have heardfrom as part of the group condition, but I am not familiar with your data (collection). Currently, the points will only be connected if they are the same indiv, same date and same heardfrom. Which means they will not be connected if the owl moved to a different heardfrom area. I am not sure if I am interpreting your data correctly though. – Matt Feb 25 '22 at 15:05