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

Minor changes

parent efa83459
...@@ -14,7 +14,7 @@ except ImportError: ...@@ -14,7 +14,7 @@ except ImportError:
__author__ = "Steven B. Hoek" __author__ = "Steven B. Hoek"
class GeotiffRaster(GridEnvelope2D, Raster): class GeotiffRaster(Raster, GridEnvelope2D):
"A raster represented by 2 files, with extensions 'tif' and 'tfw'" "A raster represented by 2 files, with extensions 'tif' and 'tfw'"
# Constants # Constants
......
...@@ -10,7 +10,7 @@ __author__ = "Steven B. Hoek" ...@@ -10,7 +10,7 @@ __author__ = "Steven B. Hoek"
# Class for reading quick and dirty HDF5 format that can store weather data # Class for reading quick and dirty HDF5 format that can store weather data
# in a raster format in an efficient way, for fast access # in a raster format in an efficient way, for fast access
class Hdf5Raster(GridEnvelope2D, Raster): class Hdf5Raster(Raster, GridEnvelope2D):
"A raster represented by 2 files, with extensions 'h5' and 'hdr'" "A raster represented by 2 files, with extensions 'h5' and 'hdr'"
# Constants # Constants
......
...@@ -7,7 +7,10 @@ from .const import constants as const ...@@ -7,7 +7,10 @@ from .const import constants as const
__author__ = "Steven B. Hoek" __author__ = "Steven B. Hoek"
class InMemoryRaster(Raster, GridEnvelope2D): class InMemoryRaster(Raster, GridEnvelope2D):
"A raster developed in the first place for testing purposes" '''
A class with raster interface that is not based on a particular file format, but can rather
keep data in memory in view of testing and operations that require more lines than only one
'''
# Data attributes # Data attributes
data = None data = None
__datatype = None __datatype = None
...@@ -16,7 +19,7 @@ class InMemoryRaster(Raster, GridEnvelope2D): ...@@ -16,7 +19,7 @@ class InMemoryRaster(Raster, GridEnvelope2D):
def __init__(self, filepath, data=None, *datatype): def __init__(self, filepath, data=None, *datatype):
Raster.__init__(self, filepath) Raster.__init__(self, filepath)
if data != None: if not data is None:
self.data = data self.data = data
if len(datatype) > 0: if len(datatype) > 0:
if (datatype[0] == const.INTEGER): if (datatype[0] == const.INTEGER):
...@@ -34,7 +37,15 @@ class InMemoryRaster(Raster, GridEnvelope2D): ...@@ -34,7 +37,15 @@ class InMemoryRaster(Raster, GridEnvelope2D):
else: else:
dtype = np.float dtype = np.float
if mode[0] == 'w': if mode[0] == 'w':
self.data = np.zeros((nrows*ncols), dtype=dtype) if self.data is None:
self.data = np.zeros((nrows*ncols), dtype=dtype)
else:
errmsg = "Shape of input data does not match given dimensions!"
if len(self.data) != nrows:
raise Exception(errmsg)
else:
if (len(self.data) > 0) and (len(self.data[0]) != ncols):
raise Exception(errmsg)
else: else:
if self.data == None: raise Exception("Memory was not initialised!") if self.data == None: raise Exception("Memory was not initialised!")
self.data = np.array(self.data, dtype=dtype) self.data = np.array(self.data, dtype=dtype)
......
...@@ -65,6 +65,8 @@ class Raster(object): ...@@ -65,6 +65,8 @@ class Raster(object):
def reset(self): def reset(self):
self.currow = 0; self.currow = 0;
# 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
......
...@@ -181,7 +181,7 @@ class StripTiffRaster(BaseTiffRaster, GridEnvelope2D): ...@@ -181,7 +181,7 @@ class StripTiffRaster(BaseTiffRaster, GridEnvelope2D):
self.__image = self.__image.reshape(self.__rows_per_strip, self.ncols, self.__samples_per_pixel) self.__image = self.__image.reshape(self.__rows_per_strip, self.ncols, self.__samples_per_pixel)
# Read the next row # Read the next row
result = self.__image[row_in_strip, :] result = self.__image[row_in_strip, :] # TODO: check whether 3rd index is necessary
return result return result
except StopIteration: except StopIteration:
raise StopIteration; raise StopIteration;
......
...@@ -11,14 +11,16 @@ from math import floor, ceil, sqrt ...@@ -11,14 +11,16 @@ from math import floor, ceil, sqrt
__author__ = "Steven B. Hoek" __author__ = "Steven B. Hoek"
class TileTiffRaster(BaseTiffRaster, GridEnvelope2D): class TileTiffRaster(BaseTiffRaster, GridEnvelope2D):
"A raster represented by 2 files, with extensions 'tif' and 'tfw'" '''
"This class can deal with tiff files of which the data are stored in tiles" A raster represented by 2 files, with extensions 'tif' and 'tfw'
"Different layers - e.g. RGB - are as planes: contiguously = chunky = interleaved" This class can deal with tiff files of which the data are stored in tiles
"or separately = per channel. More info: http://www.fileformat.info/format/tiff/egff.htm" Different layers - e.g. RGB - are as planes: contiguously = chunky = interleaved
"It means that the number of planes and the planar configuration determines the shape" or separately = per channel. More info: http://www.fileformat.info/format/tiff/egff.htm
"of the array written as bitmapped data, with dimensions image_depth, image_height, " It means that the number of planes and the planar configuration determines the shape
"image_width and samples. E.g. in the case of rgb and contiguous configuration, the last" of the array written as bitmapped data, with dimensions image_depth, image_height,
"dimension of the array is expected to be 3 and the field samples per pixel will also be 3" image_width and samples. E.g. in the case of rgb and contiguous configuration, the last
dimension of the array is expected to be 3 and the field samples per pixel will also be 3
'''
# Private attributes # Private attributes
_const = None _const = None
__mode = 'r' __mode = 'r'
...@@ -187,7 +189,7 @@ class TileTiffRaster(BaseTiffRaster, GridEnvelope2D): ...@@ -187,7 +189,7 @@ class TileTiffRaster(BaseTiffRaster, GridEnvelope2D):
self.__image = self.__image.reshape(length, self.ncols, self.__samples_per_pixel) self.__image = self.__image.reshape(length, self.ncols, self.__samples_per_pixel)
# Read the next row # Read the next row
result = self.__image[row_in_strip, :] result = self.__image[row_in_strip, :, 0]
return result return result
except StopIteration: except StopIteration:
raise StopIteration; raise StopIteration;
......
# Copyright (c) 2004-2021 WUR, Wageningen # Copyright (c) 2004-2021 WUR, Wageningen
"""MapPlotLib - a Python library with tools that help to plot maps""" """MapPlotLib - a Python library with tools that help to plot maps"""
import re import re
from shapely.geometry import Polygon # TODO: replace the following with a pure python equivalent!
# E.g. with this: https://github.com/karimbahgat/Shapy
from shapely.geometry import Polygon
from descartes import PolygonPatch from descartes import PolygonPatch
import numpy as np import numpy as np
......
...@@ -116,6 +116,12 @@ class SimpleShape(object): ...@@ -116,6 +116,12 @@ class SimpleShape(object):
points.append(pt) points.append(pt)
result.append(points) result.append(points)
return result return result
def get_simplified_coords(self):
# TODO: use Ramon-Douglas-Peucker algorithm to simplify the shape
# from rdp import rdp
raise NotImplementedError("Not implemented yet!")
return []
# Simple method for estimating centroid # Simple method for estimating centroid
def get_dirty_centroid(self): def get_dirty_centroid(self):
......
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