[GIS] Splitting raster into tiles using GDAL

gdalrastertiles

I have a raster that needs to be split into tiles (each tile a new raster). I have a Shapefile with multiple polygons (these polygons are how I want the raster split).

How do I do this using GDAL?

Best Answer

You can split the image to small tiles by the size of the (tile_size) using a code like this one:

file_path,file_name = {{put-yor-path-and-name-here}}
gdal_img = gdal.Open(img)

RasterXSize = gdal_img.RasterXSize
RasterYSize = gdal_img.RasterYSize
transform = gdal_img.GetGeoTransform()
minX = transform[0]
maxY = transform[3]
img_pixelWidth = transform[1]

img_out = str(path) + "\\" + str(out_img_name) + r".TIF"          

gdalnumeric.SaveArray(gdalnumeric.LoadFile(img,startX,
                      startY,tile_sizeX,tile_sizeY),
                      img_out,"GTiff")