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

fix: prevents read_lines_by_block from skipping pixels #108

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

caiubi
Copy link

@caiubi caiubi commented Nov 18, 2024

Fixes issue #4

@caiubi
Copy link
Author

caiubi commented Nov 18, 2024

Every time read_blocks_by_block yields, the pixels array has the size of block_buffer_size.
Given previous code:

          pixels.each_slice(x_block_size).with_index do |row, block_row_number|
             yield row
             break if block_row_number == y_block_size - 1
           end

If it is the last block, the x_block_size is actually the remainder value.
This causes the pixels to be sliced incorrectly, iterating more times than necessary and reaching the break condition faster, discarding valid block pixels.

@turboladen
Copy link
Contributor

Would you mind adding a test that verifies the fix?

@caiubi
Copy link
Author

caiubi commented Nov 23, 2024

Sure! Should be ready in a couple days

@caiubi
Copy link
Author

caiubi commented Nov 27, 2024

@turboladen here it is.
I had to also fix write_xy_narray, otherwise I'd have to workaround it by writing into the raster in a different way.

It kinda had the same mistake, when writing the last block it would ignore the remaining block pixels and cause the final raster to have missing pixels.

@caiubi
Copy link
Author

caiubi commented Nov 27, 2024

Note: Both GTiff driver and TILED options were used on the new test to ensure that the created raster would have a block size greater than the raster size itself.

@caiubi
Copy link
Author

caiubi commented Nov 27, 2024

Added the suggested changes. New code now uses Numo::NArray instead of NArray

All specs are passing locally 😄

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.

3 participants