Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch: better documentation for inconsistent behaviour of x_at (and y_at) #28485

Closed
qgib opened this issue Nov 29, 2018 · 3 comments
Closed

patch: better documentation for inconsistent behaviour of x_at (and y_at) #28485

qgib opened this issue Nov 29, 2018 · 3 comments
Labels
Documentation Changes to Documentation, README, INSTALL, etc Easy fix Feature Request

Comments

@qgib
Copy link
Contributor

qgib commented Nov 29, 2018

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.


@qgib
Copy link
Contributor Author

qgib commented Nov 29, 2018

Author Name: Nyall Dawson (@nyalldawson)


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?


  • status_id was changed from Open to Feedback

@qgib
Copy link
Contributor Author

qgib commented Nov 29, 2018

Author Name: Alister Hood (@AlisterH)


#8570

@qgib
Copy link
Contributor Author

qgib commented Nov 29, 2018

Author Name: Luigi Pirelli (@luipir)


fixed with merge of #8570


  • status_id was changed from Feedback to Closed

@qgib qgib closed this as completed Nov 29, 2018
@qgib qgib added Feature Request Documentation Changes to Documentation, README, INSTALL, etc Easy fix labels May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Changes to Documentation, README, INSTALL, etc Easy fix Feature Request
Projects
None yet
Development

No branches or pull requests

1 participant