Commit 2bf1dade authored by Hoek, Steven's avatar Hoek, Steven
Browse files

Base classes Raster and GridEnvelope2D were revised.

parent 779c6d08
...@@ -6,10 +6,10 @@ __author__ = "Steven B. Hoek" ...@@ -6,10 +6,10 @@ __author__ = "Steven B. Hoek"
# Helper class, to be used together with classes derived from Raster # Helper class, to be used together with classes derived from Raster
class GridEnvelope2D(object): class GridEnvelope2D(object):
# Data attributes # Data attributes
nrows = 1; __nrows = 1;
ncols = 1; __ncols = 1;
xll = 0.0; __xll = 0.0;
yll = 0.0; __yll = 0.0;
dx = 2.0; dx = 2.0;
dy = 2.0; dy = 2.0;
xcoords_sort = const.ASC; # ascending xcoords_sort = const.ASC; # ascending
...@@ -19,10 +19,10 @@ class GridEnvelope2D(object): ...@@ -19,10 +19,10 @@ class GridEnvelope2D(object):
# We define a grid by means of a number of rows, columns, # We define a grid by means of a number of rows, columns,
# a lower left corner as well as by steps in x and y direction # a lower left corner as well as by steps in x and y direction
def __init__(self, ncols, nrows, xll, yll, dx, dy): def __init__(self, ncols, nrows, xll, yll, dx, dy):
self.ncols = ncols; self.__ncols = ncols;
self.nrows = nrows; self.__nrows = nrows;
self.xll = xll; self.__xll = xll;
self.yll = yll; self.__yll = yll;
self.dx = dx; self.dx = dx;
self.dy = dy; self.dy = dy;
...@@ -32,19 +32,19 @@ class GridEnvelope2D(object): ...@@ -32,19 +32,19 @@ class GridEnvelope2D(object):
# The following 4 functions are about the extent of the envelope # The following 4 functions are about the extent of the envelope
def getMinX(self): def getMinX(self):
# X-coordinate of the lower left corner # X-coordinate of the lower left corner
return self.xll; return self.__xll;
def getMinY(self): def getMinY(self):
# Y-coordinate of the lower left corner # Y-coordinate of the lower left corner
return self.yll; return self.__yll;
def getMaxX(self): def getMaxX(self):
# X-coordinate of the upper right corner # X-coordinate of the upper right corner
return self.xll + self.ncols * self.dx; return self.__xll + self.__ncols * self.dx;
def getMaxY(self): def getMaxY(self):
# Y-coordinate of the upper right corner # Y-coordinate of the upper right corner
return self.yll + self.nrows * self.dy; return self.__yll + self.__nrows * self.dy;
def getColAndRowIndex(self, x, y): def getColAndRowIndex(self, x, y):
# Return the zero-based row and column numbers of the grid cell # Return the zero-based row and column numbers of the grid cell
...@@ -52,11 +52,11 @@ class GridEnvelope2D(object): ...@@ -52,11 +52,11 @@ class GridEnvelope2D(object):
# or from the top downwards (DESC), depending on the way the coordinates are sorted # or from the top downwards (DESC), depending on the way the coordinates are sorted
eps = const.epsilon; # we'll use this constant to prevent negative indices eps = const.epsilon; # we'll use this constant to prevent negative indices
if self.xcoords_sort == const.ASC: if self.xcoords_sort == const.ASC:
k = int(round((x - self.xll - 0.5*self.dx + eps) / self.dx)); k = int(round((x - self.__xll - 0.5*self.dx + eps) / self.dx));
else: else:
k = int(round((self.getMaxX() - x - 0.5*self.dy + eps) / self.dy)); # TODO: check k = int(round((self.getMaxX() - x - 0.5*self.dy + eps) / self.dy)); # TODO: check
if self.ycoords_sort == const.ASC: if self.ycoords_sort == const.ASC:
i = int(round((y - self.yll - 0.5*self.dy + eps) / self.dy)); i = int(round((y - self.__yll - 0.5*self.dy + eps) / self.dy));
else: else:
i = int(round((self.getMaxY() - y - 0.5*self.dy + eps) / self.dy)); # TODO: check i = int(round((self.getMaxY() - y - 0.5*self.dy + eps) / self.dy)); # TODO: check
return k, i; return k, i;
...@@ -75,11 +75,11 @@ class GridEnvelope2D(object): ...@@ -75,11 +75,11 @@ class GridEnvelope2D(object):
# Rows are counted from the top downwards # Rows are counted from the top downwards
k, i = self.getColAndRowIndex(x, y); k, i = self.getColAndRowIndex(x, y);
if self.xcoords_sort == const.ASC: if self.xcoords_sort == const.ASC:
cx = self.xll + (k + 0.5) * self.dx; cx = self.__xll + (k + 0.5) * self.dx;
else: else:
cx = self.getMaxX() - (k + 0.5) * self.dx; cx = self.getMaxX() - (k + 0.5) * self.dx;
if self.ycoords_sort == const.ASC: if self.ycoords_sort == const.ASC:
cy = self.yll + (i + 0.5) * self.dy; cy = self.__yll + (i + 0.5) * self.dy;
else: else:
cy = self.getMaxY() - (i + 0.5) * self.dy; cy = self.getMaxY() - (i + 0.5) * self.dy;
return (cx, cy); return (cx, cy);
...@@ -92,17 +92,17 @@ class GridEnvelope2D(object): ...@@ -92,17 +92,17 @@ class GridEnvelope2D(object):
return False; return False;
# Now check the extent # Now check the extent
if self.ncols != obj.ncols: if self.__ncols != obj.ncols:
return False; return False;
if self.nrows != obj.nrows: if self.__nrows != obj.nrows:
return False; return False;
if abs(self.dy - obj.dy) > epsilon: if abs(self.dy - obj.dy) > epsilon:
return False; return False;
if abs(self.dx - obj.dx) > epsilon: if abs(self.dx - obj.dx) > epsilon:
return False; return False;
if abs(self.xll - obj.xll) > epsilon: if abs(self.__xll - obj.xll) > epsilon:
return False; return False;
if abs(self.yll - obj.yll) > epsilon: if abs(self.__yll - obj.yll) > epsilon:
return False; return False;
else: else:
return True; return True;
...@@ -149,5 +149,37 @@ class GridEnvelope2D(object): ...@@ -149,5 +149,37 @@ class GridEnvelope2D(object):
return result return result
def getEnvelope(self): def getEnvelope(self):
return GridEnvelope2D(self.ncols, self.nrows, self.xll, self.yll, self.cellsize, self.cellsize) return GridEnvelope2D(self.__ncols, self.__nrows, self.__xll, self.__yll, self.cellsize, self.cellsize)
@property
def nrows(self):
return self.__nrows
@nrows.setter
def nrows(self, nrows):
self.__nrows = nrows
@property
def ncols(self):
return self.__ncols
@ncols.setter
def ncols(self, ncols):
self.__ncols = ncols
@property
def xll(self):
return self.__xll
@xll.setter
def xll(self, xll):
self.__xll = xll
@property
def yll(self):
return self.__yll
@yll.setter
def yll(self, yll):
self.__yll = yll
\ No newline at end of file
...@@ -13,6 +13,8 @@ class Raster(object): ...@@ -13,6 +13,8 @@ class Raster(object):
nodatavalue = -9999.0; nodatavalue = -9999.0;
cellsize = 1; cellsize = 1;
currow = 0 currow = 0
roty = 0.0
rotx = 0.0
file_exists = False file_exists = False
def __init__(self, filepath): def __init__(self, filepath):
...@@ -66,7 +68,6 @@ class Raster(object): ...@@ -66,7 +68,6 @@ class Raster(object):
self.currow = 0; self.currow = 0;
# TODO: Raster and GridEnvelope2D are often used together; both have dx and dy, so this causes ambiguity! # TODO: Raster and GridEnvelope2D are often used together; both have dx and dy, so this causes ambiguity!
@property @property
def dx(self): def dx(self):
return self.cellsize return self.cellsize
......
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