Skip to main content

Raster Bands, Resolution, and NoData

A raster is not merely a matrix. Its dimensions, bands, data type, CRS, affine transform, cell support, scale and offset, units, mask, and NoData value jointly determine what every stored number means.

Prerequisites​

Complete cartographic encoding and accessible maps and revisit vector and raster data. You should be able to distinguish visual resolution from measurement accuracy.

Learning goals​

  • Inspect band meaning, dimensions, data type, CRS, transform, bounds, and pixel support.
  • Convert row/column indices to spatial coordinates without reversing row direction.
  • Treat valid zero, NoData, masked cells, and out-of-extent cells as different states.
  • Choose resampling from the measurement type rather than convenience.

One grid contract​

The ticket fixture has two int16 bands on the same 4 by 4 grid. Band 1 stores surface temperature in tenths of a degree Celsius; band 2 stores a categorical quality flag. Its upper-left corner is (391000, 5820000) in EPSG:32633; each pixel covers a 500 m by 500 m area. The affine transform has positive x scale and negative y scale because array rows increase downward while northing increases upward.

The declared extent is 2 km by 2 km. Resolution describes cell spacing and support, not sensor accuracy or the smallest real feature. Making 250 m output cells would create more values through interpolation; it would not create new observations.

NoData is not zero. A physical zero can be a valid observation. The fixture uses -9999, and Rasterio exposes invalidity through both metadata and masks. GDAL-style valid-data masks use zero for invalid and 255 for valid; NumPy masked arrays use True for invalid. Check which convention an operation expects.

For a continuous band, bilinear resampling may be defensible when the spatial process and support justify interpolation. For a categorical quality flag, nearest-neighbor resampling preserves class codes; bilinear interpolation would invent meaningless classes. Downsampling extensive quantities may require sum, while intensive quantities may require a weighted mean. State the aggregation semantics.

Worked example​

from pathlib import Path

import rasterio

path = Path("tests/fixtures/geospatial-data-science/tiny-multiband.tif")
with rasterio.open(path) as raster:
data = raster.read(masked=True)
x, y = raster.xy(0, 0)
print(f"shape={raster.count}x{raster.height}x{raster.width} dtype={raster.dtypes[0]}")
print(f"crs={raster.crs.to_string()} bounds={tuple(int(value) for value in raster.bounds)}")
print(f"transform={tuple(float(value) for value in raster.transform)[:6]} cell=500m pixel_is_area={raster.tags()['AREA_OR_POINT']}")
print(f"bands={list(raster.descriptions)} nodata={raster.nodata} masked={int(data.mask[0].sum())}")
print(f"upper_left_center=({int(x)},{int(y)}) temperature_c={data[0, 0, 0] / 10:.1f} quality={int(data[1, 0, 0])}")

Expected output:

shape=2x4x4 dtype=int16
crs=EPSG:32633 bounds=(391000, 5818000, 393000, 5820000)
transform=(500.0, 0.0, 391000.0, 0.0, -500.0, 5820000.0) cell=500m pixel_is_area=Area
bands=['surface_temperature_c_x10', 'quality_flag'] nodata=-9999.0 masked=1
upper_left_center=(391250,5819750) temperature_c=18.0 quality=1

The output preserves the declared CRS, transform, band order, NoData, and pixel-is-area convention. The band value is scaled only after the mask is applied.

Limitations and common mistakes​

  • Band number is not band meaning; descriptions, units, acquisition time, and provenance belong in the schema.
  • A shared extent does not guarantee a shared transform or pixel alignment.
  • Cropping or padding changes extent; reprojection and resampling change the grid and may change values.
  • Comparing masked values to the NoData sentinel can fail after type conversion; propagate masks deliberately.
  • Tiny fixture timings are teaching diagnostics, not a benchmark for cloud, compressed, tiled, or remote rasters.

Practice​

Write a raster contract for land-cover classes and another for rainfall depth. Specify the valid range, units, CRS, transform, cell support, NoData, and the allowed upsampling and downsampling methods. Explain why their resampling policies differ.

Next steps​

Next, use windowed raster processing without losing the window transform, mask, or resampling policy.

Primary sources​

Checked 2026-10-18: Rasterio, dataset georeferencing and affine transforms; Rasterio, NoData masks; Rasterio, resampling methods; GDAL, raster data model.