Skip to content

Closes #60 invalid values for get_int_box on left-top tif border#74

Open
st-korn wants to merge 1 commit into
KipCrossing:mainfrom
st-korn:main
Open

Closes #60 invalid values for get_int_box on left-top tif border#74
st-korn wants to merge 1 commit into
KipCrossing:mainfrom
st-korn:main

Conversation

@st-korn
Copy link
Copy Markdown

@st-korn st-korn commented Sep 20, 2024

Sometimes, when box is over left or over top border of the tif, i_min or j_min were negative.
It causes zerro-range of array selected.
See issue #60

Issue

from geotiff import GeoTiff

def read_square(x,y):
    arr = gtf.read_box(((x-square_size//2, y+square_size//2), (x+square_size//2, y-square_size//2)))
    print(arr.shape)

gtf = GeoTiff("ASTGTMV003_N43E039_dem.tif", as_crs=3857)
box = gtf.tif_bBox_converted
square_size = min(box[1][0]-box[0][0], box[0][1]-box[1][1]) // 3
print(gtf.tif_bBox)
print(box, square_size)
# ((4341444.67989728, 5465463.676723338), (4452795.092771329, 5311950.706664268)) 37116.0

# Center
read_square((box[1][0]+box[0][0])//2, (box[0][1]+box[1][1])//2)
# (869, 1199) - OK

# Right
read_square(box[1][0], (box[0][1]+box[1][1])//2)
#(869, 600) - OK

# Right-bottom
read_square(box[1][0], box[1][1])
# (438, 600) - OK

# Bottom
read_square((box[1][0]+box[0][0])//2, box[1][1])
# (438, 1199) - OK

# Left-bottom
read_square(box[0][0], box[1][1])
# (438, 0) - ISSUE

# Left
read_square(box[0][0], (box[0][1]+box[1][1])//2)
#(869, 0) - ISSUE

# Left-top
read_square(box[0][0], box[0][1])
# (0, 0) - ISSUE

# Top
read_square((box[1][0]+box[0][0])//2, box[0][1])
# (0, 1199) - ISSUE
  • I check i_min, j_min: if they are negative - I make them equal to zero.
  • I check i_max, j_max of tif dimensions, and if they are greater - I make them equal to tif width or height. This is not necessary. Range is correct selected from array, wher its borders are greater than array's length.
  • I check i_min, j_min of tif dimensions, and if they are greater - I raise BoundaryNotInTifError. Because the box is located outside tid file.
  • I check i_max, j_max: if they are negative - I raise BoundaryNotInTifError. Because the box is located outside tid file.

I remove function _check_bound_in_tiff. It was called only from within get_int_box. Now get_int_box already contains all its functionality.

I tested code with mypy and use pre-commit for verification.

@st-korn st-korn changed the title Fix #60 invalid values for get_int_box on left-top tif border Closes #60 invalid values for get_int_box on left-top tif border Sep 20, 2024
@st-korn st-korn marked this pull request as draft April 30, 2025 22:01
@st-korn st-korn marked this pull request as ready for review April 30, 2025 22:02
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.

1 participant