Fixed #27421 -- Added shape, size, and offset controls to GDALRaster constructor.

Thanks Tim Graham for the review.
This commit is contained in:
Daniel Wiesmann 2016-11-11 12:09:38 +00:00 committed by Tim Graham
parent 501c993010
commit 2dc07da497
4 changed files with 128 additions and 12 deletions

View file

@ -1117,16 +1117,39 @@ blue.
>>> rst = GDALRaster('/path/to/your/raster.tif', write=False)
>>> rst.name
'/path/to/your/raster.tif'
>>> rst.width, rst.height # This file has 163 x 174 pixels
>>> rst.width, rst.height # This file has 163 x 174 pixels
(163, 174)
>>> rst = GDALRaster({'srid': 4326, 'width': 1, 'height': 2, 'datatype': 1
... 'bands': [{'data': [0, 1]}]}) # Creates in-memory raster
>>> rst = GDALRaster({ # Creates an in-memory raster
... 'srid': 4326,
... 'width': 4,
... 'height': 4,
... 'datatype': 1,
... 'bands': [{
... 'data': (2, 3),
... 'offset': (1, 1),
... 'size': (2, 2),
... 'shape': (2, 1),
... 'nodata_value': 5,
... }]
... })
>>> rst.srs.srid
4326
>>> rst.width, rst.height
(1, 2)
(4, 4)
>>> rst.bands[0].data()
array([[0, 1]], dtype=int8)
array([[5, 5, 5, 5],
[5, 2, 3, 5],
[5, 2, 3, 5],
[5, 5, 5, 5]], dtype=uint8)
.. versionchanged:: 1.11
Added the ability to pass the ``size``, ``shape``, and ``offset``
parameters when creating :class:`GDALRaster` objects. The parameters
can be passed through the ``ds_input`` dictionary. This allows to
finely control initial pixel values. The functionality is similar to
the :meth:`GDALBand.data()<django.contrib.gis.gdal.GDALBand.data>`
method.
.. attribute:: name