class GDALBand
GDALBand
instances are not created explicitly, but rather obtained from a GDALRaster
object, through its bands
attribute. The GDALBands contain the actual pixel values of the raster.
-
description
-
The name or description of the band, if any.
-
width
-
The width of the band in pixels (X-axis).
-
height
-
The height of the band in pixels (Y-axis).
-
pixel_count
-
New in Django 1.9.
The total number of pixels in this band. Is equal to
width * height
.
-
statistics(refresh=False, approximate=False)
-
New in Django 1.10.
Compute statistics on the pixel values of this band. The return value is a tuple with the following structure:
(minimum, maximum, mean, standard deviation)
.If the
approximate
argument is set toTrue
, the statistics may be computed based on overviews or a subset of image tiles.If the
refresh
argument is set toTrue
, the statistics will be computed from the data directly, and the cache will be updated with the result.If a persistent cache value is found, that value is returned. For raster formats using Persistent Auxiliary Metadata (PAM) services, the statistics might be cached in an auxiliary file. In some cases this metadata might be out of sync with the pixel values or cause values from a previous call to be returned which don’t reflect the value of the
approximate
argument. In such cases, use therefresh
argument to get updated values and store them in the cache.For empty bands (where all pixel values are “no data”), all statistics are returned as
None
.The statistics can also be retrieved directly by accessing the
min
,max
,mean
, andstd
properties.
-
min
-
The minimum pixel value of the band (excluding the “no data” value).
-
max
-
The maximum pixel value of the band (excluding the “no data” value).
-
mean
-
New in Django 1.10.
The mean of all pixel values of the band (excluding the “no data” value).
-
std
-
New in Django 1.10.
The standard deviation of all pixel values of the band (excluding the “no data” value).
-
nodata_value
-
The “no data” value for a band is generally a special marker value used to mark pixels that are not valid data. Such pixels should generally not be displayed, nor contribute to analysis operations.
To delete an existing “no data” value, set this property to
None
(requires GDAL ≥ 2.1).Changed in Django 1.9:This property can now be set as well.
Changed in Django 1.10:The “no data” value can now be deleted by setting the
nodata_value
attribute toNone
.
-
datatype(as_string=False)
-
The data type contained in the band, as an integer constant between 0 (Unknown) and 11. If
as_string
isTrue
, the data type is returned as a string with the following possible values:GDT_Unknown
,GDT_Byte
,GDT_UInt16
,GDT_Int16
,GDT_UInt32
,GDT_Int32
,GDT_Float32
,GDT_Float64
,GDT_CInt16
,GDT_CInt32
,GDT_CFloat32
, andGDT_CFloat64
.
-
data(data=None, offset=None, size=None, shape=None)
-
New in Django 1.9.
The accessor to the pixel values of the
GDALBand
. Returns the complete data array if no parameters are provided. A subset of the pixel array can be requested by specifying an offset and block size as tuples.If NumPy is available, the data is returned as NumPy array. For performance reasons, it is highly recommended to use NumPy.
Data is written to the
GDALBand
if thedata
parameter is provided. The input can be of one of the following types - packed string, buffer, list, array, and NumPy array. The number of items in the input should normally correspond to the total number of pixels in the band, or to the number of pixels for a specific block of pixel values if theoffset
andsize
parameters are provided.If the number of items in the input is different from the target pixel block, the
shape
parameter must be specified. The shape is a tuple that specifies the width and height of the input data in pixels. The data is then replicated to update the pixel values of the selected block. This is useful to fill an entire band with a single value, for instance.For example:
>>> rst = GDALRaster({'width': 4, 'height': 4, 'srid': 4326, 'datatype': 1, 'nr_of_bands': 1}) >>> bnd = rst.bands[0] >>> bnd.data(range(16)) >>> bnd.data() array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]], dtype=int8) >>> bnd.data(offset=(1, 1), size=(2, 2)) array([[ 5, 6], [ 9, 10]], dtype=int8) >>> bnd.data(data=[-1, -2, -3, -4], offset=(1, 1), size=(2, 2)) >>> bnd.data() array([[ 0, 1, 2, 3], [ 4, -1, -2, 7], [ 8, -3, -4, 11], [12, 13, 14, 15]], dtype=int8) >>> bnd.data(data='\x9d\xa8\xb3\xbe', offset=(1, 1), size=(2, 2)) >>> bnd.data() array([[ 0, 1, 2, 3], [ 4, -99, -88, 7], [ 8, -77, -66, 11], [ 12, 13, 14, 15]], dtype=int8) >>> bnd.data([1], shape=(1, 1)) >>> bnd.data() array([[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], dtype=uint8) >>> bnd.data(range(4), shape=(1, 4)) array([[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]], dtype=uint8)
The shape
parameter and the ability to replicate data input when setting GDALBand
data was added.
Please login to continue.