geotiff icon indicating copy to clipboard operation
geotiff copied to clipboard

read_box fails if reading with the bounding box of the tiff

Open jarmniku opened this issue 1 year ago • 3 comments

At least with as_crs=3857 I cannot correctly read_box() using the bounding box returned by tif_bBox_converted. This problem happens also when shrinking another dimension but keeping the other to match with the original bouding box.

The geotiff I am playing with is attached. (W5131F.tif, provided by Maanmittauslaitos 2023/05, Finland)

Code:

geotif = GeoTiff("W5131F.tif", as_crs=3857, band=0)
arr = geotif.read_box(geotif.tif_bBox_converted)
print(f"{arr.shape=}")

This should print something like 3000 by 3000 as the shape, but instead the output is:

arr.shape=(73, 3000)

I debugged for a while and noted that i_min and j_min in get_int_box() get negative values. Limiting them to be equal or greater than zero seems to fix something. Not sure if I can survive with that.

W5131F.zip

jarmniku avatar Jun 20 '23 11:06 jarmniku

Thanks for picking that up. If you've already debugged, please open a PR and I'll merge asap! Thanks!

KipCrossing avatar Jun 20 '23 13:06 KipCrossing

I am not currently sure if my fix is the correct way to fix the issue. I am writing a solution that can automatically build up a single elevation map for a given rectangle area, using provided small geotiff tiles (6 km x 6 km). This required a bit of code logic so that the overlapping regions between the given area and the tiles are found. After the mentioned fix, the next problem seems to be that there are gaps between the tiles. It might be due to some kind of coordinate misalignment, see the image below. In this case, nine geotiff tiles are used to construct the shown elevation map.

image

jarmniku avatar Jun 21 '23 06:06 jarmniku