Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

Rasterio: Python Library for Reading Geospatial Raster Data

Rasterio reads and writes GeoTIFF and other raster data in Python as NumPy arrays. Install, open, window, mask and write a raster, with troubleshooting.

Written and maintained by CASRAI Editorial Board

Last updated

Rasterio is a Python library that reads and writes geospatial raster data such as GeoTIFF satellite imagery and terrain models, and hands the pixel values to you as NumPy arrays. This guide is for researchers who need to open a raster, check its coordinate system, read it safely and write a result back out. It was checked against the Rasterio documentation and PyPI listing on 2026-11-07.

What Rasterio is used for in research

The Rasterio documentation describes geographic information systems as using GeoTIFF and other formats to store gridded raster datasets such as satellite imagery and terrain models. Rasterio reads and writes these formats and provides a Python API based on NumPy N-dimensional arrays and GeoJSON. The PyPI project page summarises it as: “Rasterio reads and writes geospatial raster data.” It is released under the BSD-3-Clause licence.

In practice that means a raster band becomes an ordinary array you can analyse with the rest of the scientific Python stack, while the georeferencing (coordinate reference system, affine transform, bounds) stays available alongside it. The search phrase “rasterio python” refers to this same library; there is no separate product. For gridded population surfaces that you might open this way, see WorldPop open population data; for multidimensional climate and ocean grids, see NetCDF.

Install or access

The official installation page gives one command:

pip install rasterio

Binary distributions (wheels) containing libgdal and its own dependencies are available from the Python Package Index. The documentation notes that these wheels are aimed at simple applications and omit many optional GDAL drivers; for more drivers it suggests the conda-forge channel. If you build from source, the documentation states that version 1.4.4 and later need Python 3.10 or newer and GDAL 3.5 or newer. At the time of checking, PyPI listed release 1.5.2 (30 September 2026), which requires Python 3.12 or newer. If you have not set up a Python environment yet, see installing Anaconda Python.

Step-by-step: open, inspect, read and write a raster

The steps below follow the official Quickstart and the windowed reading topic. Replace example.tif with your own file.

  1. Open the file. import rasterio then dataset = rasterio.open('example.tif'). Using it as a context manager (with rasterio.open('example.tif') as dataset:) closes it for you.
  2. Inspect the georeferencing before any analysis. The dataset exposes count (number of bands), width, height, crs, transform (an Affine object) and bounds (a BoundingBox with left, bottom, right, top). dataset.indexes lists the band indexes; bands are numbered from 1, so a single-band file returns (1,).
  3. Read a band. band = dataset.read(1) returns a numpy.ndarray.
  4. Read only part of a large raster. Pass a window: from rasterio.windows import Window, then dataset.read(1, window=Window(0, 0, 512, 256)). The arguments are column offset, row offset, width and height. To walk a file block by block, iterate for ji, window in dataset.block_windows(1): and call dataset.read(1, window=window) inside the loop.
  5. Handle missing data. dataset.read(1, masked=True) returns a masked array so that nodata pixels are excluded from statistics.
  6. Write a result. Open a new file in write mode with the metadata the Quickstart lists: rasterio.open('out.tif', 'w', driver='GTiff', height=H, width=W, count=1, dtype=arr.dtype, crs=dataset.crs, transform=dataset.transform), then dst.write(arr, 1). Reusing the source crs and transform keeps the output aligned with the input.

Output and how to read it

  • crs identifies the coordinate reference system. Two rasters can only be compared pixel for pixel if their CRS, transform and dimensions agree.
  • transform maps pixel (column, row) positions to spatial coordinates; bounds gives the extent those coordinates cover.
  • read() returns array values only. Nothing in the array itself tells you the units or the nodata convention; take those from the dataset metadata and the data provider’s documentation.
  • A masked read separates valid from nodata cells, so means, minima and maxima are computed over valid pixels only.

Troubleshooting

pip cannot find a matching version

Current releases declare a minimum Python version (PyPI lists Python 3.12 or newer for 1.5.2). If your interpreter is older, upgrade it or install an earlier Rasterio release that supports it.

A file format will not open

The PyPI wheels omit many optional GDAL drivers. If the driver for your format is missing, the installation documentation points to conda-forge for a build with more drivers.

Results do not line up with another layer

Compare crs, transform and bounds of the two datasets first; a mismatch there is the first thing to rule out.

Memory errors on large files

Switch from reading the whole band to windowed reads (step 4) so that only one block is in memory at a time.

Free alternatives and companions

Tool What the project page says
GDAL/OGR Python package (osgeo) PyPI describes it as tools for programming and manipulating the GDAL Geospatial Data Abstraction Library, with classes and methods that mostly match the GDAL and OGR C++ classes.
Rasterio command line The Rasterio documentation has a separate Command Line section for use outside Python scripts.

For related research tooling see Google Earth Engine for cloud-based raster analysis and NetCDF for gridded scientific data.

Frequently asked questions

What is Rasterio?

An open-source (BSD-3-Clause) Python library that reads and writes geospatial raster data, exposing pixel values as NumPy arrays with the georeferencing alongside.

How do I install Rasterio?

Run pip install rasterio. Wheels on PyPI bundle libgdal; for additional drivers the documentation suggests conda-forge.

Is “rasterio python” different from Rasterio?

No. Rasterio is a Python library, so the two searches describe the same package.

Are bands numbered from 0 or 1?

From 1. dataset.read(1) reads the first band.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Rasterio: Python Library for Reading Geospatial Raster Data

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →