1 代码实现(一小块儿区域裁剪)
import gdal
in_ds = gdal.Open("zx1.jpg")
print("open tif file succeed")
width = in_ds.RasterXSize
height = in_ds.RasterYSize
outbandsize = in_ds.RasterCount
im_geotrans = in_ds.GetGeoTransform()
im_proj = in_ds.GetProjection()
datatype = in_ds.GetRasterBand(1).DataType
im_data = in_ds.ReadAsArray()
in_band1 = in_ds.GetRasterBand(1)
in_band2 = in_ds.GetRasterBand(2)
in_band3 = in_ds.GetRasterBand(3)
offset_x = 0
offset_y = 0
block_xsize = 60
block_ysize = 60
k = 0
for i in range(width // block_xsize):
for j in range(height // block_xsize):
out_band1 = in_band1.ReadAsArray(i * block_xsize, j * block_xsize, block_xsize, block_ysize)
out_band2 = in_band2.ReadAsArray(i * block_xsize, j * block_xsize, block_xsize, block_ysize)
out_band3 = in_band3.ReadAsArray(i * block_xsize, j * block_xsize, block_xsize, block_ysize)
print(out_band3)
k += 1
gtif_driver = gdal.GetDriverByName("GTiff")
out_ds = gtif_driver.Create(str(k) + 'clip4.tif', block_xsize, block_ysize, outbandsize, datatype)
ori_transform = in_ds.GetGeoTransform()
if ori_transform:
print(ori_transform)
print("Origin = ({}, {})".format(ori_transform[0], ori_transform[3]))
print("Pixel Size = ({}, {})".format(ori_transform