def __init__(self, data=None, projection=None, geotransform=None, name=None, keywords=None, style_info=None): """Initialise object with either data or filename NOTE: Doc strings in constructor are not harvested and exposed in online documentation. Hence the details are specified in the class docstring. """ # Invoke common layer constructor Layer.__init__(self, name=name, projection=projection, keywords=keywords, style_info=style_info) # Input checks if data is None: # Instantiate empty object self.geotransform = None self.rows = self.columns = 0 return # Initialisation if isinstance(data, basestring): self.read_from_file(data) elif isinstance(data, QgsRasterLayer): self.read_from_qgis_native(data) else: # Assume that data is provided as a numpy array # with extra keyword arguments supplying metadata self.data = numpy.array(data, dtype='d', copy=False) proj4 = self.get_projection(proj4=True) if 'longlat' in proj4 and 'WGS84' in proj4: # This is only implemented for geographic coordinates # Omit check for projected coordinate systems check_geotransform(geotransform) self.geotransform = geotransform self.rows = data.shape[0] self.columns = data.shape[1] self.number_of_bands = 1 # We assume internal numpy layers are using nan correctly # FIXME (Ole): If read from file is refactored to load the data # this should be taken care of there self.nodata_value = numpy.nan
def __init__(self, data=None, projection=None, geotransform=None, name=None, keywords=None, style_info=None): """Initialise object with either data or filename Args: * data: Can be either * a filename of a raster file format known to GDAL * an MxN array of raster data * None (FIXME (Ole): Remove this option) * projection: Geospatial reference in WKT format. Only used if data is provide as a numeric array, if None, WGS84 geographic is assumed * geotransform: GDAL geotransform (6-tuple). (top left x, w-e pixel resolution, rotation, top left y, rotation, n-s pixel resolution). See e.g. http://www.gdal.org/gdal_tutorial.html Only used if data is provide as a numeric array, * name: Optional name for layer. If None, basename is used. * keywords: Optional dictionary with keywords that describe the layer. When the layer is stored, these keywords will be written into an associated file with extension .keywords. Keywords can for example be used to display text about the layer in a web application. * style_info: Dictionary with information about how this layer should be styled. See impact_functions/styles.py for examples. Note: If data is a filename, all other arguments are ignored as they will be inferred from the file. """ # Invoke common layer constructor Layer.__init__(self, name=name, projection=projection, keywords=keywords, style_info=style_info) # Input checks if data is None: # Instantiate empty object self.geotransform = None self.rows = self.columns = 0 return # Initialisation if isinstance(data, basestring): self.read_from_file(data) else: # Assume that data is provided as a numpy array # with extra keyword arguments supplying metadata self.data = numpy.array(data, dtype='d', copy=False) proj4 = self.get_projection(proj4=True) if 'longlat' in proj4 and 'WGS84' in proj4: # This is only implemented for geographic coordinates # Omit check for projected coordinate systems check_geotransform(geotransform) self.geotransform = geotransform self.rows = data.shape[0] self.columns = data.shape[1] self.number_of_bands = 1 # We assume internal numpy layers are using nan correctly # FIXME (Ole): If read from file is refactored to load the data # this should be taken care of there self.nodata_value = numpy.nan