I have a set of lines consisting of several single object LineStrings. These line can be collected to routes by attribute, e.g. a street consisting of multiple lines from crossing to crossing, but they all have the same street name.
I can query the start and endpoints of a route with the following virtual layer query:
select id, sts as route_id, st_endpoint(geometry) as geometry, 2 as type from pointclasstest
union
select id, sts as route_id, st_startpoint(geometry) as geometry, 1 as type from pointclasstest
But this yet gives me ALL start & end points from each LineString (see line 101). I only want to get the start and end of each route. adding a group by sts does indeed only give me one start and end point per route, but not necessarily the spatially correct points (the endpoint can be in the middle of the route) as the query dooes not know which one to keep and which to drop.
So how does a query look that chooses the spatially correct start and endpoints?
Constraints:
- It has to be made via virtual layer
- I cannot convert the input layer to a multilinestring (although processing through a virtual layer making routes as multilines might be an option?)
This question is a follow-up to a previous question of mine.

