Module: safe.storage.raster

Class Raster

class safe.storage.raster.Raster(data=None, projection=None, geotransform=None, name=None, keywords=None, style_info=None)[source]

Internal representation of raster data

copy()[source]

Return copy of raster layer

This copy will be equal to self in the sense defined by __eq__

get_bins(N=10, quantiles=False)[source]

Get N values between the min and the max occurred in this dataset.

Return sorted list of length N+1 where the first element is min and the last is max. Intermediate values depend on the keyword quantiles: If quantiles is True, they represent boundaries between quantiles. If quantiles is False, they represent equidistant interval boundaries.

get_bounding_box()[source]

Get bounding box coordinates for raster layer

Note:
Format is [West, South, East, North]
get_data(nan=True, scaling=None, copy=False)[source]

Get raster data as numeric array

Args:
  • nan: Optional flag controlling handling of missing values.

    If nan is True (default), nodata values will be replaced with numpy.nan If keyword nan has a numeric value, nodata values will be replaced by that value. E.g. to set missing values to 0, do get_data(nan=0.0)

  • scaling: Optional flag controlling if data is to be scaled

    if it has been resampled. Admissible values are False: data is retrieved without modification. True: Data is rescaled based on the squared ratio

    between its current and native resolution. This is typically required if raster data represents a density such as population per km^2

    None: The behaviour will depend on the keyword

    “population” associated with the layer. If it is “density”, scaling will be applied otherwise not. This is the default.

    scalar value: If scaling takes a numerical scalar value,

    that will be use to scale the data

  • copy (optional): If present and True return copy
Note:
Scaling does not currently work with projected layers. See issue #123
get_extrema()[source]

Get min and max from raster Note:

If raster has a nominated no_data value, this is ignored.
Returns:
min, max
get_geometry()[source]

Return longitudes and latitudes (the axes) for grid.

Note:

Return two vectors (longitudes and latitudes) corresponding to grid. The values are offset by half a pixel size to correspond to pixel registration.

I.e. If the grid origin (top left corner) is (105, 10) and the resolution is 1 degrees in each direction, then the vectors will take the form

longitudes = [100.5, 101.5, ..., 109.5] latitudes = [0.5, 1.5, ..., 9.5]

get_geotransform(copy=False)[source]

Return geotransform for this raster layer

Returns: * geotransform: 6 digit vector

(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

  • copy (optional): If present and True return copy
get_nodata_value()[source]

Get the internal representation of NODATA

Note:
If the internal value is None, the standard -9999 is assumed
get_resolution(isotropic=False, native=False)[source]

Get raster resolution as a 2-tuple (resx, resy)

Args:
  • isotropic: If True, verify that dx == dy and return dx

    If False return 2-tuple (dx, dy)

  • native: Optional flag. If True, return native resolution if

    available. Otherwise return actual.

read_from_file(filename)[source]

Read and unpack raster data

to_vector_layer()[source]

Convert raster grid to vector point data

Returns:
a vector layer object with data points corresponding to grid points. The order is row-major which means that the x (longitude) direction is varying the fastest.
to_vector_points()[source]

Convert raster grid to vector point data

Returns:
  • coordinates: Nx2 array of x, y (lon, lat) coordinates
  • values: N array of corresponding grid values
write_to_file(filename)[source]

Save raster data to file

Args:
  • filename: filename with extension .tif

Gdal documentation at: http://www.gdal.org/classGDALRasterBand.html

This module forms part of the InaSAFE tool.

Previous topic

Module: safe.storage.utilities

Next topic

Module: safe.storage.test_clipping

This Page