Commit bad28b82 authored by Hoek, Steven's avatar Hoek, Steven
Browse files

Bug fixed, few improvements applied and TODO items added in view of...

Bug fixed, few improvements applied and TODO items added in view of implementation of option "average"
parent 0a21764a
......@@ -227,9 +227,9 @@ class TileStitcher():
__tilewidth = 1
__tileheight = 1
__coloverlap = 0
__rowoverlpa = 0
__rowoverlap = 0
__tilelist = []
__option = "topleft"
__option = "bottomright"
def __init__(self, tilewidth, tileheight, coloverlap=0, rowoverlap=0, option="bottomright"):
'''
......@@ -242,9 +242,13 @@ class TileStitcher():
'''
self.__tilewidth = tilewidth
self.__tileheight = tileheight
if (coloverlap < 0) or (rowoverlap < 0):
raise ValueError("Overlap cannot be negative!")
self.__coloverlap = coloverlap
self.__rowoverlap = rowoverlap
self.__option = option # or average or topleft
if not option in ['average', 'topleft', 'bottomright']:
raise ValueError("Invalid option: %s!" % option)
self.__option = option
def add(self, filename, separator="_"):
# Initialise
......@@ -288,6 +292,10 @@ class TileStitcher():
# Now loop over the tiles; in principle i and k should be zero-based
xul, yul = 0.0, 0.0
data = np.empty((self.__tileheight, self.__ncols * self.__tilewidth))
if self.__option == "average":
# We'll need to store some values temporarily
colbuffer = np.empty((self.__tileheight, self.__coloverlap))
rowbuffer = np.empty((self.__rowoverlap, self.__tilewidth * self.__nrows))
for i in range(minrowidx, maxrowidx + 1):
for k in range(mincolidx, maxcolidx + 1):
# Get hold of the right tile
......@@ -317,7 +325,18 @@ class TileStitcher():
# Add the data from the tile at the right location
for j in range(rg.nrows - self.__rowoverlap):
line = rg.next()
if (self.__option == "average") and (k > mincolidx):
# TODO: use the data from the column buffer to do the calculations
pass
data[j, k*self.__tilewidth:(k+1)*self.__tilewidth] = line[0:self.__tilewidth]
if self.__option == "average":
colbuffer[j, 0:self.__coloverlap] = line[self.__tilewidth:self.__tilewidth + self.__coloverlap]
# If option average has been selected, keep the values from the overlapping edge in a buffer
if self.__option == "average":
for j in range(self.__rowoverlap):
line = rg.next()
rowbuffer[j, k*self.__tilewidth:(k+1)*self.__tilewidth] = line[0:self.__tilewidth]
# When the last column is filled, write the strip to disk
if (k == maxcolidx):
......@@ -326,6 +345,7 @@ class TileStitcher():
nrows = self.__nrows * self.__tileheight
yll = yul - nrows * rg.dy
outputraster.open('w', ncols, nrows, xul, yll, rg.cellsize, rg.nodatavalue)
# TODO: if option average has been selected, use data in the row buffer to do the calculations
for j in range(self.__tileheight):
line = data[j, :]
outputraster.writenext(line)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment