[GIS] How to force the blocksize when using gdal_rasterize

gdal-rasterize

I am rasterizing a shapefile of continents. I use the following command:

gdal_rasterize -burn 1  -ts 1440000 560000 -te -180 -60 180 80 -ot Byte -co COMPRESS=PACKBITS -co NUM_THREADS=ALL_CPUS -co BLOCKXSIZE=256 -co BLOCKYSIZE=256 -co PREDICTOR=2 continent.shp continents.tif

You can see I specify the blocksize to be 256 x 256. Yet when I check the blocksize:

blah = gdal.Open(continents.tif)
blah.GetRasterBand(1).GetBlockSize()

Out[74]: [1440000, 256]

gdal_rasterize is overwriting my BLOCKXSIZE specification and instead using the number of columns. Is there any way to force the 256×256 blocksize?

I understand that larger x-blocksizes are more I/O efficient generally, but not for my specific application.

Best Answer

To force the 256x256 blocksize you have to add the -co "TILED=YES" Option

gdal_rasterize -burn 1  -ts 1440000 560000 -te -180 -60 180 80 -ot Byte -co COMPRESS=PACKBITS -co NUM_THREADS=ALL_CPUS -co "TILED=YES" -co BLOCKXSIZE=256 -co BLOCKYSIZE=256 -co PREDICTOR=2 continent.shp continents.tif