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

thread 'main' panicked at 'index out of bounds: the len is 724 but the index is 724 #6

Open
LaurentBerder opened this issue Aug 1, 2023 · 3 comments

Comments

@LaurentBerder
Copy link

Hi,

I'm fairly new in Rust and wanted to try reading a .tif hyperspectral imaging file which contains multiple layers (its shape is (356, 724, 757), for 356 layers, width of 724 and height of 757 pixels).

My first test was to just read the file, then look at value at coordinates (1, 1), which I'm guessing should be a vector of size 356.

extern crate geotiff;

fn main() {
    let geotiff = geotiff::TIFF::open("path_to_my_file.tif").unwrap();
    println!("{:?}", geotiff);

    let pixel = geotiff.get_value_at(1, 1);
    println!("{:?}", pixel);
}

But I run into this panic:

thread 'main' panicked at 'index out of bounds: the len is 724 but the index is 724', ...index.crates.io-6f17d22bba15001f\geotiff-0.0.2\src\reader.rs:303:17

Should I understand that the multiplicity of layers is not handled by geotiff, or am I doing something wrong?

@dominikbucher
Copy link
Member

Hi Laurent!

It's been a while since I originally started the library, and as a word of caution, I only needed it to read elevation data (single channel / layer) - it served that purpose but is sadly far from implementing the whole GeoTiff standard.

Looking at https://github.com/georust/geotiff/blob/master/src/lib.rs#L35, it should return the first layer, however, your panic seems to be happening already during parsing. Looking at https://github.com/georust/geotiff/blob/master/src/reader.rs#L303 it seems that one of the accessors (in img[curr_x][curr_y][curr_z]) cause the error, and not necessarily the conversion of the value (self.vec_to_value::<Endian>(v);). This could well be because your tiff has multiple layers.

Lots of coulds and woulds, I know (sorry!), but it was 5 years ago that I wrote the code... if you manage to dig into the library and fix the issues, happy to merge a PR! The library is not particularly large so it should be understandable fairly quickly :) (the GeoTiff spec on the other hand...)

Cheers

@dominikbucher
Copy link
Member

Related #4

@LaurentBerder
Copy link
Author

Thanks for your reply, @dominikbucher.
As much as I'd love to give you a hand on this, I must be lucid on the fact that my level of mastery for Rust is not yet sufficient!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants