Skip to content

"Rotated bounds" or "corners" attribute #98

@kylebarron

Description

@kylebarron

Right now, GeoTIFF and Overview expose a .bounds attribute which gives the axis aligned bounds of the raster. But in the case of a rotated transform, this is not the same as the four corners. It would probably be nice to expose a method that returns the four corners of the image.

Here's a suggestion from claude:

@property
def corners(self: HasTransform) -> tuple[tuple[float, float], tuple[float, float], tuple[float, float], tuple[float, float]]:
    """Return the four corners of the image in the units of its CRS.

    Unlike `bounds`, which returns the axis-aligned bounding box, this returns
    the actual image corners in order: upper-left, upper-right, lower-right, lower-left.
    For non-rotated images these are equivalent; for rotated images the corners
    describe the true footprint.

    Returns:
        (ul, ur, lr, ll) as (x, y) tuples.
    """
    t = self.transform
    ul = t * (0, 0)
    ur = t * (self.width, 0)
    lr = t * (self.width, self.height)
    ll = t * (0, self.height)
    return (ul, ur, lr, ll)

Note that the ordering of the output depends on whether the raster's origin is top left or bottom left.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions