17  Raster Data

17.1 Read raster metadata

import rasterio

with rasterio.open("data/raster.tif") as src:
    print(src.crs)
    print(src.width, src.height)
    print(src.count)
    print(src.bounds)

17.2 Read the first band

with rasterio.open("data/raster.tif") as src:
    band_1 = src.read(1)
    nodata = src.nodata

print(band_1.shape)
print(nodata)

17.3 Things to remember

  • A raster can contain multiple bands.
  • NoData values are not ordinary measurements.
  • Resolution and CRS affect comparison between rasters.