Skip to content

Commit

Permalink
BUG: Fix the issue with getting the bounds wrong when affine has no r…
Browse files Browse the repository at this point in the history
…otation or the resolution is negative. Fixes mdbartos#250
  • Loading branch information
Taher Chegini committed Apr 14, 2024
1 parent 727c521 commit a761d6e
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions pysheds/sview.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,28 @@ def size(self):

@property
def bbox(self):
shape = self.shape
xmin, ymax = View.affine_transform(self.affine, 0, 0)
xmax, ymin = View.affine_transform(self.affine, shape[-1], shape[-2])
_bbox = (xmin, ymin, xmax, ymax)
return _bbox
has_rotation = self.affine.b == self.affine.d != 0
if has_rotation:
resolution_x = np.sqrt(self.affine.a**2 + self.affine.d**2)
resolution_y = np.sqrt(self.affine.b**2 + self.affine.e**2)
else:
resolution_x, resolution_y = self.affine.a, self.affine.e

left = self.affine.c
top = self.affine.f
right = left + resolution_x * self.shape[-1]
bottom = top + resolution_y * self.shape[-2]

if resolution_y < 0:
miny, maxy = bottom, top
else:
miny, maxy = top, bottom

if resolution_x < 0:
minx, maxx = right, left
else:
minx, maxx = left, right
return (minx, miny, maxx, maxy)

@property
def extent(self):
Expand Down

0 comments on commit a761d6e

Please sign in to comment.