ArchGDAL.jl icon indicating copy to clipboard operation
ArchGDAL.jl copied to clipboard

Tif files are not always chunked

Open rafaqz opened this issue 4 years ago • 6 comments

https://github.com/yeesian/ArchGDAL.jl/blob/6d67ee60bfdc3cd680c57efa3bc504bbeae088cb/src/raster/array.jl#L106-L107

There is TILED=NO for the GTiff driver, so Chunked is not always true. I'm not sure what the function is to check if a band is chunked or not, but we should use it.

This can be a problem for gdal, giving a Bad value 514 for "TileWidth" tag error if you try to set the tile size to the chunk size, or a problem for DiskArrays with an error broadcasting different chunk sizes... when in fact there are no chunks.

rafaqz avatar Jun 05 '21 23:06 rafaqz

This may be an issue with the difference between GDALs "natural" and actual block sizes.

rafaqz avatar Jun 06 '21 00:06 rafaqz

Do we need to compare blocksize(rasterband) with (width(rasterband), height(rasterband))?

yeesian avatar Jun 06 '21 03:06 yeesian

Yeah maybe. I'm wondering if @meggart had a reason for always using Chunked()

rafaqz avatar Jun 06 '21 03:06 rafaqz

Afaik, even if with no tiling, you end up with blocks (that are single rows). In that sense there always is a chunk.

I can imagine though that setting tile options on a non tiled rasters results in errors. @rafaqz can you give a mwe for that error you mentioned?

evetion avatar Jun 06 '21 20:06 evetion

Yeah maybe. I'm wondering if @meggart had a reason for always using Chunked()

No, I did not know that there is a TILED=NO and I just assumed GDAL datasets are tiled. I would be happy to do a check here e.g. as @yeesian suggested, by comparing blocksize with the actual size of the band.

meggart avatar Jun 07 '21 10:06 meggart

Just to drop this here:

gds = GDAL.gdalopen(somefile, GDAL.GA_ReadOnly)
infoopts = GDAL.gdalinfooptionsnew(C_NULL, C_NULL)
info = GDAL.gdalinfo(gds, infoopts)
info = split(info)
filter(contains("Block"), info)
GDAL.gdalinfooptionsfree(infoopts)
GDAL.gdalclose(gds)

This is neither fast nor solid, but retrieves the block size.

maxfreu avatar Aug 18 '22 11:08 maxfreu