Skip to content

BUG: Use epsilon to determine rotation when calculating bounds#2568

Open
groutr wants to merge 7 commits into
rasterio:mainfrom
groutr:base_bounds_0
Open

BUG: Use epsilon to determine rotation when calculating bounds#2568
groutr wants to merge 7 commits into
rasterio:mainfrom
groutr:base_bounds_0

Conversation

@groutr
Copy link
Copy Markdown
Contributor

@groutr groutr commented Aug 24, 2022

This should address an issue found when investigating #2565.

A tolerance needs to be considered in the comparison affine coefficients to 0.
I'm not entirely sure where the best place to test this would be. My initial though was to add a test to test_read.py.

Comment thread tests/test_read.py Outdated
Comment thread rasterio/_base.pyx Outdated
@groutr
Copy link
Copy Markdown
Contributor Author

groutr commented Aug 26, 2022

Decided to use transform.array_bounds to compute bounding box in the simple case. array_bounds does not use numpy and therefore doesn't violate the intent of _base.pyx to be numpy-free.
We also use the builtin property to determine if the transform is rectilinear (https://github.com/rasterio/affine/blob/master/affine/__init__.py#L409-L410). This checks for any axis aligned rotation using affine's epsilon.

@groutr
Copy link
Copy Markdown
Contributor Author

groutr commented Aug 26, 2022

I'm getting a confusing result when using transform.array_bounds in a test case.

from affine import identity
from rasterio.transform import array_bounds
t = identity.translation(2, 3)
width, height = 10, 10
array_bounds(height, width, t)
# (2, 13.0, 12.0, 3)

I would expect the bounds to be (2, 3, 12, 13). Am I doing something wrong here?

EDIT: It looks like the identity transform is south-up. Any north-up transform involves a reflection (ie. e < 0).

@snowman2 snowman2 added the bug label Dec 29, 2025
@snowman2 snowman2 added this to the 1.5.1 milestone Dec 29, 2025
Comment thread rasterio/_base.pyx
height = self.height
if b == d == 0:
return BoundingBox(c, f + e * height, c + a * width, f)
if self.transform.is_rectilinear:
Copy link
Copy Markdown
Member

@snowman2 snowman2 Jan 7, 2026

Choose a reason for hiding this comment

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

Mind moving this check to array_bounds and just use array_bounds inside this method?

That way the behavior remains consistent with both methods.

@snowman2
Copy link
Copy Markdown
Member

snowman2 commented Jan 7, 2026

This PR is older. @groutr is this something you still have time & interest to work on?

@snowman2 snowman2 changed the title Use epsilon when comparing to 0 BUG: Use epsilon to determine rotation when calculating bounds Jan 7, 2026
@groutr
Copy link
Copy Markdown
Contributor Author

groutr commented Jan 7, 2026

I'll take a look.

@sgillies sgillies removed this from the 1.5.1 milestone Mar 20, 2026
@sgillies
Copy link
Copy Markdown
Member

Let's punt on this for 1.5.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants