from osgeo import gdal, ogr, gdalconst
import sys

gdal.UseExceptions()
gdal.AllRegister()

src_filename = "../../aineisto/Clc2012_FI20m.tif"
dstPath = "../../output"
berries = ["mustikka", "puolukka", "karpalo", "vadelma"]

if len(sys.argv) > 1:
	berries = [sys.argv[1]]

# WARNING: these values are for testing only, not real data
corineToBerryIndex = dict()
corineToBerryIndex["mustikka"] = dict()
corineToBerryIndex["mustikka"][24] = 70
corineToBerryIndex["mustikka"][25] = 80
corineToBerryIndex["mustikka"][27] = 50
corineToBerryIndex["mustikka"][28] = 60
corineToBerryIndex["puolukka"] = dict()
corineToBerryIndex["puolukka"][24] = 80
corineToBerryIndex["puolukka"][25] = 60
corineToBerryIndex["karpalo"] = dict()
corineToBerryIndex["karpalo"][40] = 50
corineToBerryIndex["karpalo"][42] = 80
corineToBerryIndex["vadelma"] = dict()
corineToBerryIndex["vadelma"][36] = 80
corineToBerryIndex["vadelma"][35] = 60

normalizationFactor = 100 / 80

src_ds = gdal.Open(src_filename)
corineBand = src_ds.GetRasterBand(1)
xSize = corineBand.XSize
ySize = corineBand.YSize
print "Input raster size is ", xSize, ySize

for berry in berries:
	driver = src_ds.GetDriver()
	dst_ds = driver.Create(dstPath + "/" + berry + ".tif", xSize, ySize, 1, gdal.GDT_UInt16, options = ['COMPRESS=LZW'])
	dst_ds.SetGeoTransform(src_ds.GetGeoTransform())
	dst_ds.SetProjection(src_ds.GetProjection())

	array = corineBand.ReadAsArray(0, 0, xSize, ySize)

	for x in range(0, xSize):
		if x % 500 == 0:
			print `round(100.0 * x / xSize)` + " % of " + berry + " done"
		for y in range(0, ySize):
			origVal = array[y,x]
			if origVal in corineToBerryIndex[berry]:
				finalVal = corineToBerryIndex[berry][origVal] * normalizationFactor
			else:
				finalVal = 0
			array[y,x] = finalVal

	dstBand = dst_ds.GetRasterBand(1)
	dstBand.WriteArray(array, 0, 0)

	# Once we're done, close properly the dataset
	dstBand = None
	dst_ds = None

corineBand = None
src_ds = None

@@ -1,8 +1,228 @@
+# This script generates GeoTiff files based Corine land cover data%0A# Usage: python generateGeotiff.py berryName%0A# berryName is optional. If not provided all output layers are generated.%0A# Licensed under the MIT license%0A%0A
 from osg
@@ -305,16 +305,79 @@
 ster()%0A%0A
+# Paths for input and output. These may be adjusted as needed.%0A
 src_file
@@ -443,16 +443,17 @@
 output%22%0A
+%0A
 berries 
@@ -582,39 +582,41 @@
 are 
-for testing only, not real data
+not based on scientific research.
 %0Acor
@@ -1195,16 +1195,85 @@
 %5D = 60%0A%0A
+# Normalize values so that the highest value in output is always 100%0A
 normaliz
@@ -1293,20 +1293,23 @@
  100
+.0
  / 80
+.0
 %0A%0Asrc
-_d
+D
 s = 
@@ -1344,26 +1344,25 @@
 neBand = src
-_d
+D
 s.GetRasterB
@@ -1498,18 +1498,17 @@
 er = src
-_d
+D
 s.GetDri
@@ -1513,26 +1513,25 @@
 river()%0A%09dst
-_d
+D
 s = driver.C
@@ -1630,26 +1630,25 @@
 =LZW'%5D)%0A%09dst
-_d
+D
 s.SetGeoTran
@@ -1652,26 +1652,25 @@
 ransform(src
-_d
+D
 s.GetGeoTran
@@ -1682,18 +1682,17 @@
 ())%0A%09dst
-_d
+D
 s.SetPro
@@ -1702,18 +1702,17 @@
 tion(src
-_d
+D
 s.GetPro
@@ -1803,16 +1803,54 @@
 xSize):%0A
+%09%09indexes = corineToBerryIndex%5Bberry%5D%0A
 %09%09if x %25
@@ -1998,75 +1998,43 @@
  in 
-corineToBerryIndex%5Bberry%5D:%0A%09%09%09%09finalVal = corineToBerryIndex%5Bberry%5D
+indexes:%0A%09%09%09%09finalVal = int(indexes
 %5Bori
@@ -2060,16 +2060,17 @@
 onFactor
+)
 %0A%09%09%09else
@@ -2128,18 +2128,17 @@
 nd = dst
-_d
+D
 s.GetRas
@@ -2249,18 +2249,17 @@
 one%0A%09dst
-_d
+D
 s = None
@@ -2285,10 +2285,9 @@
 %0Asrc
-_d
+D
 s = 

Clean up and fix normalization