-
Notifications
You must be signed in to change notification settings - Fork 96
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
Fix raster buffer indexing #550
Conversation
I think |
To try to understand the format, I tried to read a .tiff file with size (5100, 2400), however, I could only directly read in the range (0,0) to (2399, 2399), when trying to read (2400, 0), I got a "index out of bounds error". |
If you mean the previous computation, that was x * N_x + y rather than x + N_x * y if convention with this Wikipedia article: https://en.wikipedia.org/wiki/Row-_and_column-major_order |
That's because band sizes are (width, height), but that doesn't mean the data is structured the same way. Compare to GDAL's
|
As far as I understand, this doesn't contradict what I am saying. |
Because |
I don't understand what you are saying here. That it is in column-major representation? (In which case the formula would still be incorrect)? I have tried to work with reversed coordinates, but that doesn't stop the problem of accessing elements outside of a square. So we have the width = number of columns, height = number of rows. Say we have a buffer, |
Oh, I didn't spot the bounds check. Yeah, I think the formula is correct, but the bounds check is wrong. |
CC @metasim my intention was to index by |
I think ndarray can use both (https://docs.rs/ndarray/latest/ndarray/enum.Order.html) and there are good arguments for both options. I prefer [y,x] which is what numpy (python) use. And if i remember correct this is also the default in ndarray. |
@CyclotomicDev can you update this PR to switch around the bounds check? |
Apologies, its my first time using a PR. I seem to have somehow reverted the Cargo.toml file, will that be fine to ignore in the merge? |
e3a2aa4
to
5d1e1c4
Compare
r? @jdroenner |
There's a lot of historical legacy here, but my memory is fuzzy on why it is the way it is. Every time I would iterate over cells, I'd double check the docs, for both correctness and cache coherence (an iterator can take care of that part). In my own personal libraries I never return tuples, but structs with labeled fields because it's too easy for me to mess up. But As you note, |
I was asking more about what |
I have been thinking about the Buffer. To be honest i think we should deprecate all methods with tuple params as well as the shape method. We should simply add new methods with row and column as parameters. Who ever needs ndarray style access can transform the Buffer into an Ndarray... |
@jdroenner we should probably discuss the deprecation of |
good idea. some lint broke the CI. I guess we should fix that first. |
I have an open PR for that. |
merged! thx! |
Gentle nudge about publishing a patch update, @jdroenner. |
i will do it later today or Sunday (edit: will do it Sunday morning) |
CHANGES.md
if knowledge of this change could be valuable to users.Changed to the correct indexing when converting from a row-major 2D array to vector index.
Previous test only really tested if
std::ops::Index
works, and not indexing the buffer; in the example the index ofb[(3,5)] = 3 * 5 + 5
would be the same asb[(4,0)] = 4 * 5 + 0
. New test ensures all buffer indices covered.