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

Add RasterBand::write_block #490

Merged
merged 1 commit into from
Dec 11, 2023
Merged

Conversation

lnicola
Copy link
Member

@lnicola lnicola commented Dec 10, 2023

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

@lnicola
Copy link
Member Author

lnicola commented Dec 10, 2023

Will rebase on top of #489.

r? @metasim

@lnicola lnicola force-pushed the rasterband-write-block branch 2 times, most recently from b0b62e7 to 2fb4da8 Compare December 10, 2023 18:16
@metasim
Copy link
Contributor

metasim commented Dec 11, 2023

Should we also support {read|write}_block without ndarray?

Copy link
Contributor

@metasim metasim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm torn about having core operations that are only supported with in ndarray enabled, mode without a technical reason.

  • Pros: easier to submit PRs.
  • Cons: forces users to use ndarry when in reality

I'd like to use these features as a Buffer user.

But I admittedly have a bit of an axe to grind here. I would have preferred ndarray integration to have happened as a copy-free Buffer::to_ndarray method (for example), rather than having dual I/O methods for Buffer and for Array2.

#[cfg_attr(docsrs, doc(cfg(feature = "array")))]
/// Write a [`Array2<T>`] from a [`Dataset`] block, where `T` implements [`GdalType`].
///
/// # Arguments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a reference to the method for getting the block layout (so one can know how many blocks there are in each dimension)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example would be helpful here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an example and a note to block_size and actual_block_size.

/// The Matrix shape is (rows, cols) and raster shape is (cols in x-axis, rows in y-axis).
pub fn write_block<T: Copy + GdalType>(
&mut self,
block_index: (usize, usize),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the block index is out of bounds? Do we get an error, or panic (or worse)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no way it can panic, of course :-). Added a note in the docs.

@lnicola
Copy link
Member Author

lnicola commented Dec 11, 2023

Should we also support {read|write}_block without ndarray?

I think we should, but I don't think I want to do it in this PR, since there's a bit of design space to explore. I don't like the current situation either, but in the meanwhile it's probably better than having no access to these.

@lnicola lnicola force-pushed the rasterband-write-block branch from 2fb4da8 to 5a8c2f2 Compare December 11, 2023 18:55
@lnicola lnicola merged commit 78827be into georust:master Dec 11, 2023
9 checks passed
@lnicola lnicola deleted the rasterband-write-block branch December 11, 2023 19:40
@lnicola
Copy link
Member Author

lnicola commented Dec 12, 2023

@metasim do you ever use the MD API, and would you expect it to require ndarray, or use some form of Buffer3, BufferN version?

@metasim
Copy link
Contributor

metasim commented Dec 12, 2023

do you ever use the MD API, and would you expect it to require ndarray, or use some form of Buffer3, BufferN version?

@lnicola I do not. That's a good point (I didn't realize MD required it). For that API it seems reasonable to require ndarray, and would be silly to implement a bespoke multidimensional array capability just to avoid a dependency.

I wouldn't be adverse to ndarray being required for everything. But because we advertise it as an "optional" dependency, I don't think not using it should preclude access to basic functionality (i.e. block I/O).

@lnicola
Copy link
Member Author

lnicola commented Dec 12, 2023

I didn't realize MD required it

It doesn't, I should have checked before asking 😔.

@metasim
Copy link
Contributor

metasim commented Dec 12, 2023

PS: I think ndarray is fantastic. My position is more about it's optionality, and treating Buffer as a first-class citizen in face of that optionality.

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

Successfully merging this pull request may close these issues.

2 participants