Skip to content

Commit

Permalink
Merge branch '198-inverse_geotransform-class-argument' into 'master'
Browse files Browse the repository at this point in the history
refacto: inverse geotransform class argument

Closes #198

See merge request 3d/shareloc!128
  • Loading branch information
duboise-cnes committed Oct 13, 2023
2 parents 6865bc7 + 174bdd7 commit 2ca741d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions shareloc/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ def __init__(self, image_path, read_data=False, roi=None, roi_is_in_physical_spa
# | pixel size col, row rotation, origin col |
# | col rotation , pixel size row, origin row |
self.transform = self.dataset.transform
# bitwise not inversion (Affine.__invert implemented, pylint bug)
self.trans_inv = ~self.transform # pylint: disable=invalid-unary-operand-type

roi_window = None
if roi is not None:
# User have set ROI in physical space or not
if roi_is_in_physical_space:
Expand All @@ -90,8 +91,11 @@ def __init__(self, image_path, read_data=False, roi=None, roi_is_in_physical_spa
col_off = roi[1]
width = roi[3] - roi[1]
height = roi[2] - roi[0]

roi_window = rasterio.windows.Window(col_off, row_off, width, height)
self.transform = self.dataset.window_transform(roi_window)
# bitwise not inversion (Affine.__invert implemented, pylint bug)
self.trans_inv = ~self.transform # pylint: disable=invalid-unary-operand-type
self.nb_rows = height
self.nb_columns = width
else:
Expand Down Expand Up @@ -187,7 +191,5 @@ def transform_physical_point_to_index(self, row_geo, col_geo):
:return: index coordinates (row, col)
:rtype: Tuple(row float or 1D np.array, col float or 1D np.array)
"""
# bitwise not inversion (Affine.__invert implemented, pylint bug)
trans_inv = ~self.transform # pylint: disable=invalid-unary-operand-type
col, row = trans_inv * (col_geo, row_geo)
col, row = self.trans_inv * (col_geo, row_geo)
return row - 0.5, col - 0.5

0 comments on commit 2ca741d

Please sign in to comment.