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

Minor changes

parent efa83459
......@@ -14,7 +14,7 @@ except ImportError:
__author__ = "Steven B. Hoek"
class GeotiffRaster(GridEnvelope2D, Raster):
class GeotiffRaster(Raster, GridEnvelope2D):
"A raster represented by 2 files, with extensions 'tif' and 'tfw'"
# Constants
......
......@@ -10,7 +10,7 @@ __author__ = "Steven B. Hoek"
# Class for reading quick and dirty HDF5 format that can store weather data
# 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'"
# Constants
......
......@@ -7,7 +7,10 @@ from .const import constants as const
__author__ = "Steven B. Hoek"
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 = None
__datatype = None
......@@ -16,7 +19,7 @@ class InMemoryRaster(Raster, GridEnvelope2D):
def __init__(self, filepath, data=None, *datatype):
Raster.__init__(self, filepath)
if data != None:
if not data is None:
self.data = data
if len(datatype) > 0:
if (datatype[0] == const.INTEGER):
......@@ -34,7 +37,15 @@ class InMemoryRaster(Raster, GridEnvelope2D):
else:
dtype = np.float
if mode[0] == 'w':
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:
if self.data == None: raise Exception("Memory was not initialised!")
self.data = np.array(self.data, dtype=dtype)
......
......@@ -65,6 +65,8 @@ class Raster(object):
def reset(self):
self.currow = 0;
# TODO: Raster and GridEnvelope2D are often used together; both have dx and dy, so this causes ambiguity!
@property
def dx(self):
return self.cellsize
......
......@@ -181,7 +181,7 @@ class StripTiffRaster(BaseTiffRaster, GridEnvelope2D):
self.__image = self.__image.reshape(self.__rows_per_strip, self.ncols, self.__samples_per_pixel)
# 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
except StopIteration:
raise StopIteration;
......
......@@ -11,14 +11,16 @@ from math import floor, ceil, sqrt
__author__ = "Steven B. Hoek"
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"
"Different layers - e.g. RGB - are as planes: contiguously = chunky = interleaved"
"or separately = per channel. More info: http://www.fileformat.info/format/tiff/egff.htm"
"It means that the number of planes and the planar configuration determines the shape"
"of the array written as bitmapped data, with dimensions image_depth, image_height, "
"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"
'''
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
Different layers - e.g. RGB - are as planes: contiguously = chunky = interleaved
or separately = per channel. More info: http://www.fileformat.info/format/tiff/egff.htm
It means that the number of planes and the planar configuration determines the shape
of the array written as bitmapped data, with dimensions image_depth, image_height,
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
_const = None
__mode = 'r'
......@@ -187,7 +189,7 @@ class TileTiffRaster(BaseTiffRaster, GridEnvelope2D):
self.__image = self.__image.reshape(length, self.ncols, self.__samples_per_pixel)
# Read the next row
result = self.__image[row_in_strip, :]
result = self.__image[row_in_strip, :, 0]
return result
except StopIteration:
raise StopIteration;
......
# Copyright (c) 2004-2021 WUR, Wageningen
"""MapPlotLib - a Python library with tools that help to plot maps"""
import re
# 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
import numpy as np
......
......@@ -117,6 +117,12 @@ class SimpleShape(object):
result.append(points)
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
def get_dirty_centroid(self):
points = sum(self.get_point_series(), [])
......
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