Dissecting a GeoTIFF into 4K pixel size tiles

Hi!

I’ve been trying to work out how to even approach this issue for a few weeks. Basically what I am trying to do is write some code that takes a GeoTIFF of varying size between files, cuts it up into 4K pixel tiles, and saves these as a GeoTIFF. I know how to do the last bit, but I have no idea how to work the actual dissection of the TIFF. Any ideas?

Does this SO question help?

Hi Barry,
Not really, I’m working on a Raster image TIFF. I dont particularly want to change the values, the only issue I have in my way is the actual splitting up of the big TIFF into 4k pixel size. I’ve managed to use GDAL to dissect it into equal size images, but the programme I use next annoyingly requires 4K, which is not guaranteed by the GDAL method (which does not allow a specification of the pixel size of the image). At the moment I’m looking into using Rasterio but have had no luck so far!

I would use tifffile · PyPI to load and write TIFF files
and Python for loops over x and y
and numpy slicing to get the 4K tiles.
Look at the tifffile example where it says “Create a TIFF file from a generator of tiles” which does basically the opposite of what you want. It should be possible to do something similar for your scenario.
Roughly a line like this: tile = original[y*4000:(y+1)*4000,x*4000:(x+1)*4000].