forked from manish295/socket-rocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsat_script.py
64 lines (45 loc) · 1.47 KB
/
sat_script.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import rasterio
import rasterioxyz
from rasterio.merge import merge
import glob
import os
# List all TIFF files
tiff_files = glob.glob("*.tif")
print(len(tiff_files))
print(tiff_files)
# Open all the TIFF files
src_files = [rasterio.open(file) for file in tiff_files]
# Merge the files, keeping all bands
print('Merging...')
merged, transform = merge(src_files)
print('Merged!')
# Get metadata from the first file
meta = src_files[0].meta.copy()
# Update metadata to reflect the new dimensions
meta.update({
"driver": "GTiff",
"height": merged.shape[1],
"width": merged.shape[2],
"transform": transform,
"count": merged.shape[0], # Update the number of bands
"dtype": merged.dtype,
})
print('Meta data updated')
# Save the merged file
print('Saving file to sattelite.tif...')
with rasterio.open("sattelite.tif", "w", **meta) as dst:
dst.write(merged)
# Close all source files
for src in src_files:
src.close()
print('File saved!')
img = rasterio.open("sattelite.tif")
print('Generating tiles...')
path = './react_gui/public/gps-info/Tiles'
folders = [f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))]
if len(folders) != 0:
tiled = rasterioxyz.Tiles(image=img, zooms=range(int(folders[0]), int(folders[-1]) + 1), resampling="bilinear", )
else:
tiled = rasterioxyz.Tiles(image=img, zooms=range(11, 16), resampling="bilinear", )
tiled.write("./react_gui/public/gps-info/sattelite")
print('Tiles generated! Saved to sattelite')