-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit.py
More file actions
45 lines (35 loc) · 1.29 KB
/
split.py
File metadata and controls
45 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from osgeo import gdal
import os
def split_image(input_image_path, output_folder, block_size, overlap):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
dataset = gdal.Open(input_image_path)
width = dataset.RasterXSize
height = dataset.RasterYSize
m=0
n=0
for i in range(0, width, block_size - overlap):
n=0
for j in range(0, height, block_size - overlap):
x_offset = i
y_offset = j
x_size = min(block_size, width - i)
y_size = min(block_size, height - j)
output_filename = os.path.join(output_folder, f"block1_{m}_{n}.tif")
n = n + 1
gdal.Translate(output_filename, dataset, format="GTiff", srcWin=(x_offset, y_offset, x_size, y_size))
m=m+1
dataset = None
if __name__ == "__main__":
'''
input_image_path = "D:/RS/17JULRGB_linear.tif"
output_folder = "D:/RS/Blocks_17JULRGB_linear"
block_size = 1024
overlap = 10
split_image(input_image_path, output_folder, block_size, overlap)
'''
input_image_path = "D:/RS/Blocks_17JULRGB_linear/block_1_0.tif"
output_folder = "D:/RS/Blocks_17JULRGB_linear_small1"
block_size = 16
overlap = 0
split_image(input_image_path, output_folder, block_size, overlap)