-
Notifications
You must be signed in to change notification settings - Fork 1
/
Output.py
38 lines (34 loc) · 1.16 KB
/
Output.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
import os
import numpy
from osgeo import gdal
import Config
dataFolderDir = Config.dataFolderDir
def makeFileName(prefix, suffix, ext = "tif"):
return prefix + '_' + suffix + '.' + ext
def createTiff(band, prefix, suffix):
width = band.shape[1]
height = band.shape[0]
r_band = numpy.zeros((height, width), dtype=numpy.int)
g_band = numpy.zeros((height, width), dtype=numpy.int)
b_band = numpy.zeros((height, width), dtype=numpy.int)
for x in range(0, height):
for y in range(0, width):
if band[x][y] == 0:
r_band[x][y] = 196
g_band[x][y] = 118
b_band[x][y] = 8
if band[x][y] == 1:
r_band[x][y] = 122
g_band[x][y] = 214
b_band[x][y] = 9
driver = gdal.GetDriverByName('GTiff')
outfile_name = makeFileName(prefix, suffix, 'tif')
dataset = driver.Create(outfile_name, width, height, 3, gdal.GDT_Byte)
vi = gdal.Open(os.path.join(dataFolderDir, "EVI_2005_DBSH.tif")) # HACK
geoT = vi.GetGeoTransform()
proj = vi.GetProjection()
dataset.SetGeoTransform(geoT)
dataset.SetProjection(proj)
dataset.GetRasterBand(1).WriteArray(r_band)
dataset.GetRasterBand(2).WriteArray(g_band)
dataset.GetRasterBand(3).WriteArray(b_band)