Skip to content

Opening Data with Rasterio

This guide shows how to use obspec-utils readers to open cloud-hosted raster data with rasterio.

Opening a Cloud-Hosted GeoTIFF

Use EagerStoreReader to provide a file-like interface that rasterio can read:

import rasterio
from obstore.store import S3Store
from obspec_utils.readers import EagerStoreReader

# Access public Arctic DEM data (no credentials needed)
store = S3Store(
    bucket="pgc-opendata-dems",
    aws_region="us-west-2",
    skip_signature=True,
)

path = "arcticdem/mosaics/v4.1/2m_dem_tiles.vrt"

with EagerStoreReader(store, path) as reader:
    with rasterio.open(reader) as src:
        print(f"CRS: {src.crs}")
        print(f"Bounds: {src.bounds}")
        print(f"Shape: {src.width} x {src.height}")
CRS: EPSG:3413
Bounds: BoundingBox(left=-4000100.0, bottom=-3400100.0, right=3400100.0, top=4100100.0)
Shape: 3700100 x 3750100

Using with Xarray and rioxarray

For analysis workflows, combine with rioxarray to load raster data as xarray datasets:

import xarray as xr
from obstore.store import S3Store
from obspec_utils.readers import EagerStoreReader

store = S3Store(
    bucket="pgc-opendata-dems",
    aws_region="us-west-2",
    skip_signature=True,
)

path = "arcticdem/mosaics/v4.1/2m_dem_tiles.vrt"

with EagerStoreReader(store, path) as reader:
    ds = xr.open_dataset(reader, engine="rasterio")
    print(ds)
<xarray.Dataset> Size: 56TB
Dimensions:      (band: 1, x: 3700100, y: 3750100)
Coordinates:
  * band         (band) int64 8B 1
  * x            (x) float64 30MB -4e+06 -4e+06 -4e+06 ... 3.4e+06 3.4e+06
  * y            (y) float64 30MB 4.1e+06 4.1e+06 4.1e+06 ... -3.4e+06 -3.4e+06
    spatial_ref  int64 8B ...
Data variables:
    band_data    (band, y, x) float32 56TB ...

Choosing a Reader

For raster data, the choice of reader depends on your access pattern:

Reader Best for
EagerStoreReader Small files or when you need the entire file (metadata parsing, VRT files)
BlockStoreReader Large files with sparse access patterns (reading specific tiles/windows)

For most rasterio use cases, EagerStoreReader works well since rasterio typically needs to read file headers and metadata which requires random access across the file.