docs/topics/switch.rst - update the section abound bands (#2201)

This commit is contained in:
Idan Miara 2021-06-09 18:45:48 +03:00 committed by GitHub
parent 69305c72b5
commit 14834341f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -185,8 +185,11 @@ dataset connections.
Bands
-----
``gdal`` has band objects. Rasterio does not and thus never has objects with
dangling dataset pointers. With Rasterio, bands are represented by a numerical
``gdal`` and ``Rasterio`` both have band objects.
But unlike gdal's band, Rasterio's band is just a tuple of the dataset,
band index and some other band properties.
Thus Rasterio never has objects with dangling dataset pointers.
With Rasterio, bands are represented by a numerical
index, starting from 1 (as GDAL does), and are used as arguments to dataset
methods. To read the first band of a dataset as a Numpy ``ndarray``, do this.
@ -195,6 +198,14 @@ methods. To read the first band of a dataset as a Numpy ``ndarray``, do this.
with rasterio.open('example.tif') as src:
band1 = src.read(1)
A band object can be used to represent a single band (or a sequence of bands):
.. code-block:: python
with rasterio.open('example.tif') as src:
bnd = rasterio.band(src, 1)
print(bnd.dtype)
Other attributes of GDAL band objects generally surface in Rasterio as tuples
returned by dataset attributes, with one value per band, in order.