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

Merge branch 'master' of https://github.com//sbhoek/lmgeo

Conflicts:
	.gitignore
parents a7859ff2 7974848a
from gridenvelope2d import GridEnvelope2D;
from raster import Raster
import numpy as np
import const
class InMemoryRaster(GridEnvelope2D, Raster):
"A raster developed in the first place for testing purposes"
# Data attributes
data = None
__datatype = None
__open = False
dataformat = 'f'
def __init__(self, filepath, data=None, *datatype):
Raster.__init__(self, filepath)
if data != None:
self.data = data
if len(datatype) > 0:
if (datatype[0] == const.INTEGER):
self.__datatype = const.INTEGER;
self.dataformat = 'i'
else:
self.__datatype = const.FLOAT;
self.dataformat = 'f'
def open(self, mode, ncols=1, nrows=1, xll=0.0, yll=0.0, cellsize=1.0, nodatavalue=-9999.0):
super(InMemoryRaster, self).open(mode);
self.__open = True
if self.__datatype == const.INTEGER:
dtype = np.int
else:
dtype = np.float
if mode[0] == 'w':
self.data = np.zeros((nrows*ncols), dtype=dtype)
else:
if self.data == None: raise Exception("Memory was not initialised!")
self.data = np.array(self.data, dtype=dtype)
self.data = self.data.flatten()
self.data.shape = (nrows, ncols)
self.xll = xll
self.yll = yll
self.dx = cellsize
self.dy = cellsize
self.nodatavalue = nodatavalue
GridEnvelope2D.__init__(self, ncols, nrows, self.xll, self.yll, self.dx, self.dy)
return True;
def next(self, parseLine=True):
if not self.__open: raise Exception("Not yet fully initialised!")
self.currow += 1;
if (self.currow > self.nrows): raise StopIteration;
if parseLine:
return self.data[self.currow - 1, :]
else:
return None
def writenext(self, sequence_with_data):
if not self.__open: raise Exception("Not yet fully initialised!")
self.currow += 1;
if (self.currow > self.nrows): raise StopIteration;
if len(sequence_with_data) != self.ncols:
raise Exception("Attempt to assign line of wrong length!")
self.data[self.currow - 1, :] = sequence_with_data
return True
\ No newline at end of file
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