Cloud-Optimized GeoTIFFs: read only the pixels you need
A plain GeoTIFF stores its pixels in long horizontal strips, so reading one small county out of a national file can mean downloading nearly all of it. A Cloud-Optimized GeoTIFF (COG) is the same GeoTIFF format with a smarter internal layout — built so a reader on the other side of the internet can fetch just the pixels it needs, and nothing else.
The code
# One-time conversion (GDAL command line):
# gdal_translate rainfall.tif rainfall_cog.tif -of COG
# Later, from anywhere: read one window of the file, in place
import rasterio
from rasterio.windows import Window
with rasterio.open("s3://lake/rainfall_cog.tif") as src:
data = src.read(1, window=Window(0, 0, 512, 512))
print(data.shape) # (512, 512) — only those tiles crossed the network
In practice
Three layout choices do the work. Internal tiling: pixels are stored in small square blocks (often 512 by 512) instead of strips, so one area of the map is one contiguous chunk of the file. Overviews: shrunken copies of the whole image at several zoom levels are baked in, so a zoomed-out map reads a tiny overview instead of the full-resolution pixels. Header first: the file's table of contents sits at the front, so a reader learns where every tile lives from the first few kilobytes.
Put together, a COG-aware reader (rasterio, GDAL, most map servers) uses HTTP range requests: fetch the header, fetch the overview or the handful of tiles covering your window, done. It is exactly the trick from the last two weeks in new clothes — Parquet reads only the columns and row groups it needs; a COG reads only the tiles and zoom level it needs. Read less, over the network, on purpose.
In practice, COG is the default way raster data is published now: satellite imagery, elevation, land cover, and weather grids sit in cloud buckets as COGs, usually catalogued with STAC metadata so you can search by place and time before reading a single pixel. Lesson 27's rainfall grid, stored for real, would be one of these.
Python bridge: with rasterio, opening a COG by URL looks exactly like opening a local file — the range requests happen under the hood. The skill is not the code; it is knowing to ask for a window instead of reading band 1 whole.
Further reading
Cloud-Optimized GeoTIFFs — Cloud-Native Geospatial Formats Guide (what makes a GeoTIFF cloud-optimized, from the same guide as the GeoParquet lesson)
Try it
Practice question: a map app first shows all of New Jersey at low zoom, then a user zooms into Princeton. For each step, which part of a COG gets read — and why would a plain GeoTIFF be slower at both steps?
Show answer
Result: at low zoom the app reads one of the baked-in overviews — a small, pre-shrunk copy of the whole state — instead of downsampling billions of full-resolution pixels on the fly. Zoomed into Princeton, it reads only the few internal tiles that cover Princeton, fetched with range requests. A plain GeoTIFF stores pixels in strips and has no overviews, so both steps drag most of the file across the network before a single pixel can be shown.