You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$x_at(i) and $y_at(i) return the coordinates of a vertex. The help in the expression dialog explains that i is the index of a point of a line, starting at 0; negative values applying from the last index.
I wanted to get the coordinates at the end of a line, so I tried using $x_at(-0), but it returned the coordinates at the start of the line, presumably because -0=0. I therefore assumed it is impossible to get the coordinates at the end of the line, so I reversed all the lines in my layer, extracted the coordinates of the start points to attribute fields, and then reversed them again. Someone else might instead get wrong results by trying to get coordinates of e.g. the second to last point by using -1.
I've now found that what I did was unnecessary, because the negative indices simply start at -1. In my opinion this is unnecessarily inconsistent (if it is not technically possible for negative indices to start at -0, then positive indices should start at 1 instead of 0). But I guess it is too late to change this behaviour, in which case I propose documenting it properly - see patch attached.
It's modelled off the approach Python uses -- they also use 0 based indices in the ascending direction, and -1 to refer to the last element in an array.
But the documentation improvement is very welcome. Can you file this as a PR on github so that we can merge?
Author Name: Alister Hood (@AlisterH)
Original Redmine Issue: 20665
Redmine category:documentation_and_help
Assignee: Yves Jacolin
$x_at(i) and $y_at(i) return the coordinates of a vertex. The help in the expression dialog explains that i is the index of a point of a line, starting at 0; negative values applying from the last index.
I wanted to get the coordinates at the end of a line, so I tried using $x_at(-0), but it returned the coordinates at the start of the line, presumably because -0=0. I therefore assumed it is impossible to get the coordinates at the end of the line, so I reversed all the lines in my layer, extracted the coordinates of the start points to attribute fields, and then reversed them again. Someone else might instead get wrong results by trying to get coordinates of e.g. the second to last point by using -1.
I've now found that what I did was unnecessary, because the negative indices simply start at -1. In my opinion this is unnecessarily inconsistent (if it is not technically possible for negative indices to start at -0, then positive indices should start at 1 instead of 0). But I guess it is too late to change this behaviour, in which case I propose documenting it properly - see patch attached.
The text was updated successfully, but these errors were encountered: