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.
- Open the file.
import rasteriothendataset = rasterio.open('example.tif'). Using it as a context manager (with rasterio.open('example.tif') as dataset:) closes it for you. - Inspect the georeferencing before any analysis. The dataset exposes
count(number of bands),width,height,crs,transform(an Affine object) andbounds(a BoundingBox with left, bottom, right, top).dataset.indexeslists the band indexes; bands are numbered from 1, so a single-band file returns(1,). - Read a band.
band = dataset.read(1)returns anumpy.ndarray. - Read only part of a large raster. Pass a window:
from rasterio.windows import Window, thendataset.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, iteratefor ji, window in dataset.block_windows(1):and calldataset.read(1, window=window)inside the loop. - Handle missing data.
dataset.read(1, masked=True)returns a masked array so that nodata pixels are excluded from statistics. - 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), thendst.write(arr, 1). Reusing the sourcecrsandtransformkeeps 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
- Rasterio on PyPI, read 2026-11-07.
- Rasterio documentation: Installation, read 2026-11-07.
- Rasterio documentation: Quickstart, read 2026-11-07.
- Rasterio documentation: Windowed reading and writing, read 2026-11-07.
- GDAL on PyPI, read 2026-11-07.







