-
Notifications
You must be signed in to change notification settings - Fork 1
/
sen2cat.py
38 lines (32 loc) · 1018 Bytes
/
sen2cat.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
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 9 12:55:09 2019
@author: Shengjie Liu
@Email: [email protected]
"""
import gdal
import numpy as np
import glob
def sen2cat(wdir,img='*.tif',name='concat',outdir=None):
if outdir==None:
name = wdir+'/'+name
else:
name = outdir+'/'+name
flist = glob.glob(wdir+'/'+img)
imz = len(flist)
count = 0
for fn in flist:
print(fn)
im = gdal.Open(fn,gdal.GA_ReadOnly)
projection = im.GetProjection()
geotransform = im.GetGeoTransform()
im = im.ReadAsArray()
imx,imy = im.shape
count += 1
if count==1:
outdata = gdal.GetDriverByName('GTiff').Create(name+'.tif',imy,imx,imz,gdal.GDT_UInt16)
outdata.SetGeoTransform(geotransform)
outdata.SetProjection(projection)
outdata.GetRasterBand(count).WriteArray(im)
outdata.FlushCache() ##saves to disk!!
outdata = None