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

Use epsilon when comparing to 0 #2568

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

groutr
Copy link
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.

Test bounds computation when transform has almost zero values.
tests/test_read.py Outdated Show resolved Hide resolved
rasterio/_base.pyx Outdated Show resolved Hide resolved
@groutr
Copy link
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
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).

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.

None yet

2 participants