3

I'm working with QGIS 3.22.11-Białowieża and I've got a point layer that represents the migration route of a bird species. Each point has the following attributes:

  • trip that identifies a single trip (all points of a certain individual and route -northwards or southwards- have the same value for that field)
  • time_stamp that holds date for that position
  • day_night that indicates whether the position was obtained during day or night time.

Using the Point to Path algorithm I can easily represent each migration route, using the trip attribute as grouping expression and the time_stamp as the order expression. But I need to represent in different colours the night and day stretches of each route, as the points in the image below, and the point-to-path algorithm doesn't seem to be able to hold that variable (only the trip id and the begin and end date).

enter image description here

Data for this example can be downloaded here.

I've found this thread with some hints, but my knowledge of Python is still too limited. Is there a way or workaround to do that representation?

2
  • 2
    You state that your data contains the field "..time_stamp that holds date and time for that position..." However, when I download your data I do not see that field. Instead I see the field date_time, which only contains the date - not time. It seems to me that having the time is required because the bird travels sequentially along many points during each day. Did I miss something?
    – Stu Smith
    Commented Dec 3, 2022 at 18:27
  • You're right @StuSmith. Edited
    – jpinilla
    Commented Dec 3, 2022 at 19:27

1 Answer 1

5

Divide the line in segments and assign each segment the daynight value of the closest point:

  1. Explode lines

  2. Add an attribute with field calculator: overlay_touches ('foo_points', daynight)[0]

  3. Assign different colors based on this attribute with Categorized layer styling.

Even easier, I introduced the expression directly in the Categorized styling dialog, thus doing step 2 and 3 in a single step:

enter image description here

If you want to filter to catch only points with the same trip id (what seems not necessary, as long as you don't have points belonging to different trips in exactly the same spot, what seems unlikely), it's a bit more complicated. Unfortunately, filtering inside overlay functions in QGIS 3.28 still does not work as described here. But you can use this expression instead:

array_sort (
    array_foreach (
        overlay_touches ('foo_points', $id),
        if (
            attribute (get_feature_by_id ('foo_points',@element), 'trip') = trip,
            attribute (get_feature_by_id ('foo_points', @element), 'daynight'),
            ''
        )
    ),0
)[0]
4
  • And what would be the filter so the overlay_touches function only affected points with the same trip value as the exploded line?
    – jpinilla
    Commented Dec 3, 2022 at 17:24
  • overlay_touches anyhow only finds points that touch the line, so I guess you don't have points of different trip in exactly the same spot, do you?
    – Babel
    Commented Dec 3, 2022 at 17:29
  • I honestly don't know. It is just to work on the safe side.
    – jpinilla
    Commented Dec 3, 2022 at 17:54
  • See updated answer
    – Babel
    Commented Dec 3, 2022 at 18:02

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.